- 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 android:name=".activities.ImportSeedActivity" >
</activity>
<activity android:name=".activities.CreateSeedActivity" >
</activity>
<activity android:name=".activities.SendTransactionActivity" >
</activity>
<activity android:name=".activities.GeneralSettingsActivity" >

View file

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

View file

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

View file

@ -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() {

View file

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

View file

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

View file

@ -73,36 +73,6 @@
android:textColor="@color/red"
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
android:layout_width="match_parent"
android:layout_height="wrap_content"