This commit is contained in:
Javier Varona 2018-04-22 20:28:18 -04:00
commit 032cc6fae5
5 changed files with 64 additions and 45 deletions

View file

@ -130,17 +130,14 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator
@Override
public void onCarryOut() {
processDialog.dismiss();
if (request.getAccount() != null){
if (request.getStatus().equals(ValidateCreateBitsharesAccountRequest.StatusCode.SUCCEEDED)) {
GrapheneAccount accountSeed = request.getAccount();
Intent intent = new Intent(getApplicationContext(), BackupSeedActivity.class);
intent.putExtra("SEED_ID",accountSeed.getId());
intent.putExtra("SEED_ID", accountSeed.getId());
startActivity(intent);
} else {
createSeedValidator.validate();
}
}
});

View file

@ -301,7 +301,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
sendRequest.setListener(new CryptoNetInfoRequestListener() {
@Override
public void onCarryOut() {
if (sendRequest.isSend()){
if (sendRequest.getStatus().equals(ValidateBitsharesSendRequest.StatusCode.SUCCEEDED)){
try {
this.finalize();
} catch (Throwable throwable) {

View file

@ -289,6 +289,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
}
private void validateCreateAccount(final ValidateCreateBitsharesAccountRequest createRequest){
//TODO test for internet and server connection
// Generate seed or find key
Context context = createRequest.getContext();
AccountSeed seed = AccountSeed.getAccountSeed(SeedType.BIP39, context);
@ -306,13 +307,13 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
@Override
public void success(Object answer) {
createRequest.setAccountExists(false);
createRequest.setAccount((GrapheneAccount) answer);
createRequest.setStatus(ValidateCreateBitsharesAccountRequest.StatusCode.SUCCEEDED);
}
@Override
public void fail() {
createRequest.setAccountExists(true);
createRequest.setStatus(ValidateCreateBitsharesAccountRequest.StatusCode.ACCOUNT_EXIST);
}
}, context);
@ -348,6 +349,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
* Broadcast a transaction request
*/
private void validateSendRequest(final ValidateBitsharesSendRequest sendRequest) {
//TODO check internet, server connection
//TODO feeAsset
CrystalDatabase db = CrystalDatabase.getAppDatabase(sendRequest.getContext());
CryptoCurrency currency = db.cryptoCurrencyDao().getByNameAndCryptoNet(sendRequest.getAsset(), CryptoNet.BITSHARES.name());
@ -360,7 +362,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
@Override
public void fail() {
sendRequest.setStatus(ValidateBitsharesSendRequest.StatusCode.NO_ASSET_INFO_DB);
}
});
}else{
@ -374,7 +376,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
@Override
public void fail() {
sendRequest.setStatus(ValidateBitsharesSendRequest.StatusCode.NO_ASSET_INFO);
}
});
}else {
@ -415,12 +417,12 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
ApiRequest transactionRequest = new ApiRequest(0, new ApiRequestListener() {
@Override
public void success(Object answer, int idPetition) {
sendRequest.setSend(true);
sendRequest.setStatus(ValidateBitsharesSendRequest.StatusCode.SUCCEEDED);
}
@Override
public void fail(int idPetition) {
sendRequest.setSend(false);
sendRequest.setStatus(ValidateBitsharesSendRequest.StatusCode.PETITION_FAILED);
}
});
@ -429,7 +431,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
@Override
public void fail() {
//TODO bad user to user account
sendRequest.setStatus(ValidateBitsharesSendRequest.StatusCode.NO_TO_USER_INFO);
}
});

View file

@ -12,6 +12,20 @@ import cy.agorise.crystalwallet.models.GrapheneAccount;
*/
public class ValidateBitsharesSendRequest extends CryptoNetInfoRequest {
/**
* The status code of this request
*/
public enum StatusCode{
NOT_STARTED,
SUCCEEDED,
NO_INTERNET,
NO_SERVER_CONNECTION,
NO_ASSET_INFO_DB,
NO_ASSET_INFO,
NO_TO_USER_INFO,
PETITION_FAILED
}
// The app context
private Context mContext;
// The source account used to transfer fund from
@ -25,7 +39,7 @@ public class ValidateBitsharesSendRequest extends CryptoNetInfoRequest {
// The memo, can be null
private String mMemo;
// The state of this request
private Boolean isSend;
private StatusCode status = StatusCode.NOT_STARTED;
public ValidateBitsharesSendRequest(Context context, GrapheneAccount sourceAccount,
String toAccount, long amount, String asset, String memo) {
@ -68,18 +82,18 @@ public class ValidateBitsharesSendRequest extends CryptoNetInfoRequest {
return mMemo;
}
public boolean isSend() {
return isSend;
}
public void setSend(boolean send) {
isSend = send;
this.validate();
}
public void validate(){
if ((this.isSend != null)){
if ((this.status != StatusCode.NOT_STARTED)){
this._fireOnCarryOutEvent();
}
}
public void setStatus(StatusCode code){
this.status = code;
this._fireOnCarryOutEvent();
}
public StatusCode getStatus() {
return status;
}
}

View file

@ -14,15 +14,27 @@ import cy.agorise.crystalwallet.models.GrapheneAccount;
public class ValidateCreateBitsharesAccountRequest extends CryptoNetInfoRequest {
/**
* The status code of this request
*/
public enum StatusCode{
NOT_STARTED,
SUCCEEDED,
NO_INTERNET,
NO_SERVER_CONNECTION,
ACCOUNT_EXIST,
NO_ACCOUNT_DATA
}
/**
* The name of the account
*/
private String accountName;
/**
* Indicates if the account exist
*/
private Boolean accountExists;
// The state of this request
private StatusCode status = StatusCode.NOT_STARTED;
private GrapheneAccount account;
@ -34,34 +46,19 @@ public class ValidateCreateBitsharesAccountRequest extends CryptoNetInfoRequest
this.context = context;
}
public void setAccountExists(boolean value){
this.accountExists = value;
this.validate();
}
public void setAccount(GrapheneAccount account){
this.account = account;
this.validate();
}
public boolean getAccountExists(){
return this.accountExists;
}
public GrapheneAccount getAccount() {
return account;
}
public void validate(){
if ((this.accountExists != null)){// && (this.account != null)){
if (this.accountExists == true) {
this._fireOnCarryOutEvent();
} else {
if (this.account != null){
this._fireOnCarryOutEvent();
}
}
}
if(!status.equals(StatusCode.NOT_STARTED))
this._fireOnCarryOutEvent();
}
public String getAccountName() {
@ -75,4 +72,13 @@ public class ValidateCreateBitsharesAccountRequest extends CryptoNetInfoRequest
public Context getContext() {
return context;
}
public void setStatus(StatusCode code){
this.status = code;
this.validate();
}
public StatusCode getStatus() {
return status;
}
}