- The create seed activity now makes a request to create the account

This commit is contained in:
Javier Varona 2018-01-08 21:30:02 -04:00
parent 06ef3e3dc3
commit 4d3b939f62
7 changed files with 67 additions and 85 deletions

View file

@ -26,6 +26,8 @@
</activity> </activity>
<activity android:name=".activities.ImportSeedActivity" > <activity android:name=".activities.ImportSeedActivity" >
</activity> </activity>
<activity android:name=".activities.CreateSeedActivity" >
</activity>
<activity android:name=".activities.SendTransactionActivity" > <activity android:name=".activities.SendTransactionActivity" >
</activity> </activity>
<activity android:name=".activities.GeneralSettingsActivity" > <activity android:name=".activities.GeneralSettingsActivity" >

View file

@ -13,6 +13,9 @@ import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
import butterknife.OnTextChanged; import butterknife.OnTextChanged;
import cy.agorise.crystalwallet.R; 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.enums.SeedType;
import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.AccountSeed;
import cy.agorise.crystalwallet.models.CryptoNetAccount; 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.UIValidatorListener;
import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField;
import static cy.agorise.crystalwallet.enums.SeedType.BIP39;
public class CreateSeedActivity extends AppCompatActivity implements UIValidatorListener { public class CreateSeedActivity extends AppCompatActivity implements UIValidatorListener {
AccountSeedViewModel accountSeedViewModel; AccountSeedViewModel accountSeedViewModel;
@ -40,8 +45,8 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator
@BindView(R.id.tvPinConfirmationError) @BindView(R.id.tvPinConfirmationError)
TextView tvPinConfirmationError; TextView tvPinConfirmationError;
@BindView(R.id.tvSeedWords) //@BindView(R.id.tvSeedWords)
TextView tvSeedWords; //TextView tvSeedWords;
@BindView (R.id.etAccountName) @BindView (R.id.etAccountName)
EditText etAccountName; EditText etAccountName;
@ -58,12 +63,11 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.create_seed); setContentView(R.layout.create_seed);
ButterKnife.bind(this); ButterKnife.bind(this);
btnCreate.setEnabled(false); btnCreate.setEnabled(false);
accountSeedViewModel = ViewModelProviders.of(this).get(AccountSeedViewModel.class); 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); createSeedValidator.setListener(this);
} }
@ -79,12 +83,12 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator
this.createSeedValidator.validate(); this.createSeedValidator.validate();
} }
@OnTextChanged(value = R.id.etSeedWords, /*@OnTextChanged(value = R.id.etSeedWords,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void afterSeedWordsChanged(Editable editable) { void afterSeedWordsChanged(Editable editable) {
this.createSeedValidator.validate(); this.createSeedValidator.validate();
} }
*/
@OnTextChanged(value = R.id.etAccountName, @OnTextChanged(value = R.id.etAccountName,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
@ -97,31 +101,26 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator
this.finish(); this.finish();
} }
@OnClick(R.id.btnImport) @OnClick(R.id.btnCreate)
public void createSeed(){ public void createSeed(){
if (this.createSeedValidator.isValid()) { 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 request.setListener(new CryptoNetInfoRequestListener() {
//TODO check if name has been asigned to other seed @Override
seed.setMasterSeed(tvSeedWords.getText().toString()); public void onCarryOut() {
seed.setName(etAccountName.getText().toString()); if (request.getAccount() != null){
seed.setType(SeedType.BIP39); finish();
} else {
createSeedValidator.validate();
}
}
});
CryptoNetInfoRequests.getInstance().addRequest(request);
accountSeedViewModel.addSeed(seed); //this.finish();
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();
} }
} }
@ -138,14 +137,14 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator
tvPinConfirmationError.setText(""); tvPinConfirmationError.setText("");
} else if (field.getView() == etAccountName){ } else if (field.getView() == etAccountName){
tvAccountNameError.setText(""); tvAccountNameError.setText("");
} else if (field.getView() == etSeedWords){ } //else if (field.getView() == etSeedWords){
tvSeedWordsError.setText(""); // tvSeedWordsError.setText("");
} //}
if (activity.importSeedValidator.isValid()){ if (activity.createSeedValidator.isValid()){
btnImport.setEnabled(true); btnCreate.setEnabled(true);
} else { } else {
btnImport.setEnabled(false); btnCreate.setEnabled(false);
} }
} }
@ -160,8 +159,8 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator
tvPinConfirmationError.setText(field.getMessage()); tvPinConfirmationError.setText(field.getMessage());
} else if (field.getView() == etAccountName){ } else if (field.getView() == etAccountName){
tvAccountNameError.setText(field.getMessage()); tvAccountNameError.setText(field.getMessage());
} else if (field.getView() == etSeedWords){ } //else if (field.getView() == etSeedWords){
tvSeedWordsError.setText(field.getMessage()); // tvSeedWordsError.setText(field.getMessage());
} //}
} }
} }

View file

@ -51,6 +51,7 @@ public class IntroActivity extends AppCompatActivity {
Intent intent = new Intent(this, ImportSeedActivity.class); Intent intent = new Intent(this, ImportSeedActivity.class);
startActivity(intent); startActivity(intent);
} else { } else {
//Intent intent = new Intent(this, CreateSeedActivity.class);
Intent intent = new Intent(this, BoardActivity.class); Intent intent = new Intent(this, BoardActivity.class);
startActivity(intent); startActivity(intent);
} }

View file

@ -84,6 +84,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
private GrapheneAccount grapheneAccount; private GrapheneAccount grapheneAccount;
private CrystalDatabase db; private CrystalDatabase db;
private FloatingActionButton fabSend; private FloatingActionButton fabSend;
private AlertDialog.Builder builder;
public static SendTransactionFragment newInstance(long cryptoNetAccountId) { public static SendTransactionFragment newInstance(long cryptoNetAccountId) {
SendTransactionFragment f = new SendTransactionFragment(); SendTransactionFragment f = new SendTransactionFragment();
@ -107,7 +108,8 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
fabSend = getActivity().findViewById(R.id.fabSend); fabSend = getActivity().findViewById(R.id.fabSend);
fabSend.hide(); 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"); //builder.setTitle("Send");
LayoutInflater inflater = getActivity().getLayoutInflater(); LayoutInflater inflater = getActivity().getLayoutInflater();
@ -169,7 +171,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
btnScanQrCode = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_NEUTRAL); // btnScanQrCode = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_NEUTRAL);
Handler handler = new Handler(); Handler handler = new Handler();
handler.postDelayed(new Runnable() { handler.postDelayed(new Runnable() {
public void run() { public void run() {

View file

@ -2,6 +2,7 @@ package cy.agorise.crystalwallet.viewmodels.validators;
import android.content.Context; import android.content.Context;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView;
import cy.agorise.crystalwallet.viewmodels.validators.validationfields.BitsharesAccountMnemonicValidationField; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.BitsharesAccountMnemonicValidationField;
import cy.agorise.crystalwallet.viewmodels.validators.validationfields.BitsharesAccountNameDoesntExistsValidationField; 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 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); 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 BitsharesAccountNameDoesntExistsValidationField(bitsharesAccountNameEdit)); this.addField(new BitsharesAccountNameDoesntExistsValidationField(bitsharesAccountNameEdit));
this.addField(new BitsharesAccountMnemonicValidationField(mnemonicTextView));
} }
} }

View file

@ -24,22 +24,30 @@ public class BitsharesAccountNameDoesntExistsValidationField extends ValidationF
final String newValue = accountNameField.getText().toString(); final String newValue = accountNameField.getText().toString();
this.setLastValue(newValue); this.setLastValue(newValue);
this.startValidating(); this.startValidating();
final ValidationField field = this;
final ValidateExistBitsharesAccountRequest request = new ValidateExistBitsharesAccountRequest(newValue); if (newValue.equals("")){
request.setListener(new CryptoNetInfoRequestListener() { setValidForValue("", false);
@Override setMessage("");
public void onCarryOut() { validator.validationFailed(this);
if (request.getAccountExists()){ } else {
setValidForValue(newValue, false);
setMessage(validator.getContext().getResources().getString(R.string.account_name_already_exist)); final ValidationField field = this;
validator.validationFailed(field);
} else { final ValidateExistBitsharesAccountRequest request = new ValidateExistBitsharesAccountRequest(newValue);
setValidForValue(newValue, true); request.setListener(new CryptoNetInfoRequestListener() {
validator.validationSucceeded(field); @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); }
} }
} }

View file

@ -73,36 +73,6 @@
android:textColor="@color/red" android:textColor="@color/red"
android:textStyle="bold" /> android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="10dp"
android:text="@string/seed_words"
android:textStyle="bold" />
<TextView
android:id="@+id/tvSeedWords"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:background="@drawable/edittext_bg"
android:gravity="top"
android:inputType="textMultiLine"
android:textColor="@color/black" />
<TextView
android:id="@+id/tvSeedWordsError"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="10dp"
android:textColor="@color/red"
android:textStyle="bold" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"