From 56ff51e9077b9d65cf73c3bf59be0aab057fee9a Mon Sep 17 00:00:00 2001 From: henry Date: Sun, 22 Apr 2018 19:11:23 -0400 Subject: [PATCH] Change validate send request and create account request to have status code, to handle exit errors --- .../activities/CreateSeedActivity.java | 7 +-- .../fragments/SendTransactionFragment.java | 2 +- .../manager/BitsharesAccountManager.java | 16 ++++--- .../ValidateBitsharesSendRequest.java | 36 +++++++++----- ...ValidateCreateBitsharesAccountRequest.java | 48 +++++++++++-------- 5 files changed, 64 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java index 1718203..aa6d024 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java @@ -130,17 +130,14 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator @Override public void onCarryOut() { processDialog.dismiss(); - - if (request.getAccount() != null){ + if (request.getStatus().equals(ValidateCreateBitsharesAccountRequest.StatusCode.SUCCEEDED)) { GrapheneAccount accountSeed = request.getAccount(); Intent intent = new Intent(getApplicationContext(), BackupSeedActivity.class); - intent.putExtra("SEED_ID",accountSeed.getId()); + intent.putExtra("SEED_ID", accountSeed.getId()); startActivity(intent); } else { createSeedValidator.validate(); } - - } }); diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java index d3bbf8c..13114be 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java @@ -301,7 +301,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat sendRequest.setListener(new CryptoNetInfoRequestListener() { @Override public void onCarryOut() { - if (sendRequest.isSend()){ + if (sendRequest.getStatus().equals(ValidateBitsharesSendRequest.StatusCode.SUCCEEDED)){ try { this.finalize(); } catch (Throwable throwable) { 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 65e3aea..d095a0f 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -289,6 +289,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI } private void validateCreateAccount(final ValidateCreateBitsharesAccountRequest createRequest){ + //TODO test for internet and server connection // Generate seed or find key Context context = createRequest.getContext(); AccountSeed seed = AccountSeed.getAccountSeed(SeedType.BIP39, context); @@ -306,13 +307,13 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI @Override public void success(Object answer) { - createRequest.setAccountExists(false); createRequest.setAccount((GrapheneAccount) answer); + createRequest.setStatus(ValidateCreateBitsharesAccountRequest.StatusCode.SUCCEEDED); } @Override public void fail() { - createRequest.setAccountExists(true); + createRequest.setStatus(ValidateCreateBitsharesAccountRequest.StatusCode.ACCOUNT_EXIST); } }, context); @@ -348,6 +349,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI * Broadcast a transaction request */ private void validateSendRequest(final ValidateBitsharesSendRequest sendRequest) { + //TODO check internet, server connection //TODO feeAsset CrystalDatabase db = CrystalDatabase.getAppDatabase(sendRequest.getContext()); CryptoCurrency currency = db.cryptoCurrencyDao().getByNameAndCryptoNet(sendRequest.getAsset(), CryptoNet.BITSHARES.name()); @@ -360,7 +362,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI @Override public void fail() { - + sendRequest.setStatus(ValidateBitsharesSendRequest.StatusCode.NO_ASSET_INFO_DB); } }); }else{ @@ -374,7 +376,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI @Override public void fail() { - + sendRequest.setStatus(ValidateBitsharesSendRequest.StatusCode.NO_ASSET_INFO); } }); }else { @@ -415,12 +417,12 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI ApiRequest transactionRequest = new ApiRequest(0, new ApiRequestListener() { @Override public void success(Object answer, int idPetition) { - sendRequest.setSend(true); + sendRequest.setStatus(ValidateBitsharesSendRequest.StatusCode.SUCCEEDED); } @Override public void fail(int idPetition) { - sendRequest.setSend(false); + sendRequest.setStatus(ValidateBitsharesSendRequest.StatusCode.PETITION_FAILED); } }); @@ -429,7 +431,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI @Override public void fail() { - //TODO bad user to user account + sendRequest.setStatus(ValidateBitsharesSendRequest.StatusCode.NO_TO_USER_INFO); } }); diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateBitsharesSendRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateBitsharesSendRequest.java index d1ba87b..6967ed5 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateBitsharesSendRequest.java +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateBitsharesSendRequest.java @@ -12,6 +12,20 @@ import cy.agorise.crystalwallet.models.GrapheneAccount; */ public class ValidateBitsharesSendRequest extends CryptoNetInfoRequest { + /** + * The status code of this request + */ + public enum StatusCode{ + NOT_STARTED, + SUCCEEDED, + NO_INTERNET, + NO_SERVER_CONNECTION, + NO_ASSET_INFO_DB, + NO_ASSET_INFO, + NO_TO_USER_INFO, + PETITION_FAILED + } + // The app context private Context mContext; // The source account used to transfer fund from @@ -25,7 +39,7 @@ public class ValidateBitsharesSendRequest extends CryptoNetInfoRequest { // The memo, can be null private String mMemo; // The state of this request - private Boolean isSend; + private StatusCode status = StatusCode.NOT_STARTED; public ValidateBitsharesSendRequest(Context context, GrapheneAccount sourceAccount, String toAccount, long amount, String asset, String memo) { @@ -68,18 +82,18 @@ public class ValidateBitsharesSendRequest extends CryptoNetInfoRequest { return mMemo; } - public boolean isSend() { - return isSend; - } - - public void setSend(boolean send) { - isSend = send; - this.validate(); - } - public void validate(){ - if ((this.isSend != null)){ + if ((this.status != StatusCode.NOT_STARTED)){ this._fireOnCarryOutEvent(); } } + + public void setStatus(StatusCode code){ + this.status = code; + this._fireOnCarryOutEvent(); + } + + public StatusCode getStatus() { + return status; + } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateCreateBitsharesAccountRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateCreateBitsharesAccountRequest.java index c753a63..58f802c 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateCreateBitsharesAccountRequest.java +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateCreateBitsharesAccountRequest.java @@ -14,15 +14,27 @@ import cy.agorise.crystalwallet.models.GrapheneAccount; public class ValidateCreateBitsharesAccountRequest extends CryptoNetInfoRequest { + /** + * The status code of this request + */ + public enum StatusCode{ + NOT_STARTED, + SUCCEEDED, + NO_INTERNET, + NO_SERVER_CONNECTION, + ACCOUNT_EXIST, + NO_ACCOUNT_DATA + + } + /** * The name of the account */ private String accountName; - /** - * Indicates if the account exist - */ - private Boolean accountExists; + + // The state of this request + private StatusCode status = StatusCode.NOT_STARTED; private GrapheneAccount account; @@ -34,34 +46,19 @@ public class ValidateCreateBitsharesAccountRequest extends CryptoNetInfoRequest this.context = context; } - public void setAccountExists(boolean value){ - this.accountExists = value; - this.validate(); - } - public void setAccount(GrapheneAccount account){ this.account = account; this.validate(); } - public boolean getAccountExists(){ - return this.accountExists; - } public GrapheneAccount getAccount() { return account; } public void validate(){ - if ((this.accountExists != null)){// && (this.account != null)){ - if (this.accountExists == true) { - this._fireOnCarryOutEvent(); - } else { - if (this.account != null){ - this._fireOnCarryOutEvent(); - } - } - } + if(!status.equals(StatusCode.NOT_STARTED)) + this._fireOnCarryOutEvent(); } public String getAccountName() { @@ -75,4 +72,13 @@ public class ValidateCreateBitsharesAccountRequest extends CryptoNetInfoRequest public Context getContext() { return context; } + + public void setStatus(StatusCode code){ + this.status = code; + this.validate(); + } + + public StatusCode getStatus() { + return status; + } }