mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 13:26: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.TransactionEntry;
|
||||||
import com.sparrowwallet.sparrow.wallet.WalletTransactionsEntry;
|
import com.sparrowwallet.sparrow.wallet.WalletTransactionsEntry;
|
||||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.TreeTableColumn;
|
import javafx.scene.control.TreeTableColumn;
|
||||||
import javafx.scene.control.TreeTableView;
|
import javafx.scene.control.TreeTableView;
|
||||||
|
|
||||||
|
@ -49,6 +50,7 @@ public class TransactionsTreeTable extends TreeTableView<Entry> {
|
||||||
balanceCol.setSortable(true);
|
balanceCol.setSortable(true);
|
||||||
getColumns().add(balanceCol);
|
getColumns().add(balanceCol);
|
||||||
|
|
||||||
|
setPlaceholder(new Label("No transactions"));
|
||||||
setEditable(true);
|
setEditable(true);
|
||||||
setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
|
setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
|
||||||
dateCol.setSortType(TreeTableColumn.SortType.DESCENDING);
|
dateCol.setSortType(TreeTableColumn.SortType.DESCENDING);
|
||||||
|
@ -59,6 +61,12 @@ public class TransactionsTreeTable extends TreeTableView<Entry> {
|
||||||
RecursiveTreeItem<Entry> rootItem = new RecursiveTreeItem<>(rootEntry, Entry::getChildren);
|
RecursiveTreeItem<Entry> rootItem = new RecursiveTreeItem<>(rootEntry, Entry::getChildren);
|
||||||
setRoot(rootItem);
|
setRoot(rootItem);
|
||||||
rootItem.setExpanded(true);
|
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) {
|
public void updateHistory(List<WalletNode> updatedNodes) {
|
||||||
|
|
|
@ -274,12 +274,15 @@ public class ElectrumServer {
|
||||||
references.addAll(nodeReferences);
|
references.addAll(nodeReferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Integer, BlockHeader> blockHeaderMap = getBlockHeaders(references);
|
Map<Sha256Hash, BlockTransaction> transactionMap = new HashMap<>();
|
||||||
Map<Sha256Hash, BlockTransaction> transactionMap = getTransactions(references, blockHeaderMap);
|
if(!references.isEmpty()) {
|
||||||
|
Map<Integer, BlockHeader> blockHeaderMap = getBlockHeaders(references);
|
||||||
|
transactionMap = getTransactions(references, blockHeaderMap);
|
||||||
|
}
|
||||||
|
|
||||||
if(!transactionMap.equals(wallet.getTransactions())) {
|
if(!transactionMap.equals(wallet.getTransactions())) {
|
||||||
for(BlockTransaction blockTx : transactionMap.values()) {
|
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);
|
optionalLabel.ifPresent(blockTx::setLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,5 @@ public class SettingsWalletForm extends WalletForm {
|
||||||
wallet = walletCopy.copy();
|
wallet = walletCopy.copy();
|
||||||
save();
|
save();
|
||||||
EventManager.get().post(new WalletSettingsChangedEvent(wallet, getWalletFile()));
|
EventManager.get().post(new WalletSettingsChangedEvent(wallet, getWalletFile()));
|
||||||
refreshHistory(wallet.getStoredBlockHeight());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class WalletForm {
|
||||||
public WalletForm(Storage storage, Wallet currentWallet) {
|
public WalletForm(Storage storage, Wallet currentWallet) {
|
||||||
this.storage = storage;
|
this.storage = storage;
|
||||||
this.wallet = currentWallet;
|
this.wallet = currentWallet;
|
||||||
refreshHistory(wallet.getStoredBlockHeight());
|
refreshHistory(AppController.getCurrentBlockHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Wallet getWallet() {
|
public Wallet getWallet() {
|
||||||
|
@ -51,7 +51,7 @@ public class WalletForm {
|
||||||
public void saveAndRefresh() throws IOException {
|
public void saveAndRefresh() throws IOException {
|
||||||
wallet.clearHistory();
|
wallet.clearHistory();
|
||||||
save();
|
save();
|
||||||
refreshHistory(wallet.getStoredBlockHeight());
|
refreshHistory(AppController.getCurrentBlockHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshHistory(Integer blockHeight) {
|
public void refreshHistory(Integer blockHeight) {
|
||||||
|
@ -136,31 +136,36 @@ public class WalletForm {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void walletLabelChanged(WalletEntryLabelChangedEvent event) {
|
public void walletLabelChanged(WalletEntryLabelChangedEvent event) {
|
||||||
backgroundSaveWallet(event);
|
if(event.getWallet().equals(wallet)) {
|
||||||
|
backgroundSaveWallet(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void walletBlockHeightChanged(WalletBlockHeightChangedEvent event) {
|
public void walletBlockHeightChanged(WalletBlockHeightChangedEvent event) {
|
||||||
backgroundSaveWallet(event);
|
if(event.getWallet().equals(wallet)) {
|
||||||
|
backgroundSaveWallet(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void backgroundSaveWallet(WalletChangedEvent event) {
|
private void backgroundSaveWallet(WalletChangedEvent event) {
|
||||||
if(event.getWallet().equals(wallet)) {
|
try {
|
||||||
try {
|
save();
|
||||||
save();
|
} catch (IOException e) {
|
||||||
} catch (IOException e) {
|
//Background save failed
|
||||||
//Background save failed
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void walletSettingsChanged(WalletSettingsChangedEvent event) {
|
public void walletSettingsChanged(WalletSettingsChangedEvent event) {
|
||||||
walletTransactionsEntry = null;
|
if(event.getWalletFile().equals(storage.getWalletFile())) {
|
||||||
accountEntries.clear();
|
wallet = event.getWallet();
|
||||||
|
walletTransactionsEntry = null;
|
||||||
EventManager.get().post(new WalletNodesChangedEvent(wallet));
|
accountEntries.clear();
|
||||||
|
EventManager.get().post(new WalletNodesChangedEvent(wallet));
|
||||||
|
refreshHistory(AppController.getCurrentBlockHeight());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class WalletTransactionsEntry extends Entry {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateTransactions() {
|
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());
|
List<Entry> previous = new ArrayList<>(getChildren());
|
||||||
for(Entry currentEntry : current) {
|
for(Entry currentEntry : current) {
|
||||||
int index = previous.indexOf(currentEntry);
|
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.RECEIVE));
|
||||||
getWalletTransactions(wallet, walletTransactionMap, wallet.getNode(KeyPurpose.CHANGE));
|
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) {
|
private static void getWalletTransactions(Wallet wallet, Map<BlockTransaction, WalletTransaction> walletTransactionMap, WalletNode purposeNode) {
|
||||||
|
|
Loading…
Reference in a new issue