From c4ac6b4a29fc198cd3bddffbabbc4a91ff7cc540 Mon Sep 17 00:00:00 2001 From: hvarona Date: Thu, 25 Oct 2018 08:09:54 -0400 Subject: [PATCH] Fixed error feedback on import request --- .../apigenerator/GrapheneApiGenerator.java | 9 ++- .../manager/BitsharesAccountManager.java | 62 ++++++++++--------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java index b654b48..d4b0cb4 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java @@ -129,8 +129,13 @@ public abstract class GrapheneApiGenerator { List accounts = resp.get(0); if(accounts.size() > 0){ for(UserAccount account : accounts) { - request.getListener().success(account,request.getId());}}} - request.getListener().fail(request.getId()); + request.getListener().success(account, request.getId()); + break; + } + } + }else{ + request.getListener().fail(request.getId()); + } } @Override diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java index 4baf5d9..7f08e20 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -276,44 +276,46 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI @Override public void fail(int idPetition) { - //importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.PETITION_FAILED); - } - }); + BIP39 bip39 = new BIP39(-1, importRequest.getMnemonic()); + ApiRequest getAccountNamesBP39 = new ApiRequest(0, new ApiRequestListener() { + @Override + public void success(Object answer, int idPetition) { + if(answer != null && importRequest.getStatus().equals(ImportBitsharesAccountRequest.StatusCode.NOT_STARTED)) { + UserAccount userAccount = (UserAccount) answer; + importRequest.setSeedType(SeedType.BIP39); + importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.SUCCEEDED); - ApiRequest getAccountNamesBP39 = new ApiRequest(0, new ApiRequestListener() { - @Override - public void success(Object answer, int idPetition) { - if(answer != null && importRequest.getStatus().equals(ImportBitsharesAccountRequest.StatusCode.NOT_STARTED)) { - UserAccount userAccount = (UserAccount) answer; - importRequest.setSeedType(SeedType.BIP39); - importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.SUCCEEDED); - - AccountSeed seed = new AccountSeed(); - seed.setName(userAccount.getName()); - seed.setType(importRequest.getSeedType()); - seed.setMasterSeed(importRequest.getMnemonic()); - long idSeed = accountSeedDao.insertAccountSeed(seed); - if (idSeed >= 0) { - GrapheneAccount account = new GrapheneAccount(); - account.setCryptoNet(CryptoNet.BITSHARES); - account.setAccountIndex(0); - account.setSeedId(idSeed); - account.setAccountId(userAccount.getObjectId()); - importAccountFromSeed(account, importRequest.getContext()); + AccountSeed seed = new AccountSeed(); + seed.setName(userAccount.getName()); + seed.setType(importRequest.getSeedType()); + seed.setMasterSeed(importRequest.getMnemonic()); + long idSeed = accountSeedDao.insertAccountSeed(seed); + if (idSeed >= 0) { + GrapheneAccount account = new GrapheneAccount(); + account.setCryptoNet(CryptoNet.BITSHARES); + account.setAccountIndex(0); + account.setSeedId(idSeed); + account.setAccountId(userAccount.getObjectId()); + importAccountFromSeed(account, importRequest.getContext()); + } + } } - } - } - @Override - public void fail(int idPetition) { - //importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.PETITION_FAILED); + @Override + public void fail(int idPetition) { + importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.PETITION_FAILED); + } + }); + GrapheneApiGenerator.getAccountByOwnerOrActiveAddress(new Address(ECKey.fromPublicOnly(bip39.getBitsharesActiveKey(0).getPubKey())),getAccountNamesBP39); } }); + + BrainKey bk = new BrainKey(importRequest.getMnemonic(), 0); - BIP39 bip39 = new BIP39(-1, importRequest.getMnemonic()); + GrapheneApiGenerator.getAccountByOwnerOrActiveAddress(bk.getPublicAddress("BTS"),getAccountNamesBK); - GrapheneApiGenerator.getAccountByOwnerOrActiveAddress(new Address(ECKey.fromPublicOnly(bip39.getBitsharesActiveKey(0).getPubKey())),getAccountNamesBP39); + }