diff --git a/app/src/main/java/com/coinblesk/client/MainActivity.java b/app/src/main/java/com/coinblesk/client/MainActivity.java index 13f4705..91e8b80 100644 --- a/app/src/main/java/com/coinblesk/client/MainActivity.java +++ b/app/src/main/java/com/coinblesk/client/MainActivity.java @@ -473,13 +473,21 @@ public void onServiceConnected(ComponentName className, IBinder binder) { walletServiceBinder = (WalletService.WalletServiceBinder) binder; initPeers(); - if (SharedPrefUtils.isMultisig2of2ToCltvForwardingEnabled(MainActivity.this)) { - new Multisig2of2ToCltvForwardTask(MainActivity.this, - walletServiceBinder, - walletServiceBinder.getMultisigClientKey(), - walletServiceBinder.getMultisigServerKey()) - .execute(); - } + + walletServiceBinder.onWalletLoaded(new Runnable(){ + @Override + public void run() { + if (SharedPrefUtils.isMultisig2of2ToCltvForwardingEnabled(MainActivity.this)) { + new Multisig2of2ToCltvForwardTask(MainActivity.this, + walletServiceBinder, + walletServiceBinder.getMultisigClientKey(), + walletServiceBinder.getMultisigServerKey()) + .execute(); + } + } + }); + + } diff --git a/payments/src/main/java/com/coinblesk/payments/WalletService.java b/payments/src/main/java/com/coinblesk/payments/WalletService.java index 69708f2..8add3b7 100644 --- a/payments/src/main/java/com/coinblesk/payments/WalletService.java +++ b/payments/src/main/java/com/coinblesk/payments/WalletService.java @@ -199,8 +199,12 @@ protected void onSetupCompleted() { keyExchange(); loadKeysIfExist(); } + initAddresses(); + if(walletLRunnable!=null) { + walletLRunnable.run(); + } appKitInitDone = true; broadcastBalanceChanged(); } catch (Exception e) { @@ -1283,8 +1287,21 @@ public boolean isReady() { public void restartWalletService() { WalletService.this.restartWalletService(); } + + + public void onWalletLoaded(Runnable walletLRunnable) { + + if(getMultisigClientKey() != null && getMultisigServerKey()!=null) { + walletLRunnable.run(); + WalletService.this.walletLRunnable = null; + } else { + WalletService.this.walletLRunnable = walletLRunnable; + } + } } + private Runnable walletLRunnable; + private class CoinbleskWalletEventListener implements WalletCoinsReceivedEventListener, WalletCoinsSentEventListener, ScriptsChangeEventListener, diff --git a/payments/src/main/java/com/coinblesk/payments/communications/peers/nfc/NFCClientServiceCLTV.java b/payments/src/main/java/com/coinblesk/payments/communications/peers/nfc/NFCClientServiceCLTV.java index 4e92bbe..e976fb0 100644 --- a/payments/src/main/java/com/coinblesk/payments/communications/peers/nfc/NFCClientServiceCLTV.java +++ b/payments/src/main/java/com/coinblesk/payments/communications/peers/nfc/NFCClientServiceCLTV.java @@ -22,6 +22,7 @@ import com.coinblesk.der.DERObject; import com.coinblesk.der.DERParser; import com.coinblesk.payments.WalletService; +import com.coinblesk.payments.communications.PaymentError; import com.coinblesk.payments.communications.PaymentException; import com.coinblesk.payments.communications.steps.cltv.PaymentFinalizeStep; import com.coinblesk.payments.communications.steps.cltv.PaymentRequestReceiveStep; @@ -294,7 +295,11 @@ public void run() { } catch (PaymentException pe) { approveAddress = null; approveAmount = null; - broadcastInsufficientBalance(); + if(pe.getErrorCode() == PaymentError.INSUFFICIENT_FUNDS) { + broadcastInsufficientBalance(); + } else { + broadcastError(); + } long duration = System.currentTimeMillis() - processStartTime; Log.d(TAG, "Payment not completed: " + duration + "ms"); pe.printStackTrace(); @@ -373,6 +378,13 @@ private void broadcastInsufficientBalance() { .sendBroadcast(insufficientBalance); } + private void broadcastError() { + Intent intent = new Intent(Constants.WALLET_ERROR_ACTION); + LocalBroadcastManager + .getInstance(NFCClientServiceCLTV.this) + .sendBroadcast(intent); + } + private void broadcastInstantPaymentSuccess() { Intent instantPaymentSuccess = new Intent(Constants.INSTANT_PAYMENT_SUCCESSFUL_ACTION); LocalBroadcastManager