mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-02 20:36:44 +00:00
bug fixing on walletsettingsupdated
This commit is contained in:
parent
a8f16c15e0
commit
d4d61b8d41
5 changed files with 38 additions and 21 deletions
|
@ -5,6 +5,7 @@ import com.sparrowwallet.sparrow.wallet.Entry;
|
|||
import com.sparrowwallet.sparrow.wallet.TransactionEntry;
|
||||
import com.sparrowwallet.sparrow.wallet.WalletTransactionsEntry;
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TreeTableColumn;
|
||||
import javafx.scene.control.TreeTableView;
|
||||
|
||||
|
@ -49,6 +50,7 @@ public class TransactionsTreeTable extends TreeTableView<Entry> {
|
|||
balanceCol.setSortable(true);
|
||||
getColumns().add(balanceCol);
|
||||
|
||||
setPlaceholder(new Label("No transactions"));
|
||||
setEditable(true);
|
||||
setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
|
||||
dateCol.setSortType(TreeTableColumn.SortType.DESCENDING);
|
||||
|
@ -59,6 +61,12 @@ public class TransactionsTreeTable extends TreeTableView<Entry> {
|
|||
RecursiveTreeItem<Entry> rootItem = new RecursiveTreeItem<>(rootEntry, Entry::getChildren);
|
||||
setRoot(rootItem);
|
||||
rootItem.setExpanded(true);
|
||||
|
||||
if(getColumns().size() > 0) {
|
||||
TreeTableColumn<Entry, ?> dateCol = getColumns().get(0);
|
||||
getSortOrder().add(dateCol);
|
||||
dateCol.setSortType(TreeTableColumn.SortType.DESCENDING);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateHistory(List<WalletNode> updatedNodes) {
|
||||
|
|
|
@ -274,12 +274,15 @@ public class ElectrumServer {
|
|||
references.addAll(nodeReferences);
|
||||
}
|
||||
|
||||
Map<Integer, BlockHeader> blockHeaderMap = getBlockHeaders(references);
|
||||
Map<Sha256Hash, BlockTransaction> transactionMap = getTransactions(references, blockHeaderMap);
|
||||
Map<Sha256Hash, BlockTransaction> transactionMap = new HashMap<>();
|
||||
if(!references.isEmpty()) {
|
||||
Map<Integer, BlockHeader> blockHeaderMap = getBlockHeaders(references);
|
||||
transactionMap = getTransactions(references, blockHeaderMap);
|
||||
}
|
||||
|
||||
if(!transactionMap.equals(wallet.getTransactions())) {
|
||||
for(BlockTransaction blockTx : transactionMap.values()) {
|
||||
Optional<String> optionalLabel = wallet.getTransactions().values().stream().filter(oldBlTx -> oldBlTx.getHash().equals(blockTx.getHash())).map(BlockTransaction::getLabel).findFirst();
|
||||
Optional<String> optionalLabel = wallet.getTransactions().values().stream().filter(oldBlTx -> oldBlTx.getHash().equals(blockTx.getHash())).map(BlockTransaction::getLabel).filter(Objects::nonNull).findFirst();
|
||||
optionalLabel.ifPresent(blockTx::setLabel);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,5 @@ public class SettingsWalletForm extends WalletForm {
|
|||
wallet = walletCopy.copy();
|
||||
save();
|
||||
EventManager.get().post(new WalletSettingsChangedEvent(wallet, getWalletFile()));
|
||||
refreshHistory(wallet.getStoredBlockHeight());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class WalletForm {
|
|||
public WalletForm(Storage storage, Wallet currentWallet) {
|
||||
this.storage = storage;
|
||||
this.wallet = currentWallet;
|
||||
refreshHistory(wallet.getStoredBlockHeight());
|
||||
refreshHistory(AppController.getCurrentBlockHeight());
|
||||
}
|
||||
|
||||
public Wallet getWallet() {
|
||||
|
@ -51,7 +51,7 @@ public class WalletForm {
|
|||
public void saveAndRefresh() throws IOException {
|
||||
wallet.clearHistory();
|
||||
save();
|
||||
refreshHistory(wallet.getStoredBlockHeight());
|
||||
refreshHistory(AppController.getCurrentBlockHeight());
|
||||
}
|
||||
|
||||
public void refreshHistory(Integer blockHeight) {
|
||||
|
@ -136,31 +136,36 @@ public class WalletForm {
|
|||
|
||||
@Subscribe
|
||||
public void walletLabelChanged(WalletEntryLabelChangedEvent event) {
|
||||
backgroundSaveWallet(event);
|
||||
if(event.getWallet().equals(wallet)) {
|
||||
backgroundSaveWallet(event);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void walletBlockHeightChanged(WalletBlockHeightChangedEvent event) {
|
||||
backgroundSaveWallet(event);
|
||||
if(event.getWallet().equals(wallet)) {
|
||||
backgroundSaveWallet(event);
|
||||
}
|
||||
}
|
||||
|
||||
private void backgroundSaveWallet(WalletChangedEvent event) {
|
||||
if(event.getWallet().equals(wallet)) {
|
||||
try {
|
||||
save();
|
||||
} catch (IOException e) {
|
||||
//Background save failed
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
save();
|
||||
} catch (IOException e) {
|
||||
//Background save failed
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void walletSettingsChanged(WalletSettingsChangedEvent event) {
|
||||
walletTransactionsEntry = null;
|
||||
accountEntries.clear();
|
||||
|
||||
EventManager.get().post(new WalletNodesChangedEvent(wallet));
|
||||
if(event.getWalletFile().equals(storage.getWalletFile())) {
|
||||
wallet = event.getWallet();
|
||||
walletTransactionsEntry = null;
|
||||
accountEntries.clear();
|
||||
EventManager.get().post(new WalletNodesChangedEvent(wallet));
|
||||
refreshHistory(AppController.getCurrentBlockHeight());
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
|
|
@ -37,7 +37,7 @@ public class WalletTransactionsEntry extends Entry {
|
|||
}
|
||||
|
||||
public void updateTransactions() {
|
||||
List<Entry> current = getWalletTransactions(wallet).stream().map(WalletTransaction::getTransactionEntry).collect(Collectors.toList());
|
||||
List<Entry> current = getWalletTransactions(wallet).stream().map(WalletTransaction::getTransactionEntry).peek(entry -> entry.setParent(this)).collect(Collectors.toList());
|
||||
List<Entry> previous = new ArrayList<>(getChildren());
|
||||
for(Entry currentEntry : current) {
|
||||
int index = previous.indexOf(currentEntry);
|
||||
|
@ -57,7 +57,9 @@ public class WalletTransactionsEntry extends Entry {
|
|||
getWalletTransactions(wallet, walletTransactionMap, wallet.getNode(KeyPurpose.RECEIVE));
|
||||
getWalletTransactions(wallet, walletTransactionMap, wallet.getNode(KeyPurpose.CHANGE));
|
||||
|
||||
return walletTransactionMap.values();
|
||||
List<WalletTransaction> walletTxList = new ArrayList<>(walletTransactionMap.values());
|
||||
Collections.reverse(walletTxList);
|
||||
return walletTxList;
|
||||
}
|
||||
|
||||
private static void getWalletTransactions(Wallet wallet, Map<BlockTransaction, WalletTransaction> walletTransactionMap, WalletNode purposeNode) {
|
||||
|
|
Loading…
Reference in a new issue