From c4ac6b4a29fc198cd3bddffbabbc4a91ff7cc540 Mon Sep 17 00:00:00 2001 From: hvarona Date: Thu, 25 Oct 2018 08:09:54 -0400 Subject: [PATCH 1/2] Fixed error feedback on import request --- .../apigenerator/GrapheneApiGenerator.java | 9 ++- .../manager/BitsharesAccountManager.java | 62 ++++++++++--------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java index b654b48..d4b0cb4 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java @@ -129,8 +129,13 @@ public abstract class GrapheneApiGenerator { List accounts = resp.get(0); if(accounts.size() > 0){ for(UserAccount account : accounts) { - request.getListener().success(account,request.getId());}}} - request.getListener().fail(request.getId()); + request.getListener().success(account, request.getId()); + break; + } + } + }else{ + request.getListener().fail(request.getId()); + } } @Override diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java index 4baf5d9..7f08e20 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -276,44 +276,46 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI @Override public void fail(int idPetition) { - //importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.PETITION_FAILED); - } - }); + BIP39 bip39 = new BIP39(-1, importRequest.getMnemonic()); + ApiRequest getAccountNamesBP39 = new ApiRequest(0, new ApiRequestListener() { + @Override + public void success(Object answer, int idPetition) { + if(answer != null && importRequest.getStatus().equals(ImportBitsharesAccountRequest.StatusCode.NOT_STARTED)) { + UserAccount userAccount = (UserAccount) answer; + importRequest.setSeedType(SeedType.BIP39); + importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.SUCCEEDED); - ApiRequest getAccountNamesBP39 = new ApiRequest(0, new ApiRequestListener() { - @Override - public void success(Object answer, int idPetition) { - if(answer != null && importRequest.getStatus().equals(ImportBitsharesAccountRequest.StatusCode.NOT_STARTED)) { - UserAccount userAccount = (UserAccount) answer; - importRequest.setSeedType(SeedType.BIP39); - importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.SUCCEEDED); - - AccountSeed seed = new AccountSeed(); - seed.setName(userAccount.getName()); - seed.setType(importRequest.getSeedType()); - seed.setMasterSeed(importRequest.getMnemonic()); - long idSeed = accountSeedDao.insertAccountSeed(seed); - if (idSeed >= 0) { - GrapheneAccount account = new GrapheneAccount(); - account.setCryptoNet(CryptoNet.BITSHARES); - account.setAccountIndex(0); - account.setSeedId(idSeed); - account.setAccountId(userAccount.getObjectId()); - importAccountFromSeed(account, importRequest.getContext()); + AccountSeed seed = new AccountSeed(); + seed.setName(userAccount.getName()); + seed.setType(importRequest.getSeedType()); + seed.setMasterSeed(importRequest.getMnemonic()); + long idSeed = accountSeedDao.insertAccountSeed(seed); + if (idSeed >= 0) { + GrapheneAccount account = new GrapheneAccount(); + account.setCryptoNet(CryptoNet.BITSHARES); + account.setAccountIndex(0); + account.setSeedId(idSeed); + account.setAccountId(userAccount.getObjectId()); + importAccountFromSeed(account, importRequest.getContext()); + } + } } - } - } - @Override - public void fail(int idPetition) { - //importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.PETITION_FAILED); + @Override + public void fail(int idPetition) { + importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.PETITION_FAILED); + } + }); + GrapheneApiGenerator.getAccountByOwnerOrActiveAddress(new Address(ECKey.fromPublicOnly(bip39.getBitsharesActiveKey(0).getPubKey())),getAccountNamesBP39); } }); + + BrainKey bk = new BrainKey(importRequest.getMnemonic(), 0); - BIP39 bip39 = new BIP39(-1, importRequest.getMnemonic()); + GrapheneApiGenerator.getAccountByOwnerOrActiveAddress(bk.getPublicAddress("BTS"),getAccountNamesBK); - GrapheneApiGenerator.getAccountByOwnerOrActiveAddress(new Address(ECKey.fromPublicOnly(bip39.getBitsharesActiveKey(0).getPubKey())),getAccountNamesBP39); + } From b426076eea2f906c7d6d5fde795e2003bfb4b58c Mon Sep 17 00:00:00 2001 From: hvarona Date: Thu, 25 Oct 2018 08:30:32 -0400 Subject: [PATCH 2/2] commented the OnResponse interface Fixed error feedback on import request --- .../activities/PatternRequestActivity.java | 20 +++++++++---------- .../activities/PinRequestActivity.java | 16 +++++++-------- .../apigenerator/GrapheneApiGenerator.java | 19 ++++++++++++------ .../application/CrystalSecurityMonitor.java | 20 +++++++++---------- .../fragments/PatternSecurityFragment.java | 2 +- .../fragments/SendTransactionFragment.java | 8 ++++---- .../manager/BitsharesAccountManager.java | 2 +- 7 files changed, 47 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/PatternRequestActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/PatternRequestActivity.java index 3612ff8..ef54cd1 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/PatternRequestActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/PatternRequestActivity.java @@ -25,7 +25,7 @@ import butterknife.ButterKnife; import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.application.CrystalSecurityMonitor; -import cy.agorise.crystalwallet.interfaces.OnResponse; +//import cy.agorise.crystalwallet.interfaces.OnResponse; import cy.agorise.crystalwallet.models.GeneralSetting; import cy.agorise.crystalwallet.util.PasswordManager; import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel; @@ -43,7 +43,7 @@ public class PatternRequestActivity extends AppCompatActivity { /* * External listener for success or fail * */ - private static OnResponse onResponse; + //private static OnResponse onResponse; /* * Contains the bad tries @@ -109,23 +109,23 @@ public class PatternRequestActivity extends AppCompatActivity { //CrystalSecurityMonitor.getInstance(null).call2ndFactor(thisActivity); thisActivity.finish(); - if(onResponse != null){ + /*if(onResponse != null){ onResponse.onSuccess(); - } + }*/ } else { thisActivity.finish(); - if(onResponse != null){ + /*if(onResponse != null){ onResponse.onSuccess(); - } + }*/ } } else { incorrect(); - if(onResponse != null){ + /*if(onResponse != null){ onResponse.onFailed(); - } + }*/ } } @@ -143,9 +143,9 @@ public class PatternRequestActivity extends AppCompatActivity { }); } - public static void setOnResponse(OnResponse onResponse) { + /*public static void setOnResponse(OnResponse onResponse) { PatternRequestActivity.onResponse = onResponse; - } + }*/ private void incorrect(){ diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/PinRequestActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/PinRequestActivity.java index 2f93f18..0b2d3aa 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/PinRequestActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/PinRequestActivity.java @@ -31,7 +31,7 @@ import cy.agorise.crystalwallet.dialogs.material.DialogMaterial; import cy.agorise.crystalwallet.dialogs.material.NegativeResponse; import cy.agorise.crystalwallet.dialogs.material.PositiveResponse; import cy.agorise.crystalwallet.dialogs.material.QuestionDialog; -import cy.agorise.crystalwallet.interfaces.OnResponse; +//import cy.agorise.crystalwallet.interfaces.OnResponse; import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.GeneralSetting; import cy.agorise.crystalwallet.util.PasswordManager; @@ -59,7 +59,7 @@ public class PinRequestActivity extends AppCompatActivity { /* * External listener for success or fail * */ - private static OnResponse onResponse; + //private static OnResponse onResponse; @@ -113,16 +113,16 @@ public class PinRequestActivity extends AppCompatActivity { if (CrystalSecurityMonitor.getInstance(null).is2ndFactorSet()) { CrystalSecurityMonitor.getInstance(null).call2ndFactor(this); - if(onResponse != null){ + /*if(onResponse != null){ onResponse.onSuccess(); - } + }*/ } else { this.finish(); - if(onResponse != null){ + /*if(onResponse != null){ onResponse.onFailed(); - } + }*/ } } else{ @@ -221,9 +221,9 @@ public class PinRequestActivity extends AppCompatActivity { } - public static void setOnResponse(OnResponse onResponse) { + /*public static void setOnResponse(OnResponse onResponse) { PinRequestActivity.onResponse = onResponse; - } + }*/ @OnTextChanged(value = R.id.etPassword, diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java index d4b0cb4..d2451f4 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java @@ -124,16 +124,23 @@ public abstract class GrapheneApiGenerator { new WitnessResponseListener() { @Override public void onSuccess(WitnessResponse response) { - final List> resp = (List>) response.result; - if(resp.size() > 0){ - List accounts = resp.get(0); - if(accounts.size() > 0){ - for(UserAccount account : accounts) { + try { + final List> resp = (List>) response.result; + if (resp.size() > 0) { + List accounts = resp.get(0); + if (accounts.size() > 0) { + for (UserAccount account : accounts) { request.getListener().success(account, request.getId()); break; + } + }else{ + request.getListener().fail(request.getId()); } + } else { + request.getListener().fail(request.getId()); } - }else{ + }catch(Exception e){ + e.printStackTrace(); request.getListener().fail(request.getId()); } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/application/CrystalSecurityMonitor.java b/app/src/main/java/cy/agorise/crystalwallet/application/CrystalSecurityMonitor.java index 3ed54da..b7235aa 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/application/CrystalSecurityMonitor.java +++ b/app/src/main/java/cy/agorise/crystalwallet/application/CrystalSecurityMonitor.java @@ -17,7 +17,7 @@ import cy.agorise.crystalwallet.activities.PatternRequestActivity; import cy.agorise.crystalwallet.activities.PinRequestActivity; import cy.agorise.crystalwallet.activities.PocketRequestActivity; import cy.agorise.crystalwallet.fragments.PatternSecurityFragment; -import cy.agorise.crystalwallet.interfaces.OnResponse; +//import cy.agorise.crystalwallet.interfaces.OnResponse; import cy.agorise.crystalwallet.models.GeneralSetting; import cy.agorise.crystalwallet.notifiers.CrystalWalletNotifier; import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel; @@ -131,7 +131,7 @@ public class CrystalSecurityMonitor implements Application.ActivityLifecycleCall public void onActivityStarted(Activity activity) { if (numStarted == 0) { if (!actualSecurity().equals("")){ - callPasswordRequest(activity,null); + callPasswordRequest(activity); } } numStarted++; @@ -142,39 +142,39 @@ public class CrystalSecurityMonitor implements Application.ActivityLifecycleCall numStarted--; if (numStarted == 0) { if (!actualSecurity().equals("")){ - callPasswordRequest(activity,null); + callPasswordRequest(activity); } } } - public void callPasswordRequest(Activity activity, final OnResponse onResponsePattern){ + public void callPasswordRequest(Activity activity){ if ((!activity.getIntent().hasExtra("ACTIVITY_TYPE")) || (!activity.getIntent().getStringExtra("ACTIVITY_TYPE").equals("PASSWORD_REQUEST"))) { Intent intent = null; if ((this.passwordEncrypted != null) && (!this.passwordEncrypted.equals(""))) { intent = new Intent(activity, PinRequestActivity.class); - PinRequestActivity.setOnResponse(null); + //PinRequestActivity.setOnResponse(null); /* * Connect error and success listeners * */ - if(onResponsePattern != null){ + /*if(onResponsePattern != null){ PinRequestActivity.setOnResponse(onResponsePattern); - } + }*/ } else if ((this.patternEncrypted != null) && (!this.patternEncrypted.equals(""))) { intent = new Intent(activity, PatternRequestActivity.class); - PatternRequestActivity.setOnResponse(null); + //PatternRequestActivity.setOnResponse(null); /* * Connect error and success listeners * */ - if(onResponsePattern != null){ + /*if(onResponsePattern != null){ PatternRequestActivity.setOnResponse(onResponsePattern); - } + }*/ } if (intent != null) { intent.putExtra("ACTIVITY_TYPE", "PASSWORD_REQUEST"); diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/PatternSecurityFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/PatternSecurityFragment.java index c23306f..66732c1 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/PatternSecurityFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/PatternSecurityFragment.java @@ -30,7 +30,7 @@ import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.application.CrystalSecurityMonitor; import cy.agorise.crystalwallet.dialogs.material.CrystalDialog; -import cy.agorise.crystalwallet.interfaces.OnResponse; +//import cy.agorise.crystalwallet.interfaces.OnResponse; import cy.agorise.crystalwallet.models.GeneralSetting; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests; import cy.agorise.crystalwallet.util.ChildViewPager; 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 45b5185..bc97df5 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java @@ -61,7 +61,7 @@ import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.application.CrystalSecurityMonitor; import cy.agorise.crystalwallet.dialogs.material.CrystalDialog; import cy.agorise.crystalwallet.dialogs.material.ToastIt; -import cy.agorise.crystalwallet.interfaces.OnResponse; +//import cy.agorise.crystalwallet.interfaces.OnResponse; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests; import cy.agorise.crystalwallet.requestmanagers.ValidateBitsharesSendRequest; @@ -623,14 +623,14 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat /* * If exists mode scurity show it and valide events in case of success or fail * */ - CrystalSecurityMonitor.getInstance(null).callPasswordRequest(this.getActivity(), new OnResponse() { + /*CrystalSecurityMonitor.getInstance(null).callPasswordRequest(this.getActivity(), new OnResponse() { @Override public void onSuccess() { /* * Show loading dialog * */ - crystalDialog = new CrystalDialog((Activity) getContext()); +/* crystalDialog = new CrystalDialog((Activity) getContext()); crystalDialog.setText("Sending"); crystalDialog.progress(); crystalDialog.show(); @@ -642,7 +642,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat public void onFailed() { } - }); + });*/ } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java index 7f08e20..32ae22e 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -303,7 +303,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI @Override public void fail(int idPetition) { - importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.PETITION_FAILED); + importRequest.setStatus(ImportBitsharesAccountRequest.StatusCode.BAD_SEED); } }); GrapheneApiGenerator.getAccountByOwnerOrActiveAddress(new Address(ECKey.fromPublicOnly(bip39.getBitsharesActiveKey(0).getPubKey())),getAccountNamesBP39);