mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 13:26:44 +00:00
fix export from settings tabs for new account by ensuring bidirectional links are restored on save
This commit is contained in:
parent
6990b398c2
commit
2972f1a4d7
2 changed files with 11 additions and 13 deletions
|
@ -458,18 +458,10 @@ public class SettingsController extends WalletFormController implements Initiali
|
|||
}
|
||||
|
||||
Optional<Wallet> optWallet = AppServices.get().getOpenWallets().entrySet().stream()
|
||||
.filter(entry -> walletForm.getWalletFile().equals(entry.getValue().getWalletFile()) && entry.getKey().isMasterWallet()).map(Map.Entry::getKey).findFirst();
|
||||
.filter(entry -> walletForm.getWalletFile().equals(entry.getValue().getWalletFile())
|
||||
&& entry.getKey().getName().equals(walletForm.getWallet().getName())).map(Map.Entry::getKey).findFirst();
|
||||
if(optWallet.isPresent()) {
|
||||
Wallet wallet = optWallet.get();
|
||||
if(!walletForm.getWallet().getName().equals(wallet.getName())) {
|
||||
wallet = wallet.getChildWallet(walletForm.getWallet().getName());
|
||||
}
|
||||
|
||||
if(wallet == null) {
|
||||
throw new IllegalStateException("Cannot find child wallet " + walletForm.getWallet().getFullDisplayName() + " to export");
|
||||
}
|
||||
|
||||
WalletExportDialog dlg = new WalletExportDialog(wallet);
|
||||
WalletExportDialog dlg = new WalletExportDialog(optWallet.get());
|
||||
dlg.showAndWait();
|
||||
} else {
|
||||
AppServices.showErrorDialog("Cannot export wallet", "Wallet cannot be exported, please save it first.");
|
||||
|
|
|
@ -60,15 +60,21 @@ public class SettingsWalletForm extends WalletForm {
|
|||
//Clear node tree, detaching and saving any labels from the existing wallet
|
||||
walletCopy.clearNodes(wallet);
|
||||
|
||||
//Retrieve master or child wallets from current active wallet before overwriting
|
||||
Wallet masterWallet = wallet.isMasterWallet() ? null : wallet.getMasterWallet();
|
||||
Integer childIndex = wallet.isMasterWallet() ? null : wallet.getMasterWallet().getChildWallets().indexOf(wallet);
|
||||
List<Wallet> childWallets = wallet.getChildWallets();
|
||||
|
||||
//Replace the SettingsWalletForm wallet reference - note that this reference is only shared with the WalletForm wallet with WalletAddressesChangedEvent below
|
||||
wallet = walletCopy.copy();
|
||||
|
||||
//Restore bidirectional links between original master or child wallets
|
||||
if(wallet.isMasterWallet()) {
|
||||
wallet.setChildWallets(childWallets);
|
||||
wallet.getChildWallets().forEach(childWallet -> childWallet.setMasterWallet(wallet));
|
||||
} else if(childIndex != null) {
|
||||
wallet.getMasterWallet().getChildWallets().set(childIndex, wallet);
|
||||
} else if(masterWallet != null && childIndex != null) {
|
||||
wallet.setMasterWallet(masterWallet);
|
||||
masterWallet.getChildWallets().set(childIndex, wallet);
|
||||
}
|
||||
|
||||
save();
|
||||
|
|
Loading…
Reference in a new issue