From 4d3b939f62e479736c0c189d680efed06c14fe48 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Mon, 8 Jan 2018 21:30:02 -0400 Subject: [PATCH] - The create seed activity now makes a request to create the account --- app/src/main/AndroidManifest.xml | 2 + .../activities/CreateSeedActivity.java | 71 +++++++++---------- .../activities/IntroActivity.java | 1 + .../fragments/SendTransactionFragment.java | 6 +- .../validators/CreateSeedValidator.java | 4 +- ...ccountNameDoesntExistsValidationField.java | 38 ++++++---- app/src/main/res/layout/create_seed.xml | 30 -------- 7 files changed, 67 insertions(+), 85 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 240a2e3..453f8ae 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -26,6 +26,8 @@ + + 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 b73db04..9e306a0 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java @@ -13,6 +13,9 @@ import butterknife.ButterKnife; import butterknife.OnClick; import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests; +import cy.agorise.crystalwallet.cryptonetinforequests.ValidateCreateBitsharesAccountRequest; import cy.agorise.crystalwallet.enums.SeedType; import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.CryptoNetAccount; @@ -25,6 +28,8 @@ import cy.agorise.crystalwallet.viewmodels.validators.ImportSeedValidator; import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; +import static cy.agorise.crystalwallet.enums.SeedType.BIP39; + public class CreateSeedActivity extends AppCompatActivity implements UIValidatorListener { AccountSeedViewModel accountSeedViewModel; @@ -40,8 +45,8 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator @BindView(R.id.tvPinConfirmationError) TextView tvPinConfirmationError; - @BindView(R.id.tvSeedWords) - TextView tvSeedWords; + //@BindView(R.id.tvSeedWords) + //TextView tvSeedWords; @BindView (R.id.etAccountName) EditText etAccountName; @@ -58,12 +63,11 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.create_seed); - ButterKnife.bind(this); btnCreate.setEnabled(false); accountSeedViewModel = ViewModelProviders.of(this).get(AccountSeedViewModel.class); - createSeedValidator = new CreateSeedValidator(this.getApplicationContext(),etPin,etPinConfirmation,etAccountName,tvSeedWords); + createSeedValidator = new CreateSeedValidator(this.getApplicationContext(),etPin,etPinConfirmation,etAccountName); createSeedValidator.setListener(this); } @@ -79,12 +83,12 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator this.createSeedValidator.validate(); } - @OnTextChanged(value = R.id.etSeedWords, + /*@OnTextChanged(value = R.id.etSeedWords, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) void afterSeedWordsChanged(Editable editable) { this.createSeedValidator.validate(); } - +*/ @OnTextChanged(value = R.id.etAccountName, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) @@ -97,31 +101,26 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator this.finish(); } - @OnClick(R.id.btnImport) + @OnClick(R.id.btnCreate) public void createSeed(){ if (this.createSeedValidator.isValid()) { - AccountSeed seed = new AccountSeed(); + // Make request to create a bitshare account + final ValidateCreateBitsharesAccountRequest request = + new ValidateCreateBitsharesAccountRequest(etAccountName.getText().toString(), getApplicationContext()); - //TODO verify if words are already in the db - //TODO check if name has been asigned to other seed - seed.setMasterSeed(tvSeedWords.getText().toString()); - seed.setName(etAccountName.getText().toString()); - seed.setType(SeedType.BIP39); + request.setListener(new CryptoNetInfoRequestListener() { + @Override + public void onCarryOut() { + if (request.getAccount() != null){ + finish(); + } else { + createSeedValidator.validate(); + } + } + }); + CryptoNetInfoRequests.getInstance().addRequest(request); - 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(); + //this.finish(); } } @@ -138,14 +137,14 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator tvPinConfirmationError.setText(""); } else if (field.getView() == etAccountName){ tvAccountNameError.setText(""); - } else if (field.getView() == etSeedWords){ - tvSeedWordsError.setText(""); - } + } //else if (field.getView() == etSeedWords){ + // tvSeedWordsError.setText(""); + //} - if (activity.importSeedValidator.isValid()){ - btnImport.setEnabled(true); + if (activity.createSeedValidator.isValid()){ + btnCreate.setEnabled(true); } else { - btnImport.setEnabled(false); + btnCreate.setEnabled(false); } } @@ -160,8 +159,8 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator tvPinConfirmationError.setText(field.getMessage()); } else if (field.getView() == etAccountName){ tvAccountNameError.setText(field.getMessage()); - } else if (field.getView() == etSeedWords){ - tvSeedWordsError.setText(field.getMessage()); - } + } //else if (field.getView() == etSeedWords){ + // tvSeedWordsError.setText(field.getMessage()); + //} } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java index a2b5fc5..2aee5b8 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java @@ -51,6 +51,7 @@ public class IntroActivity extends AppCompatActivity { Intent intent = new Intent(this, ImportSeedActivity.class); startActivity(intent); } else { + //Intent intent = new Intent(this, CreateSeedActivity.class); Intent intent = new Intent(this, BoardActivity.class); startActivity(intent); } 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 6c37d63..8f44adf 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java @@ -84,6 +84,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat private GrapheneAccount grapheneAccount; private CrystalDatabase db; private FloatingActionButton fabSend; + private AlertDialog.Builder builder; public static SendTransactionFragment newInstance(long cryptoNetAccountId) { SendTransactionFragment f = new SendTransactionFragment(); @@ -107,7 +108,8 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat fabSend = getActivity().findViewById(R.id.fabSend); fabSend.hide(); - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.SendTransactionTheme); + //AlertDialog.Builder + builder = new AlertDialog.Builder(getActivity(), R.style.SendTransactionTheme); //builder.setTitle("Send"); LayoutInflater inflater = getActivity().getLayoutInflater(); @@ -169,7 +171,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat @Override public void onDestroy() { super.onDestroy(); - btnScanQrCode = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_NEUTRAL); + // btnScanQrCode = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_NEUTRAL); Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/CreateSeedValidator.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/CreateSeedValidator.java index aff977d..886dd6d 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/CreateSeedValidator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/CreateSeedValidator.java @@ -2,6 +2,7 @@ package cy.agorise.crystalwallet.viewmodels.validators; import android.content.Context; import android.widget.EditText; +import android.widget.TextView; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.BitsharesAccountMnemonicValidationField; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.BitsharesAccountNameDoesntExistsValidationField; @@ -15,11 +16,10 @@ import cy.agorise.crystalwallet.viewmodels.validators.validationfields.PinValida public class CreateSeedValidator extends UIValidator { - public CreateSeedValidator(Context context, EditText pinEdit, EditText pinConfirmationEdit, EditText bitsharesAccountNameEdit, TextView mnemonicTextView){ + public CreateSeedValidator(Context context, EditText pinEdit, EditText pinConfirmationEdit, EditText bitsharesAccountNameEdit){ super(context); this.addField(new PinValidationField(pinEdit)); this.addField(new PinConfirmationValidationField(pinEdit,pinConfirmationEdit)); this.addField(new BitsharesAccountNameDoesntExistsValidationField(bitsharesAccountNameEdit)); - this.addField(new BitsharesAccountMnemonicValidationField(mnemonicTextView)); } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameDoesntExistsValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameDoesntExistsValidationField.java index 152effb..79c965a 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameDoesntExistsValidationField.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameDoesntExistsValidationField.java @@ -24,22 +24,30 @@ public class BitsharesAccountNameDoesntExistsValidationField extends ValidationF final String newValue = accountNameField.getText().toString(); this.setLastValue(newValue); this.startValidating(); - final ValidationField field = this; - final ValidateExistBitsharesAccountRequest request = new ValidateExistBitsharesAccountRequest(newValue); - request.setListener(new CryptoNetInfoRequestListener() { - @Override - public void onCarryOut() { - if (request.getAccountExists()){ - setValidForValue(newValue, false); - setMessage(validator.getContext().getResources().getString(R.string.account_name_already_exist)); - validator.validationFailed(field); - } else { - setValidForValue(newValue, true); - validator.validationSucceeded(field); + if (newValue.equals("")){ + setValidForValue("", false); + setMessage(""); + validator.validationFailed(this); + } else { + + final ValidationField field = this; + + final ValidateExistBitsharesAccountRequest request = new ValidateExistBitsharesAccountRequest(newValue); + request.setListener(new CryptoNetInfoRequestListener() { + @Override + public void onCarryOut() { + if (request.getAccountExists()) { + setValidForValue(newValue, false); + setMessage(validator.getContext().getResources().getString(R.string.account_name_already_exist,"'"+newValue+"'")); + validator.validationFailed(field); + } else { + setValidForValue(newValue, true); + validator.validationSucceeded(field); + } } - } - }); - CryptoNetInfoRequests.getInstance().addRequest(request); + }); + CryptoNetInfoRequests.getInstance().addRequest(request); + } } } diff --git a/app/src/main/res/layout/create_seed.xml b/app/src/main/res/layout/create_seed.xml index c8adc6d..e31aa8e 100644 --- a/app/src/main/res/layout/create_seed.xml +++ b/app/src/main/res/layout/create_seed.xml @@ -73,36 +73,6 @@ android:textColor="@color/red" android:textStyle="bold" /> - - - - - -