diff --git a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/AddressesDialog.java b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/AddressesDialog.java index a8e03784..0bbfe406 100644 --- a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/AddressesDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/AddressesDialog.java @@ -38,7 +38,8 @@ public class AddressesDialog extends WalletDialog { updateAddresses(); - Panel buttonPanel = new Panel(new GridLayout(4).setHorizontalSpacing(2).setVerticalSpacing(0)); + Panel buttonPanel = new Panel(new GridLayout(5).setHorizontalSpacing(2).setVerticalSpacing(0)); + buttonPanel.addComponent(new EmptySpace(new TerminalSize(15, 1))); buttonPanel.addComponent(new EmptySpace(new TerminalSize(15, 1))); buttonPanel.addComponent(new EmptySpace(new TerminalSize(15, 1))); buttonPanel.addComponent(new Button("Back", () -> onBack(Function.ADDRESSES))); @@ -74,7 +75,7 @@ public class AddressesDialog extends WalletDialog { private String[] getTableColumns() { String address = getWalletForm().getNodeEntry(KeyPurpose.RECEIVE).getAddress().toString(); - return new String[] {centerPad("Address", address.length()), centerPad("Value", CoinTableCell.TRANSACTION_WIDTH)}; + return new String[] {centerPad("Address", Math.max(AddressTableCell.ADDRESS_MIN_WIDTH, address.length())), centerPad("Value", CoinTableCell.UTXO_WIDTH)}; } private void updateAddressesLater() { diff --git a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/SettingsDialog.java b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/SettingsDialog.java index e7106898..c9b7fc86 100644 --- a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/SettingsDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/SettingsDialog.java @@ -288,34 +288,37 @@ public class SettingsDialog extends WalletDialog { }); } } else { - Platform.runLater(() -> addAndSaveAccount(masterWallet, standardAccount)); + Platform.runLater(() -> addAndSaveAccount(masterWallet, standardAccount, null)); } } private void addAndEncryptAccount(Wallet masterWallet, StandardAccount standardAccount, Key key) { try { - addAndSaveAccount(masterWallet, standardAccount); + addAndSaveAccount(masterWallet, standardAccount, key); } finally { masterWallet.encrypt(key); - for(Wallet childWallet : masterWallet.getChildWallets()) { - if(!childWallet.isNested() && !childWallet.isEncrypted()) { - childWallet.encrypt(key); - } - } key.clear(); } } - private void addAndSaveAccount(Wallet masterWallet, StandardAccount standardAccount) { + private void addAndSaveAccount(Wallet masterWallet, StandardAccount standardAccount, Key key) { + List childWallets; if(StandardAccount.WHIRLPOOL_ACCOUNTS.contains(standardAccount)) { - WhirlpoolServices.prepareWhirlpoolWallet(masterWallet, getWalletForm().getWalletId(), getWalletForm().getStorage()); + childWallets = WhirlpoolServices.prepareWhirlpoolWallet(masterWallet, getWalletForm().getWalletId(), getWalletForm().getStorage()); SparrowTerminal.get().getGuiThread().invokeLater(() -> showSuccessDialog("Added Accounts", "Whirlpool Accounts have been successfully added.")); } else { Wallet childWallet = masterWallet.addChildWallet(standardAccount); EventManager.get().post(new ChildWalletsAddedEvent(getWalletForm().getStorage(), masterWallet, childWallet)); + childWallets = List.of(childWallet); SparrowTerminal.get().getGuiThread().invokeLater(() -> showSuccessDialog("Added Account", standardAccount.getName() + " has been successfully added.")); } + if(key != null) { + for(Wallet childWallet : childWallets) { + childWallet.encrypt(key); + } + } + saveChildWallets(masterWallet); } diff --git a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/TransactionsDialog.java b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/TransactionsDialog.java index 2770294d..6966de08 100644 --- a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/TransactionsDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/TransactionsDialog.java @@ -57,7 +57,8 @@ public class TransactionsDialog extends WalletDialog { updateLabels(walletTransactionsEntry); updateHistory(getWalletForm().getWalletTransactionsEntry()); - Panel buttonPanel = new Panel(new GridLayout(4).setHorizontalSpacing(2).setVerticalSpacing(0)); + Panel buttonPanel = new Panel(new GridLayout(5).setHorizontalSpacing(2).setVerticalSpacing(0)); + buttonPanel.addComponent(new EmptySpace(new TerminalSize(15, 1))); buttonPanel.addComponent(new EmptySpace(new TerminalSize(15, 1))); buttonPanel.addComponent(new EmptySpace(new TerminalSize(15, 1))); buttonPanel.addComponent(new Button("Back", () -> onBack(Function.TRANSACTIONS))); diff --git a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/UtxosDialog.java b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/UtxosDialog.java index 81afe521..2fa4f9cb 100644 --- a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/UtxosDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/UtxosDialog.java @@ -103,12 +103,12 @@ public class UtxosDialog extends WalletDialog { updateLabels(walletUtxosEntry); updateHistory(getWalletForm().getWalletUtxosEntry()); - Panel buttonPanel = new Panel(new GridLayout(4).setHorizontalSpacing(2).setVerticalSpacing(0)); + Panel buttonPanel = new Panel(new GridLayout(5).setHorizontalSpacing(2).setVerticalSpacing(0)); if(getWalletForm().getWallet().isWhirlpoolMixWallet()) { startMix = new Button("Start Mixing", this::toggleMixing).setSize(new TerminalSize(20, 1)).addTo(buttonPanel); startMix.setEnabled(AppServices.onlineProperty().get()); - mixTo = new Button("Mix to...", this::showMixToDialog).addTo(buttonPanel); + mixTo = new Button("Mix to...", this::showMixToDialog); if(getWalletForm().getWallet().getStandardAccountType() == StandardAccount.WHIRLPOOL_POSTMIX) { buttonPanel.addComponent(mixTo); } else { @@ -132,9 +132,11 @@ public class UtxosDialog extends WalletDialog { AppServices.onlineProperty().addListener(new WeakChangeListener<>(mixingOnlineListener)); + buttonPanel.addComponent(new EmptySpace(new TerminalSize(15, 1))); buttonPanel.addComponent(new Button("Back", () -> onBack(Function.UTXOS))); buttonPanel.addComponent(new Button("Refresh", this::onRefresh)); } else { + buttonPanel.addComponent(new EmptySpace(new TerminalSize(15, 1))); buttonPanel.addComponent(new EmptySpace(new TerminalSize(15, 1))); buttonPanel.addComponent(new EmptySpace(new TerminalSize(15, 1))); buttonPanel.addComponent(new Button("Back", () -> onBack(Function.UTXOS))); diff --git a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/table/AddressTableCell.java b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/table/AddressTableCell.java index dbe6d63e..4a66b838 100644 --- a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/table/AddressTableCell.java +++ b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/table/AddressTableCell.java @@ -5,6 +5,7 @@ import com.sparrowwallet.sparrow.wallet.NodeEntry; import com.sparrowwallet.sparrow.wallet.UtxoEntry; public class AddressTableCell extends TableCell { + public static final int ADDRESS_MIN_WIDTH = 52; public static final int UTXO_WIDTH = 18; public AddressTableCell(Entry entry) { diff --git a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/table/CoinTableCell.java b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/table/CoinTableCell.java index b175002f..0cc9633e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/table/CoinTableCell.java +++ b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/table/CoinTableCell.java @@ -5,10 +5,11 @@ import com.sparrowwallet.drongo.BitcoinUnit; import com.sparrowwallet.sparrow.UnitFormat; import com.sparrowwallet.sparrow.io.Config; import com.sparrowwallet.sparrow.wallet.Entry; +import com.sparrowwallet.sparrow.wallet.NodeEntry; import com.sparrowwallet.sparrow.wallet.TransactionEntry; public class CoinTableCell extends TableCell { - public static final int TRANSACTION_WIDTH = 20; + public static final int TRANSACTION_WIDTH = 24; public static final int UTXO_WIDTH = 18; private final boolean balance; diff --git a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/table/DateTableCell.java b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/table/DateTableCell.java index 325869ec..917fac83 100644 --- a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/table/DateTableCell.java +++ b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/table/DateTableCell.java @@ -9,7 +9,7 @@ import java.text.SimpleDateFormat; public class DateTableCell extends TableCell { private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - public static final int TRANSACTION_WIDTH = 20; + public static final int TRANSACTION_WIDTH = 23; public static final int UTXO_WIDTH = 18; public DateTableCell(Entry entry) { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java index dd9f8f28..a88023eb 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java @@ -547,7 +547,7 @@ public class SettingsController extends WalletFormController implements Initiali } else if(discoverAccounts) { ElectrumServer.AccountDiscoveryService accountDiscoveryService = new ElectrumServer.AccountDiscoveryService(masterWallet, standardAccounts); accountDiscoveryService.setOnSucceeded(event -> { - addAndSaveAccounts(masterWallet, accountDiscoveryService.getValue()); + addAndSaveAccounts(masterWallet, accountDiscoveryService.getValue(), null); if(accountDiscoveryService.getValue().isEmpty()) { AppServices.showAlertDialog("No Accounts Found", "No new accounts with existing transactions were found. Note only the first 10 accounts are scanned.", Alert.AlertType.INFORMATION, ButtonType.OK); } @@ -558,7 +558,7 @@ public class SettingsController extends WalletFormController implements Initiali }); accountDiscoveryService.start(); } else { - addAndSaveAccounts(masterWallet, standardAccounts); + addAndSaveAccounts(masterWallet, standardAccounts, null); } } } else { @@ -591,30 +591,33 @@ public class SettingsController extends WalletFormController implements Initiali private void addAndEncryptAccounts(Wallet masterWallet, List standardAccounts, Key key) { try { - addAndSaveAccounts(masterWallet, standardAccounts); + addAndSaveAccounts(masterWallet, standardAccounts, key); } finally { masterWallet.encrypt(key); - for(Wallet childWallet : masterWallet.getChildWallets()) { - if(!childWallet.isNested() && !childWallet.isEncrypted()) { - childWallet.encrypt(key); - } - } key.clear(); } } - private void addAndSaveAccounts(Wallet masterWallet, List standardAccounts) { + private void addAndSaveAccounts(Wallet masterWallet, List standardAccounts, Key key) { for(StandardAccount standardAccount : standardAccounts) { - addAndSaveAccount(masterWallet, standardAccount); + addAndSaveAccount(masterWallet, standardAccount, key); } } - private void addAndSaveAccount(Wallet masterWallet, StandardAccount standardAccount) { + private void addAndSaveAccount(Wallet masterWallet, StandardAccount standardAccount, Key key) { + List childWallets; if(StandardAccount.WHIRLPOOL_ACCOUNTS.contains(standardAccount)) { - WhirlpoolServices.prepareWhirlpoolWallet(masterWallet, getWalletForm().getWalletId(), getWalletForm().getStorage()); + childWallets = WhirlpoolServices.prepareWhirlpoolWallet(masterWallet, getWalletForm().getWalletId(), getWalletForm().getStorage()); } else { Wallet childWallet = masterWallet.addChildWallet(standardAccount); EventManager.get().post(new ChildWalletsAddedEvent(getWalletForm().getStorage(), masterWallet, childWallet)); + childWallets = List.of(childWallet); + } + + if(key != null) { + for(Wallet childWallet : childWallets) { + childWallet.encrypt(key); + } } saveChildWallets(masterWallet); diff --git a/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java b/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java index 4ad9c6db..c9704a3e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java @@ -170,7 +170,7 @@ public class WhirlpoolServices { && StandardAccount.MIXABLE_ACCOUNTS.contains(wallet.getStandardAccountType()); } - public static void prepareWhirlpoolWallet(Wallet decryptedWallet, String walletId, Storage storage) { + public static List prepareWhirlpoolWallet(Wallet decryptedWallet, String walletId, Storage storage) { Whirlpool whirlpool = AppServices.getWhirlpoolServices().getWhirlpool(walletId); whirlpool.setScode(decryptedWallet.getMasterMixConfig().getScode()); whirlpool.setHDWallet(walletId, decryptedWallet); @@ -179,12 +179,16 @@ public class WhirlpoolServices { Soroban soroban = AppServices.getSorobanServices().getSoroban(walletId); soroban.setHDWallet(decryptedWallet); + List childWallets = new ArrayList<>(); for(StandardAccount whirlpoolAccount : StandardAccount.WHIRLPOOL_ACCOUNTS) { if(decryptedWallet.getChildWallet(whirlpoolAccount) == null) { Wallet childWallet = decryptedWallet.addChildWallet(whirlpoolAccount); + childWallets.add(childWallet); EventManager.get().post(new ChildWalletsAddedEvent(storage, decryptedWallet, childWallet)); } } + + return childWallets; } @Subscribe