mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-05 05:46:44 +00:00
update wallet in walletform on label and keystore source changes, detect threshold change
This commit is contained in:
parent
9166160008
commit
8d9e253f93
10 changed files with 56 additions and 30 deletions
|
@ -921,7 +921,7 @@ public class AppController implements Initializable {
|
|||
Wallet pastWallet = wallet.copy();
|
||||
walletTabData.getStorage().backupTempWallet();
|
||||
wallet.clearHistory();
|
||||
EventManager.get().post(new WalletSettingsChangedEvent(wallet, pastWallet, walletTabData.getStorage().getWalletFile()));
|
||||
EventManager.get().post(new WalletAddressesChangedEvent(wallet, pastWallet, walletTabData.getStorage().getWalletFile()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1296,7 +1296,7 @@ public class AppController implements Initializable {
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
public void walletSettingsChanged(WalletSettingsChangedEvent event) {
|
||||
public void walletAddressesChanged(WalletAddressesChangedEvent event) {
|
||||
Tab tab = tabs.getSelectionModel().getSelectedItem();
|
||||
TabData tabData = (TabData)tab.getUserData();
|
||||
if(tabData instanceof WalletTabData) {
|
||||
|
|
|
@ -585,7 +585,7 @@ public class AppServices {
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
public void walletSettingsChanged(WalletSettingsChangedEvent event) {
|
||||
public void walletAddressesChanged(WalletAddressesChangedEvent event) {
|
||||
restartBwt(event.getWallet());
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.sparrowwallet.sparrow.AppServices;
|
|||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.event.WalletDataChangedEvent;
|
||||
import com.sparrowwallet.sparrow.event.WalletHistoryStatusEvent;
|
||||
import com.sparrowwallet.sparrow.event.WalletSettingsChangedEvent;
|
||||
import com.sparrowwallet.sparrow.event.WalletAddressesChangedEvent;
|
||||
import com.sparrowwallet.sparrow.io.Config;
|
||||
import com.sparrowwallet.sparrow.io.Storage;
|
||||
import com.sparrowwallet.sparrow.net.ServerType;
|
||||
|
@ -92,7 +92,7 @@ public class CoinTreeTable extends TreeTableView<Entry> {
|
|||
EventManager.get().post(new WalletDataChangedEvent(wallet));
|
||||
//Trigger full wallet rescan
|
||||
wallet.clearHistory();
|
||||
EventManager.get().post(new WalletSettingsChangedEvent(wallet, pastWallet, storage.getWalletFile()));
|
||||
EventManager.get().post(new WalletAddressesChangedEvent(wallet, pastWallet, storage.getWalletFile()));
|
||||
}
|
||||
});
|
||||
if(wallet.getBirthDate() == null) {
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package com.sparrowwallet.sparrow.event;
|
||||
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* This event is posted when a wallet's addresses are changed (keystores, policy, script type).
|
||||
* This event marks a fundamental change that is used to update application level UI, clear node entry caches and similar. It should only be subscribed to by application-level classes.
|
||||
* Note that WalletForm does not listen to this event to save the wallet, since the wallet is foreground saved directly in SettingsController before this event is posted.
|
||||
* This is because any failure in saving the wallet must be immediately reported to the user.
|
||||
* Note that all wallet detail controllers that share a WalletForm, and that class posts WalletNodesChangedEvent once it has cleared it's entry caches.
|
||||
*/
|
||||
public class WalletAddressesChangedEvent extends WalletSettingsChangedEvent {
|
||||
public WalletAddressesChangedEvent(Wallet wallet, Wallet pastWallet, File walletFile) {
|
||||
super(wallet, pastWallet, walletFile);
|
||||
}
|
||||
}
|
|
@ -5,11 +5,9 @@ import com.sparrowwallet.drongo.wallet.Wallet;
|
|||
import java.io.File;
|
||||
|
||||
/**
|
||||
* This event is posted when a wallet's settings are changed (keystores, policy, script type).
|
||||
* This event marks a fundamental change that is used to update application level UI, clear node entry caches and similar. It should only be subscribed to by application-level classes.
|
||||
* Note that WalletForm does not listen to this event to save the wallet, since the wallet is foreground saved directly in SettingsController before this event is posted.
|
||||
* This is because any failure in saving the wallet must be immediately reported to the user.
|
||||
* Note that all wallet detail controllers that share a WalletForm, and that class posts WalletNodesChangedEvent once it has cleared it's entry caches.
|
||||
* This event is posted when a wallet's settings are changed in a way that does not update the wallet addresses or history.
|
||||
* For example, changing the keystore source or label will trigger this event, which updates the wallet but avoids a full wallet refresh.
|
||||
* It is impossible for the validity of a wallet to change on this event - listen for WalletAddressesChangedEvent for this
|
||||
*/
|
||||
public class WalletSettingsChangedEvent extends WalletChangedEvent {
|
||||
private final Wallet pastWallet;
|
||||
|
|
|
@ -258,7 +258,7 @@ public class ReceiveController extends WalletFormController implements Initializ
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
public void walletSettingsChanged(WalletSettingsChangedEvent event) {
|
||||
public void walletAddressesChanged(WalletAddressesChangedEvent event) {
|
||||
displayAddress.setUserData(null);
|
||||
}
|
||||
|
||||
|
|
|
@ -345,7 +345,7 @@ public class SettingsController extends WalletFormController implements Initiali
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
public void walletSettingsChanged(WalletSettingsChangedEvent event) {
|
||||
public void walletAddressesChanged(WalletAddressesChangedEvent event) {
|
||||
updateBirthDate(event.getWalletFile(), event.getWallet());
|
||||
}
|
||||
|
||||
|
@ -404,9 +404,7 @@ public class SettingsController extends WalletFormController implements Initiali
|
|||
try {
|
||||
walletForm.getStorage().setEncryptionPubKey(Storage.NO_PASSWORD_KEY);
|
||||
walletForm.saveAndRefresh();
|
||||
if(requirement == WalletPasswordDialog.PasswordRequirement.UPDATE_NEW || requirement == WalletPasswordDialog.PasswordRequirement.UPDATE_CHANGE) {
|
||||
EventManager.get().post(new RequestOpenWalletsEvent());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Error saving wallet", e);
|
||||
AppServices.showErrorDialog("Error saving wallet", e.getMessage());
|
||||
|
@ -450,10 +448,7 @@ public class SettingsController extends WalletFormController implements Initiali
|
|||
walletForm.getWallet().encrypt(key);
|
||||
walletForm.getStorage().setEncryptionPubKey(encryptionPubKey);
|
||||
walletForm.saveAndRefresh();
|
||||
|
||||
if(requirement == WalletPasswordDialog.PasswordRequirement.UPDATE_NEW || requirement == WalletPasswordDialog.PasswordRequirement.UPDATE_EMPTY) {
|
||||
EventManager.get().post(new RequestOpenWalletsEvent());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error saving wallet", e);
|
||||
AppServices.showErrorDialog("Error saving wallet", e.getMessage());
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package com.sparrowwallet.sparrow.wallet;
|
||||
|
||||
import com.sparrowwallet.drongo.policy.Policy;
|
||||
import com.sparrowwallet.drongo.wallet.Keystore;
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.event.WalletAddressesChangedEvent;
|
||||
import com.sparrowwallet.sparrow.event.WalletSettingsChangedEvent;
|
||||
import com.sparrowwallet.sparrow.io.Storage;
|
||||
|
||||
|
@ -52,6 +54,8 @@ public class SettingsWalletForm extends WalletForm {
|
|||
save();
|
||||
|
||||
if(refreshAll) {
|
||||
EventManager.get().post(new WalletAddressesChangedEvent(wallet, pastWallet, getWalletFile()));
|
||||
} else {
|
||||
EventManager.get().post(new WalletSettingsChangedEvent(wallet, pastWallet, getWalletFile()));
|
||||
}
|
||||
}
|
||||
|
@ -91,6 +95,10 @@ public class SettingsWalletForm extends WalletForm {
|
|||
|
||||
//TODO: Determine if Miniscript has changed for custom policies
|
||||
|
||||
if(!Objects.equals(getNumSignaturesRequired(original.getDefaultPolicy()), getNumSignaturesRequired(changed.getDefaultPolicy()))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(original.getKeystores().size() != changed.getKeystores().size()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -110,4 +118,8 @@ public class SettingsWalletForm extends WalletForm {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Integer getNumSignaturesRequired(Policy policy) {
|
||||
return policy == null ? null : policy.getNumSignaturesRequired();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.sparrowwallet.sparrow.AppServices;
|
|||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.event.ReceiveActionEvent;
|
||||
import com.sparrowwallet.sparrow.event.SendActionEvent;
|
||||
import com.sparrowwallet.sparrow.event.WalletSettingsChangedEvent;
|
||||
import com.sparrowwallet.sparrow.event.WalletAddressesChangedEvent;
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
|
@ -106,7 +106,7 @@ public class WalletController extends WalletFormController implements Initializa
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
public void walletSettingsChanged(WalletSettingsChangedEvent event) {
|
||||
public void walletAddressesChanged(WalletAddressesChangedEvent event) {
|
||||
if(event.getWalletFile().equals(walletForm.getWalletFile())) {
|
||||
configure(event.getWallet().isValid());
|
||||
}
|
||||
|
|
|
@ -265,6 +265,8 @@ public class WalletForm {
|
|||
public void walletSettingsChanged(WalletSettingsChangedEvent event) {
|
||||
if(event.getWalletFile().equals(storage.getWalletFile())) {
|
||||
wallet = event.getWallet();
|
||||
|
||||
if(event instanceof WalletAddressesChangedEvent) {
|
||||
walletTransactionsEntry = null;
|
||||
walletUtxosEntry = null;
|
||||
accountEntries.clear();
|
||||
|
@ -278,6 +280,7 @@ public class WalletForm {
|
|||
refreshHistory(AppServices.getCurrentBlockHeight(), event.getPastWallet());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void newBlock(NewBlockEvent event) {
|
||||
|
|
Loading…
Reference in a new issue