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 bde843f..5514263 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -24,6 +24,7 @@ import cy.agorise.crystalwallet.models.seed.BIP39; import cy.agorise.crystalwallet.requestmanagers.CryptoNetEquivalentRequest; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequest; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestsListener; +import cy.agorise.crystalwallet.requestmanagers.GetBitsharesAccountNameCacheRequest; import cy.agorise.crystalwallet.requestmanagers.ValidateBitsharesLTMUpgradeRequest; import cy.agorise.crystalwallet.requestmanagers.ValidateBitsharesSendRequest; import cy.agorise.crystalwallet.requestmanagers.ValidateCreateBitsharesAccountRequest; @@ -231,7 +232,10 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI this.validateCreateAccount((ValidateCreateBitsharesAccountRequest) request); }else if (request instanceof ValidateBitsharesLTMUpgradeRequest){ this.validateLTMAccountUpgrade((ValidateBitsharesLTMUpgradeRequest) request); + }else if (request instanceof GetBitsharesAccountNameCacheRequest){ + this.getBitsharesAccountNameCacheRequest((GetBitsharesAccountNameCacheRequest) request); }else{ + //TODO not implemented System.out.println("Error request not implemented " + request.getClass().getName()); } @@ -508,6 +512,32 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI GrapheneApiGenerator.broadcastTransaction(transaction,feeAsset, transactionRequest); } + private void getBitsharesAccountNameCacheRequest(final GetBitsharesAccountNameCacheRequest request){ + final CrystalDatabase db = CrystalDatabase.getAppDatabase(request.getContext()); + BitsharesAccountNameCache cacheAccount = db.bitsharesAccountNameCacheDao().getByAccountId(request.getAccountId()); + if(cacheAccount == null) { + this.getAccountInfoById(request.getAccountId(), new ManagerRequest() { + + @Override + public void success(Object answer) { + GrapheneAccount userGrapheneAccount = (GrapheneAccount) answer; + BitsharesAccountNameCache cacheAccount = new BitsharesAccountNameCache(); + cacheAccount.setName(userGrapheneAccount.getName()); + cacheAccount.setAccountId(request.getAccountId()); + db.bitsharesAccountNameCacheDao().insertBitsharesAccountNameCache(cacheAccount); + request.setAccountName(userGrapheneAccount.getName()); + } + + @Override + public void fail() { + //TODO error + } + }); + }else { + request.setAccountName(cacheAccount.getName()); + } + } + /** * Returns the account info from a graphene id * @param grapheneId The graphene id of the account diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/GetBitsharesAccountNameCacheRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/GetBitsharesAccountNameCacheRequest.java index 48cbef0..1f32c1e 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/GetBitsharesAccountNameCacheRequest.java +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/GetBitsharesAccountNameCacheRequest.java @@ -12,11 +12,13 @@ public class GetBitsharesAccountNameCacheRequest extends CryptoNetInfoRequest { private String accountId; private String accountName; + private Context context; public GetBitsharesAccountNameCacheRequest(Context context, String accountId) { super(CryptoCoin.BITSHARES); this.accountId = accountId; this.accountName = ""; + this.context = context; } public void setAccountName(String accountName){ @@ -30,5 +32,15 @@ public class GetBitsharesAccountNameCacheRequest extends CryptoNetInfoRequest { } } + public Context getContext() { + return context; + } + public String getAccountId() { + return accountId; + } + + public String getAccountName() { + return accountName; + } }