From 04d3a0d2e662b8e7be3734813d3d350dd427242a Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Wed, 24 Oct 2018 22:53:51 -0400 Subject: [PATCH] - Change the import bitshares account request to avoid using the name of the account --- .../activities/ImportSeedActivity.java | 23 ++-- .../ImportBitsharesAccountRequest.java | 115 ++++++++++++++++++ app/src/main/res/layout/import_seed.xml | 6 +- 3 files changed, 132 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ImportBitsharesAccountRequest.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/ImportSeedActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/ImportSeedActivity.java index 954b06c..cba3f15 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/ImportSeedActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/ImportSeedActivity.java @@ -31,6 +31,7 @@ import cy.agorise.crystalwallet.dialogs.material.PositiveResponse; import cy.agorise.crystalwallet.dialogs.material.QuestionDialog; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests; +import cy.agorise.crystalwallet.requestmanagers.ImportBitsharesAccountRequest; import cy.agorise.crystalwallet.requestmanagers.ValidateImportBitsharesAccountRequest; import cy.agorise.crystalwallet.viewmodels.AccountSeedViewModel; import cy.agorise.crystalwallet.viewmodels.validators.ImportSeedValidator; @@ -203,6 +204,7 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator txtErrorAccount.setVisibility(View.INVISIBLE); } }); + /* etAccountName.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -217,9 +219,9 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator @Override public void afterTextChanged(Editable s) { - /* - * If all is ready to continue enable the button, contrarie case disable it - * */ + // + // If all is ready to continue enable the button, contrarie case disable it + // if(allFieldsAreFill()){ enableCreate(); } @@ -228,6 +230,7 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator } } }); + */ accountSeedViewModel = ViewModelProviders.of(this).get(AccountSeedViewModel.class); importSeedValidator = new ImportSeedValidator(this.getApplicationContext(),etPin,etPinConfirmation,etAccountName,etSeedWords); @@ -263,8 +266,8 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator boolean complete = false; if( etPin.getText().toString().trim().compareTo("")!=0 && etPinConfirmation.getText().toString().trim().compareTo("")!=0 && - etSeedWords.getText().toString().trim().compareTo("")!=0 && - etAccountName.getText().toString().trim().compareTo("")!=0){ + etSeedWords.getText().toString().trim().compareTo("")!=0 /*&& + etAccountName.getText().toString().trim().compareTo("")!=0*/){ complete = true; } return complete; @@ -287,11 +290,11 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator void afterSeedWordsChanged(Editable editable) { this.importSeedValidator.validate(); } - @OnTextChanged(value = R.id.etAccountName, + /*@OnTextChanged(value = R.id.etAccountName, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) void afterAccountNameChanged(Editable editable) { this.importSeedValidator.validate(); - } + }*/ @OnClick(R.id.btnCancel) public void cancel(){ @@ -327,7 +330,7 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator /* * Validate mnemonic with the server * */ - final ValidateImportBitsharesAccountRequest request = new ValidateImportBitsharesAccountRequest(etAccountName.getText().toString().trim(),etSeedWords.getText().toString().trim(),activity); + final ImportBitsharesAccountRequest request = new ImportBitsharesAccountRequest(etSeedWords.getText().toString().trim(),activity); request.setListener(new CryptoNetInfoRequestListener() { @Override public void onCarryOut() { @@ -365,8 +368,8 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator final ImportSeedActivity thisActivity = this; - final ValidateImportBitsharesAccountRequest validatorRequest = - new ValidateImportBitsharesAccountRequest(etAccountName.getText().toString(), etSeedWords.getText().toString(), getApplicationContext(), true); + final ImportBitsharesAccountRequest validatorRequest = + new ImportBitsharesAccountRequest(etSeedWords.getText().toString(), getApplicationContext(), true); validatorRequest.setListener(new CryptoNetInfoRequestListener() { @Override diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ImportBitsharesAccountRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ImportBitsharesAccountRequest.java new file mode 100644 index 0000000..cf83d4b --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ImportBitsharesAccountRequest.java @@ -0,0 +1,115 @@ +package cy.agorise.crystalwallet.requestmanagers; + +import android.content.Context; + +import cy.agorise.crystalwallet.enums.CryptoCoin; +import cy.agorise.crystalwallet.enums.SeedType; + +/** + * Imports a bitshares accounts, + * + * return true if the account exist, and the mnemonic (brainkey provide is for that account + * Created by Henry Varona on 10/24/2018. + */ + +public class ImportBitsharesAccountRequest extends CryptoNetInfoRequest { + + /** + * The status code of this request + */ + public enum StatusCode{ + NOT_STARTED, + SUCCEEDED, + NO_INTERNET, + NO_SERVER_CONNECTION, + ACCOUNT_DOESNT_EXIST, + BAD_SEED, + NO_ACCOUNT_DATA, + PETITION_FAILED + } + + /** + * The name of the account + */ + private String accountName; + + /** + * The mnemonic words + */ + private final String mnemonic; + + /** + * True - the account must be added if the accountName and mnemonic are correct + */ + private boolean addAccountIfValid = false; + + /** + * If this seed is BIP39 or Brainkey + */ + private SeedType seedType; + + /** + * The status of this request + */ + private StatusCode status = StatusCode.NOT_STARTED; + + private Context context; + + public ImportBitsharesAccountRequest(String mnemonic, Context context){ + super(CryptoCoin.BITSHARES); + this.accountName = ""; + this.mnemonic = mnemonic; + this.context = context; + } + + public ImportBitsharesAccountRequest(String mnemonic, Context context, boolean addAccountIfValid){ + super(CryptoCoin.BITSHARES); + this.accountName = ""; + this.mnemonic = mnemonic; + this.addAccountIfValid = addAccountIfValid; + this.context = context; + } + + public void validate(){ + if (!(this.status.equals(StatusCode.NOT_STARTED))){ + this._fireOnCarryOutEvent(); + } + } + + public String getAccountName() { + return accountName; + } + + public String getMnemonic() { + return mnemonic; + } + + public SeedType getSeedType() { + return seedType; + } + + public Context getContext() { + return context; + } + + public boolean addAccountIfValid(){ + return this.addAccountIfValid; + } + + public void setAccountName(String accountName){ + this.accountName = accountName; + } + + public void setSeedType(SeedType seedType) { + this.seedType = seedType; + } + + public void setStatus(StatusCode status) { + this.status = status; + this._fireOnCarryOutEvent(); + } + + public StatusCode getStatus() { + return status; + } +} diff --git a/app/src/main/res/layout/import_seed.xml b/app/src/main/res/layout/import_seed.xml index 59e5f6e..5b29d02 100644 --- a/app/src/main/res/layout/import_seed.xml +++ b/app/src/main/res/layout/import_seed.xml @@ -84,8 +84,9 @@ android:layout_width="330dp" android:layout_height="wrap_content" android:layout_below="@+id/etSeedWordsLayout" + android:layout_centerHorizontal="true" android:layout_marginTop="8dp" - android:layout_centerHorizontal="true"> + android:visibility="gone"> + android:singleLine="true" + android:visibility="gone" />