terminal - fix add account encryption and normalize ui widths

This commit is contained in:
Craig Raw 2022-10-20 12:45:09 +02:00
parent cbf847a57f
commit 603df6d0f6
9 changed files with 45 additions and 29 deletions

View file

@ -38,7 +38,8 @@ public class AddressesDialog extends WalletDialog {
updateAddresses(); 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 EmptySpace(new TerminalSize(15, 1))); buttonPanel.addComponent(new EmptySpace(new TerminalSize(15, 1)));
buttonPanel.addComponent(new Button("Back", () -> onBack(Function.ADDRESSES))); buttonPanel.addComponent(new Button("Back", () -> onBack(Function.ADDRESSES)));
@ -74,7 +75,7 @@ public class AddressesDialog extends WalletDialog {
private String[] getTableColumns() { private String[] getTableColumns() {
String address = getWalletForm().getNodeEntry(KeyPurpose.RECEIVE).getAddress().toString(); 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() { private void updateAddressesLater() {

View file

@ -288,34 +288,37 @@ public class SettingsDialog extends WalletDialog {
}); });
} }
} else { } else {
Platform.runLater(() -> addAndSaveAccount(masterWallet, standardAccount)); Platform.runLater(() -> addAndSaveAccount(masterWallet, standardAccount, null));
} }
} }
private void addAndEncryptAccount(Wallet masterWallet, StandardAccount standardAccount, Key key) { private void addAndEncryptAccount(Wallet masterWallet, StandardAccount standardAccount, Key key) {
try { try {
addAndSaveAccount(masterWallet, standardAccount); addAndSaveAccount(masterWallet, standardAccount, key);
} finally { } finally {
masterWallet.encrypt(key); masterWallet.encrypt(key);
for(Wallet childWallet : masterWallet.getChildWallets()) {
if(!childWallet.isNested() && !childWallet.isEncrypted()) {
childWallet.encrypt(key);
}
}
key.clear(); key.clear();
} }
} }
private void addAndSaveAccount(Wallet masterWallet, StandardAccount standardAccount) { private void addAndSaveAccount(Wallet masterWallet, StandardAccount standardAccount, Key key) {
List<Wallet> childWallets;
if(StandardAccount.WHIRLPOOL_ACCOUNTS.contains(standardAccount)) { 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.")); SparrowTerminal.get().getGuiThread().invokeLater(() -> showSuccessDialog("Added Accounts", "Whirlpool Accounts have been successfully added."));
} else { } else {
Wallet childWallet = masterWallet.addChildWallet(standardAccount); Wallet childWallet = masterWallet.addChildWallet(standardAccount);
EventManager.get().post(new ChildWalletsAddedEvent(getWalletForm().getStorage(), masterWallet, childWallet)); 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.")); 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); saveChildWallets(masterWallet);
} }

View file

@ -57,7 +57,8 @@ public class TransactionsDialog extends WalletDialog {
updateLabels(walletTransactionsEntry); updateLabels(walletTransactionsEntry);
updateHistory(getWalletForm().getWalletTransactionsEntry()); 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 EmptySpace(new TerminalSize(15, 1))); buttonPanel.addComponent(new EmptySpace(new TerminalSize(15, 1)));
buttonPanel.addComponent(new Button("Back", () -> onBack(Function.TRANSACTIONS))); buttonPanel.addComponent(new Button("Back", () -> onBack(Function.TRANSACTIONS)));

View file

@ -103,12 +103,12 @@ public class UtxosDialog extends WalletDialog {
updateLabels(walletUtxosEntry); updateLabels(walletUtxosEntry);
updateHistory(getWalletForm().getWalletUtxosEntry()); 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()) { if(getWalletForm().getWallet().isWhirlpoolMixWallet()) {
startMix = new Button("Start Mixing", this::toggleMixing).setSize(new TerminalSize(20, 1)).addTo(buttonPanel); startMix = new Button("Start Mixing", this::toggleMixing).setSize(new TerminalSize(20, 1)).addTo(buttonPanel);
startMix.setEnabled(AppServices.onlineProperty().get()); 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) { if(getWalletForm().getWallet().getStandardAccountType() == StandardAccount.WHIRLPOOL_POSTMIX) {
buttonPanel.addComponent(mixTo); buttonPanel.addComponent(mixTo);
} else { } else {
@ -132,9 +132,11 @@ public class UtxosDialog extends WalletDialog {
AppServices.onlineProperty().addListener(new WeakChangeListener<>(mixingOnlineListener)); 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("Back", () -> onBack(Function.UTXOS)));
buttonPanel.addComponent(new Button("Refresh", this::onRefresh)); buttonPanel.addComponent(new Button("Refresh", this::onRefresh));
} else { } 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 EmptySpace(new TerminalSize(15, 1))); buttonPanel.addComponent(new EmptySpace(new TerminalSize(15, 1)));
buttonPanel.addComponent(new Button("Back", () -> onBack(Function.UTXOS))); buttonPanel.addComponent(new Button("Back", () -> onBack(Function.UTXOS)));

View file

@ -5,6 +5,7 @@ import com.sparrowwallet.sparrow.wallet.NodeEntry;
import com.sparrowwallet.sparrow.wallet.UtxoEntry; import com.sparrowwallet.sparrow.wallet.UtxoEntry;
public class AddressTableCell extends TableCell { public class AddressTableCell extends TableCell {
public static final int ADDRESS_MIN_WIDTH = 52;
public static final int UTXO_WIDTH = 18; public static final int UTXO_WIDTH = 18;
public AddressTableCell(Entry entry) { public AddressTableCell(Entry entry) {

View file

@ -5,10 +5,11 @@ import com.sparrowwallet.drongo.BitcoinUnit;
import com.sparrowwallet.sparrow.UnitFormat; import com.sparrowwallet.sparrow.UnitFormat;
import com.sparrowwallet.sparrow.io.Config; import com.sparrowwallet.sparrow.io.Config;
import com.sparrowwallet.sparrow.wallet.Entry; import com.sparrowwallet.sparrow.wallet.Entry;
import com.sparrowwallet.sparrow.wallet.NodeEntry;
import com.sparrowwallet.sparrow.wallet.TransactionEntry; import com.sparrowwallet.sparrow.wallet.TransactionEntry;
public class CoinTableCell extends TableCell { 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; public static final int UTXO_WIDTH = 18;
private final boolean balance; private final boolean balance;

View file

@ -9,7 +9,7 @@ import java.text.SimpleDateFormat;
public class DateTableCell extends TableCell { public class DateTableCell extends TableCell {
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm"); 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 static final int UTXO_WIDTH = 18;
public DateTableCell(Entry entry) { public DateTableCell(Entry entry) {

View file

@ -547,7 +547,7 @@ public class SettingsController extends WalletFormController implements Initiali
} else if(discoverAccounts) { } else if(discoverAccounts) {
ElectrumServer.AccountDiscoveryService accountDiscoveryService = new ElectrumServer.AccountDiscoveryService(masterWallet, standardAccounts); ElectrumServer.AccountDiscoveryService accountDiscoveryService = new ElectrumServer.AccountDiscoveryService(masterWallet, standardAccounts);
accountDiscoveryService.setOnSucceeded(event -> { accountDiscoveryService.setOnSucceeded(event -> {
addAndSaveAccounts(masterWallet, accountDiscoveryService.getValue()); addAndSaveAccounts(masterWallet, accountDiscoveryService.getValue(), null);
if(accountDiscoveryService.getValue().isEmpty()) { 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); 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(); accountDiscoveryService.start();
} else { } else {
addAndSaveAccounts(masterWallet, standardAccounts); addAndSaveAccounts(masterWallet, standardAccounts, null);
} }
} }
} else { } else {
@ -591,30 +591,33 @@ public class SettingsController extends WalletFormController implements Initiali
private void addAndEncryptAccounts(Wallet masterWallet, List<StandardAccount> standardAccounts, Key key) { private void addAndEncryptAccounts(Wallet masterWallet, List<StandardAccount> standardAccounts, Key key) {
try { try {
addAndSaveAccounts(masterWallet, standardAccounts); addAndSaveAccounts(masterWallet, standardAccounts, key);
} finally { } finally {
masterWallet.encrypt(key); masterWallet.encrypt(key);
for(Wallet childWallet : masterWallet.getChildWallets()) {
if(!childWallet.isNested() && !childWallet.isEncrypted()) {
childWallet.encrypt(key);
}
}
key.clear(); key.clear();
} }
} }
private void addAndSaveAccounts(Wallet masterWallet, List<StandardAccount> standardAccounts) { private void addAndSaveAccounts(Wallet masterWallet, List<StandardAccount> standardAccounts, Key key) {
for(StandardAccount standardAccount : standardAccounts) { 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<Wallet> childWallets;
if(StandardAccount.WHIRLPOOL_ACCOUNTS.contains(standardAccount)) { if(StandardAccount.WHIRLPOOL_ACCOUNTS.contains(standardAccount)) {
WhirlpoolServices.prepareWhirlpoolWallet(masterWallet, getWalletForm().getWalletId(), getWalletForm().getStorage()); childWallets = WhirlpoolServices.prepareWhirlpoolWallet(masterWallet, getWalletForm().getWalletId(), getWalletForm().getStorage());
} else { } else {
Wallet childWallet = masterWallet.addChildWallet(standardAccount); Wallet childWallet = masterWallet.addChildWallet(standardAccount);
EventManager.get().post(new ChildWalletsAddedEvent(getWalletForm().getStorage(), masterWallet, childWallet)); 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); saveChildWallets(masterWallet);

View file

@ -170,7 +170,7 @@ public class WhirlpoolServices {
&& StandardAccount.MIXABLE_ACCOUNTS.contains(wallet.getStandardAccountType()); && StandardAccount.MIXABLE_ACCOUNTS.contains(wallet.getStandardAccountType());
} }
public static void prepareWhirlpoolWallet(Wallet decryptedWallet, String walletId, Storage storage) { public static List<Wallet> prepareWhirlpoolWallet(Wallet decryptedWallet, String walletId, Storage storage) {
Whirlpool whirlpool = AppServices.getWhirlpoolServices().getWhirlpool(walletId); Whirlpool whirlpool = AppServices.getWhirlpoolServices().getWhirlpool(walletId);
whirlpool.setScode(decryptedWallet.getMasterMixConfig().getScode()); whirlpool.setScode(decryptedWallet.getMasterMixConfig().getScode());
whirlpool.setHDWallet(walletId, decryptedWallet); whirlpool.setHDWallet(walletId, decryptedWallet);
@ -179,12 +179,16 @@ public class WhirlpoolServices {
Soroban soroban = AppServices.getSorobanServices().getSoroban(walletId); Soroban soroban = AppServices.getSorobanServices().getSoroban(walletId);
soroban.setHDWallet(decryptedWallet); soroban.setHDWallet(decryptedWallet);
List<Wallet> childWallets = new ArrayList<>();
for(StandardAccount whirlpoolAccount : StandardAccount.WHIRLPOOL_ACCOUNTS) { for(StandardAccount whirlpoolAccount : StandardAccount.WHIRLPOOL_ACCOUNTS) {
if(decryptedWallet.getChildWallet(whirlpoolAccount) == null) { if(decryptedWallet.getChildWallet(whirlpoolAccount) == null) {
Wallet childWallet = decryptedWallet.addChildWallet(whirlpoolAccount); Wallet childWallet = decryptedWallet.addChildWallet(whirlpoolAccount);
childWallets.add(childWallet);
EventManager.get().post(new ChildWalletsAddedEvent(storage, decryptedWallet, childWallet)); EventManager.get().post(new ChildWalletsAddedEvent(storage, decryptedWallet, childWallet));
} }
} }
return childWallets;
} }
@Subscribe @Subscribe