-In the import seed window, the service doest not have to be connecting to the service each time the user type text to validate if the account name exists
-In the import seed window, the service to check valid mnemonic does not have to fire each time the user is typing text -In the import seed window, the service to check valid mnemonic has to fire only when the import account button is pressed -In the import seed window add error message when the service to validate the seed or the account name is correct fails
This commit is contained in:
parent
8a7b41ad1d
commit
b73c77e86f
3 changed files with 94 additions and 61 deletions
|
@ -41,6 +41,9 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator
|
||||||
@BindView(R.id.txtErrorPIN)
|
@BindView(R.id.txtErrorPIN)
|
||||||
TextView txtErrorPIN;
|
TextView txtErrorPIN;
|
||||||
|
|
||||||
|
@BindView(R.id.txtErrorAccount)
|
||||||
|
TextView txtErrorAccount;
|
||||||
|
|
||||||
//@BindView(R.id.tvPinError)
|
//@BindView(R.id.tvPinError)
|
||||||
//TextView tvPinError;
|
//TextView tvPinError;
|
||||||
|
|
||||||
|
@ -186,6 +189,11 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator
|
||||||
else{
|
else{
|
||||||
disableCreate();
|
disableCreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hide error field
|
||||||
|
* */
|
||||||
|
txtErrorAccount.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
etAccountName.addTextChangedListener(new TextWatcher() {
|
etAccountName.addTextChangedListener(new TextWatcher() {
|
||||||
|
@ -272,8 +280,6 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator
|
||||||
void afterSeedWordsChanged(Editable editable) {
|
void afterSeedWordsChanged(Editable editable) {
|
||||||
this.importSeedValidator.validate();
|
this.importSeedValidator.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@OnTextChanged(value = R.id.etAccountName,
|
@OnTextChanged(value = R.id.etAccountName,
|
||||||
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
|
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
|
||||||
void afterAccountNameChanged(Editable editable) {
|
void afterAccountNameChanged(Editable editable) {
|
||||||
|
@ -298,74 +304,89 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator
|
||||||
final CrystalLoading crystalLoading = new CrystalLoading(activity);
|
final CrystalLoading crystalLoading = new CrystalLoading(activity);
|
||||||
crystalLoading.show();
|
crystalLoading.show();
|
||||||
|
|
||||||
final ValidateImportBitsharesAccountRequest validatorRequest =
|
/*
|
||||||
new ValidateImportBitsharesAccountRequest(etAccountName.getText().toString(), etSeedWords.getText().toString(), getApplicationContext(), true);
|
* Validate mnemonic with the server
|
||||||
|
* */
|
||||||
validatorRequest.setListener(new CryptoNetInfoRequestListener() {
|
final ValidateImportBitsharesAccountRequest request = new ValidateImportBitsharesAccountRequest(etAccountName.getText().toString().trim(),etSeedWords.getText().toString().trim(),this);
|
||||||
|
request.setListener(new CryptoNetInfoRequestListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCarryOut() {
|
public void onCarryOut() {
|
||||||
|
if(request.getStatus().equals(ValidateImportBitsharesAccountRequest.StatusCode.SUCCEEDED)){
|
||||||
|
|
||||||
/*
|
//Correct
|
||||||
* Hide the loading dialog
|
|
||||||
* */
|
|
||||||
crystalLoading.dismiss();
|
|
||||||
|
|
||||||
if (!validatorRequest.getStatus().equals(ValidateImportBitsharesAccountRequest.StatusCode.SUCCEEDED)) {
|
/*
|
||||||
String errorText = "An error ocurred attempting to import the account";
|
* Final service connection
|
||||||
|
* */
|
||||||
|
finalStep(crystalLoading);
|
||||||
|
|
||||||
switch (validatorRequest.getStatus()){
|
}
|
||||||
case PETITION_FAILED:
|
else{
|
||||||
case NO_INTERNET:
|
|
||||||
case NO_SERVER_CONNECTION:
|
|
||||||
errorText = "There was an error with the connection. Try again later";
|
|
||||||
break;
|
|
||||||
case ACCOUNT_DOESNT_EXIST:
|
|
||||||
errorText = "The account doesn't exists";
|
|
||||||
break;
|
|
||||||
case BAD_SEED:
|
|
||||||
errorText = "The seed is not valid";
|
|
||||||
break;
|
|
||||||
case NO_ACCOUNT_DATA:
|
|
||||||
errorText = "The account doesn't have any data";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Toast.makeText(thisActivity.getApplicationContext(),errorText,Toast.LENGTH_LONG).show();
|
crystalLoading.dismiss();
|
||||||
} else {
|
|
||||||
Intent intent = new Intent(thisActivity, BoardActivity.class);
|
txtErrorAccount.setVisibility(View.VISIBLE);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
txtErrorAccount.setText(activity.getResources().getString(R.string.error_invalid_account));
|
||||||
startActivity(intent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/*CryptoNetInfoRequests.getInstance().addRequest(validatorRequest);
|
CryptoNetInfoRequests.getInstance().addRequest(request);
|
||||||
|
|
||||||
AccountSeed seed = new AccountSeed();
|
|
||||||
|
|
||||||
//TODO verify if words are already in the db
|
|
||||||
//TODO check if name has been asigned to other seed
|
|
||||||
seed.setMasterSeed(etSeedWords.getText().toString());
|
|
||||||
seed.setName(etAccountName.getText().toString());
|
|
||||||
seed.setType(SeedType.BRAINKEY);
|
|
||||||
|
|
||||||
accountSeedViewModel.addSeed(seed);
|
|
||||||
|
|
||||||
CryptoNetAccountViewModel cryptoNetAccountViewModel = ViewModelProviders.of(this).get(CryptoNetAccountViewModel.class);
|
|
||||||
GrapheneAccountInfoViewModel grapheneAccountInfoViewModel = ViewModelProviders.of(this).get(GrapheneAccountInfoViewModel.class);
|
|
||||||
CryptoNetAccount cryptoNetAccount = new CryptoNetAccount();
|
|
||||||
cryptoNetAccount.setSeedId(seed.getId());
|
|
||||||
cryptoNetAccount.setAccountIndex(0);
|
|
||||||
cryptoNetAccount.setCryptoNet(cy.agorise.crystalwallet.enums.CryptoNet.BITSHARES);
|
|
||||||
cryptoNetAccountViewModel.addCryptoNetAccount(cryptoNetAccount);
|
|
||||||
GrapheneAccountInfo grapheneAccountInfo = new GrapheneAccountInfo(cryptoNetAccount.getId());
|
|
||||||
grapheneAccountInfo.setName(etAccountName.getText().toString());
|
|
||||||
grapheneAccountInfoViewModel.addGrapheneAccountInfo(grapheneAccountInfo);
|
|
||||||
|
|
||||||
this.finish();*/
|
|
||||||
CryptoNetInfoRequests.getInstance().addRequest(validatorRequest);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void finalStep(final CrystalLoading crystalLoading){
|
||||||
|
|
||||||
|
final ImportSeedActivity thisActivity = this;
|
||||||
|
|
||||||
|
final ValidateImportBitsharesAccountRequest validatorRequest =
|
||||||
|
new ValidateImportBitsharesAccountRequest(etAccountName.getText().toString(), etSeedWords.getText().toString(), getApplicationContext(), true);
|
||||||
|
|
||||||
|
validatorRequest.setListener(new CryptoNetInfoRequestListener() {
|
||||||
|
@Override
|
||||||
|
public void onCarryOut() {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hide the loading dialog
|
||||||
|
* */
|
||||||
|
crystalLoading.dismiss();
|
||||||
|
|
||||||
|
if (!validatorRequest.getStatus().equals(ValidateImportBitsharesAccountRequest.StatusCode.SUCCEEDED)) {
|
||||||
|
String errorText = "An error ocurred attempting to import the account";
|
||||||
|
|
||||||
|
switch (validatorRequest.getStatus()){
|
||||||
|
case PETITION_FAILED:
|
||||||
|
case NO_INTERNET:
|
||||||
|
case NO_SERVER_CONNECTION:
|
||||||
|
errorText = "There was an error with the connection. Try again later";
|
||||||
|
break;
|
||||||
|
case ACCOUNT_DOESNT_EXIST:
|
||||||
|
errorText = "The account doesn't exists";
|
||||||
|
break;
|
||||||
|
case BAD_SEED:
|
||||||
|
errorText = "The seed is not valid";
|
||||||
|
break;
|
||||||
|
case NO_ACCOUNT_DATA:
|
||||||
|
errorText = "The account doesn't have any data";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Toast.makeText(thisActivity.getApplicationContext(),errorText,Toast.LENGTH_LONG).show();
|
||||||
|
} else {
|
||||||
|
Intent intent = new Intent(thisActivity, BoardActivity.class);
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
CryptoNetInfoRequests.getInstance().addRequest(validatorRequest);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onValidationSucceeded(final ValidationField field) {
|
public void onValidationSucceeded(final ValidationField field) {
|
||||||
final ImportSeedActivity activity = this;
|
final ImportSeedActivity activity = this;
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class ImportSeedValidator extends UIValidator {
|
||||||
super(context);
|
super(context);
|
||||||
this.addField(new PinValidationField(pinEdit));
|
this.addField(new PinValidationField(pinEdit));
|
||||||
this.addField(new PinConfirmationValidationField(pinEdit,pinConfirmationEdit));
|
this.addField(new PinConfirmationValidationField(pinEdit,pinConfirmationEdit));
|
||||||
this.addField(new BitsharesAccountNameValidationField(bitsharesAccountNameEdit));
|
//this.addField(new BitsharesAccountNameValidationField(bitsharesAccountNameEdit));
|
||||||
this.addField(new BitsharesAccountMnemonicValidationField(mnemonicEdit,bitsharesAccountNameEdit));
|
//this.addField(new BitsharesAccountMnemonicValidationField(mnemonicEdit,bitsharesAccountNameEdit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@
|
||||||
<cy.agorise.crystalwallet.views.natives.CustomTextInputEditText
|
<cy.agorise.crystalwallet.views.natives.CustomTextInputEditText
|
||||||
android:id="@+id/etSeedWords"
|
android:id="@+id/etSeedWords"
|
||||||
android:layout_width="330dp"
|
android:layout_width="330dp"
|
||||||
android:layout_height="120dp"
|
android:layout_height="100dp"
|
||||||
android:hint="@string/Seed"
|
android:hint="@string/Seed"
|
||||||
android:maxLength="255"
|
android:maxLength="255"
|
||||||
android:inputType="textMultiLine" />
|
android:inputType="textMultiLine" />
|
||||||
|
@ -99,15 +99,27 @@
|
||||||
|
|
||||||
</android.support.design.widget.TextInputLayout>
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtErrorAccount"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/tilAccountName"
|
||||||
|
android:textColor="@color/red"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:text="@string/error_invalid_account"
|
||||||
|
android:layout_marginLeft="30dp"
|
||||||
|
android:visibility="invisible"
|
||||||
|
android:layout_marginTop="5dp"/>
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/linearlayoutButtons"
|
android:id="@+id/linearlayoutButtons"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:layout_below="@+id/tilAccountName"
|
android:layout_below="@+id/txtErrorAccount"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_marginTop="40dp">
|
android:layout_marginTop="10dp">
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btnCancel"
|
android:id="@+id/btnCancel"
|
||||||
|
|
Loading…
Reference in a new issue