diff --git a/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymController.java b/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymController.java index 8225b84c..ef474c22 100644 --- a/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymController.java +++ b/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymController.java @@ -321,7 +321,9 @@ public class PayNymController { public boolean isLinked(PayNym payNym) { PaymentCode externalPaymentCode = payNym.paymentCode(); - return getMasterWallet().getChildWallet(externalPaymentCode, payNym.segwit() ? ScriptType.P2WPKH : ScriptType.P2PKH) != null; + //As per BIP47 a notification transaction must have been sent from this wallet to enable the recipient to restore funds from seed + return getMasterWallet().getChildWallet(externalPaymentCode, payNym.segwit() ? ScriptType.P2WPKH : ScriptType.P2PKH) != null + && !getNotificationTransaction(externalPaymentCode).isEmpty(); } public void updateFollowing() { @@ -356,7 +358,7 @@ public class PayNymController { for(PayNym payNym : following) { if(!isLinked(payNym)) { PaymentCode externalPaymentCode = payNym.paymentCode(); - Map unlinkedNotification = getMasterWallet().getNotificationTransaction(externalPaymentCode); + Map unlinkedNotification = getNotificationTransaction(externalPaymentCode); if(!unlinkedNotification.isEmpty() && !INVALID_PAYMENT_CODE_LABEL.equals(unlinkedNotification.keySet().iterator().next().getLabel())) { unlinkedNotifications.putAll(unlinkedNotification); unlinkedPayNyms.put(unlinkedNotification.keySet().iterator().next(), payNym); @@ -607,6 +609,22 @@ public class PayNymController { return wallet.createWalletTransaction(utxoSelectors, utxoFilters, payments, opReturns, Collections.emptySet(), feeRate, minimumFeeRate, null, AppServices.getCurrentBlockHeight(), groupByAddress, includeMempoolOutputs, false); } + private Map getNotificationTransaction(PaymentCode externalPaymentCode) { + Map notificationTransaction = getMasterWallet().getNotificationTransaction(externalPaymentCode); + if(notificationTransaction.isEmpty()) { + for(Wallet childWallet : getMasterWallet().getChildWallets()) { + if(!childWallet.isNested()) { + notificationTransaction = childWallet.getNotificationTransaction(externalPaymentCode); + if(!notificationTransaction.isEmpty()) { + return notificationTransaction; + } + } + } + } + + return notificationTransaction; + } + public Wallet getMasterWallet() { Wallet wallet = AppServices.get().getWallet(walletId); return wallet.isMasterWallet() ? wallet : wallet.getMasterWallet(); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletController.java index ad9efe16..2ff5914c 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletController.java @@ -90,7 +90,12 @@ public class WalletController extends WalletFormController implements Initializa try { if(!existing) { - FXMLLoader functionLoader = new FXMLLoader(AppServices.class.getResource("wallet/" + function.toString().toLowerCase() + ".fxml")); + URL url = AppServices.class.getResource("wallet/" + function.toString().toLowerCase() + ".fxml"); + if(url == null) { + throw new IllegalStateException("Cannot find wallet/" + function.toString().toLowerCase() + ".fxml"); + } + + FXMLLoader functionLoader = new FXMLLoader(url); Node walletFunction = functionLoader.load(); walletFunction.setUserData(function); WalletFormController controller = functionLoader.getController();