-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:
dtvv 2018-10-18 03:28:12 -05:00
parent 8a7b41ad1d
commit b73c77e86f
3 changed files with 94 additions and 61 deletions

View file

@ -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,6 +304,45 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator
final CrystalLoading crystalLoading = new CrystalLoading(activity); final CrystalLoading crystalLoading = new CrystalLoading(activity);
crystalLoading.show(); crystalLoading.show();
/*
* Validate mnemonic with the server
* */
final ValidateImportBitsharesAccountRequest request = new ValidateImportBitsharesAccountRequest(etAccountName.getText().toString().trim(),etSeedWords.getText().toString().trim(),this);
request.setListener(new CryptoNetInfoRequestListener() {
@Override
public void onCarryOut() {
if(request.getStatus().equals(ValidateImportBitsharesAccountRequest.StatusCode.SUCCEEDED)){
//Correct
/*
* Final service connection
* */
finalStep(crystalLoading);
}
else{
crystalLoading.dismiss();
txtErrorAccount.setVisibility(View.VISIBLE);
txtErrorAccount.setText(activity.getResources().getString(R.string.error_invalid_account));
}
}
});
CryptoNetInfoRequests.getInstance().addRequest(request);
}
}
private void finalStep(final CrystalLoading crystalLoading){
final ImportSeedActivity thisActivity = this;
final ValidateImportBitsharesAccountRequest validatorRequest = final ValidateImportBitsharesAccountRequest validatorRequest =
new ValidateImportBitsharesAccountRequest(etAccountName.getText().toString(), etSeedWords.getText().toString(), getApplicationContext(), true); new ValidateImportBitsharesAccountRequest(etAccountName.getText().toString(), etSeedWords.getText().toString(), getApplicationContext(), true);
@ -338,33 +383,9 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator
} }
} }
}); });
/*CryptoNetInfoRequests.getInstance().addRequest(validatorRequest);
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); CryptoNetInfoRequests.getInstance().addRequest(validatorRequest);
} }
}
@Override @Override
public void onValidationSucceeded(final ValidationField field) { public void onValidationSucceeded(final ValidationField field) {

View file

@ -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));
} }
} }

View file

@ -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"