mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
make controller and tab data share data sources
This commit is contained in:
parent
30e2ab5e2a
commit
d5aba35184
6 changed files with 45 additions and 74 deletions
|
@ -21,6 +21,7 @@ import com.sparrowwallet.sparrow.io.*;
|
||||||
import com.sparrowwallet.sparrow.net.ElectrumServer;
|
import com.sparrowwallet.sparrow.net.ElectrumServer;
|
||||||
import com.sparrowwallet.sparrow.preferences.PreferencesDialog;
|
import com.sparrowwallet.sparrow.preferences.PreferencesDialog;
|
||||||
import com.sparrowwallet.sparrow.transaction.TransactionController;
|
import com.sparrowwallet.sparrow.transaction.TransactionController;
|
||||||
|
import com.sparrowwallet.sparrow.transaction.TransactionData;
|
||||||
import com.sparrowwallet.sparrow.transaction.TransactionView;
|
import com.sparrowwallet.sparrow.transaction.TransactionView;
|
||||||
import com.sparrowwallet.sparrow.wallet.WalletController;
|
import com.sparrowwallet.sparrow.wallet.WalletController;
|
||||||
import com.sparrowwallet.sparrow.wallet.WalletForm;
|
import com.sparrowwallet.sparrow.wallet.WalletForm;
|
||||||
|
@ -468,13 +469,9 @@ public class AppController implements Initializable {
|
||||||
TransactionTabData transactionTabData = (TransactionTabData)tabData;
|
TransactionTabData transactionTabData = (TransactionTabData)tabData;
|
||||||
Transaction transaction = transactionTabData.getTransaction();
|
Transaction transaction = transactionTabData.getTransaction();
|
||||||
|
|
||||||
//Note the transactionTabData's transaction does not change even once the final tx is extracted, so extract it here if possible
|
//Save a transaction if the PSBT is null or transaction has already been extracted, otherwise save PSBT
|
||||||
if(transactionTabData.getPsbt() != null && transactionTabData.getPsbt().isFinalized()) {
|
//The PSBT's transaction is not altered with transaction extraction, but the extracted transaction is stored in TransactionData
|
||||||
transaction = transactionTabData.getPsbt().extractTransaction();
|
boolean saveTx = (transactionTabData.getPsbt() == null || transactionTabData.getPsbt().getTransaction() != transaction);
|
||||||
}
|
|
||||||
|
|
||||||
//Save a transaction if the PSBT is null or finalized (a finalized PSBT is less useful than a broadcastable tx)
|
|
||||||
boolean saveTx = (transactionTabData.getPsbt() == null || transactionTabData.getPsbt().isFinalized());
|
|
||||||
|
|
||||||
Stage window = new Stage();
|
Stage window = new Stage();
|
||||||
FileChooser fileChooser = new FileChooser();
|
FileChooser fileChooser = new FileChooser();
|
||||||
|
@ -754,8 +751,6 @@ public class AppController implements Initializable {
|
||||||
name = name.substring(0, name.lastIndexOf('.'));
|
name = name.substring(0, name.lastIndexOf('.'));
|
||||||
}
|
}
|
||||||
Tab tab = new Tab(name);
|
Tab tab = new Tab(name);
|
||||||
TabData tabData = new WalletTabData(TabData.TabType.WALLET, wallet, storage);
|
|
||||||
tab.setUserData(tabData);
|
|
||||||
tab.setContextMenu(getTabContextMenu(tab));
|
tab.setContextMenu(getTabContextMenu(tab));
|
||||||
tab.setClosable(true);
|
tab.setClosable(true);
|
||||||
FXMLLoader walletLoader = new FXMLLoader(getClass().getResource("wallet/wallet.fxml"));
|
FXMLLoader walletLoader = new FXMLLoader(getClass().getResource("wallet/wallet.fxml"));
|
||||||
|
@ -767,6 +762,9 @@ public class AppController implements Initializable {
|
||||||
EventManager.get().register(walletForm);
|
EventManager.get().register(walletForm);
|
||||||
controller.setWalletForm(walletForm);
|
controller.setWalletForm(walletForm);
|
||||||
|
|
||||||
|
TabData tabData = new WalletTabData(TabData.TabType.WALLET, walletForm);
|
||||||
|
tab.setUserData(tabData);
|
||||||
|
|
||||||
tabs.getTabs().add(tab);
|
tabs.getTabs().add(tab);
|
||||||
return tab;
|
return tab;
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
|
@ -863,29 +861,30 @@ public class AppController implements Initializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
Tab tab = new Tab(tabName);
|
Tab tab = new Tab(tabName);
|
||||||
TabData tabData = new TransactionTabData(TabData.TabType.TRANSACTION, transaction, psbt);
|
|
||||||
tab.setUserData(tabData);
|
|
||||||
tab.setContextMenu(getTabContextMenu(tab));
|
tab.setContextMenu(getTabContextMenu(tab));
|
||||||
tab.setClosable(true);
|
tab.setClosable(true);
|
||||||
FXMLLoader transactionLoader = new FXMLLoader(getClass().getResource("transaction/transaction.fxml"));
|
FXMLLoader transactionLoader = new FXMLLoader(getClass().getResource("transaction/transaction.fxml"));
|
||||||
tab.setContent(transactionLoader.load());
|
tab.setContent(transactionLoader.load());
|
||||||
TransactionController controller = transactionLoader.getController();
|
TransactionController controller = transactionLoader.getController();
|
||||||
|
|
||||||
|
TransactionData transactionData;
|
||||||
if(psbt != null) {
|
if(psbt != null) {
|
||||||
controller.setPSBT(psbt);
|
transactionData = new TransactionData(name, psbt);
|
||||||
} else if(blockTransaction != null) {
|
} else if(blockTransaction != null) {
|
||||||
controller.setBlockTransaction(blockTransaction);
|
transactionData = new TransactionData(name, blockTransaction);
|
||||||
} else {
|
} else {
|
||||||
controller.setTransaction(transaction);
|
transactionData = new TransactionData(name, transaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.setName(name);
|
controller.setTransactionData(transactionData);
|
||||||
|
|
||||||
if(initialView != null) {
|
if(initialView != null) {
|
||||||
controller.setInitialView(initialView, initialIndex);
|
controller.setInitialView(initialView, initialIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.initializeView();
|
controller.initializeView();
|
||||||
|
|
||||||
|
TabData tabData = new TransactionTabData(TabData.TabType.TRANSACTION, transactionData);
|
||||||
|
tab.setUserData(tabData);
|
||||||
|
|
||||||
tabs.getTabs().add(tab);
|
tabs.getTabs().add(tab);
|
||||||
|
|
||||||
return tab;
|
return tab;
|
||||||
|
@ -930,7 +929,7 @@ public class AppController implements Initializable {
|
||||||
TransactionTabSelectedEvent txTabEvent = (TransactionTabSelectedEvent)event;
|
TransactionTabSelectedEvent txTabEvent = (TransactionTabSelectedEvent)event;
|
||||||
TransactionTabData transactionTabData = txTabEvent.getTransactionTabData();
|
TransactionTabData transactionTabData = txTabEvent.getTransactionTabData();
|
||||||
saveTransaction.setDisable(false);
|
saveTransaction.setDisable(false);
|
||||||
saveTransaction.setText("Save " + (transactionTabData.getPsbt() == null || transactionTabData.getPsbt().isFinalized() ? "Transaction..." : "PSBT..."));
|
saveTransaction.setText("Save " + (transactionTabData.getPsbt() == null || transactionTabData.getPsbt().getTransaction() != transactionTabData.getTransaction() ? "Transaction..." : "PSBT..."));
|
||||||
exportWallet.setDisable(true);
|
exportWallet.setDisable(true);
|
||||||
showTxHex.setDisable(false);
|
showTxHex.setDisable(false);
|
||||||
} else if(event instanceof WalletTabSelectedEvent) {
|
} else if(event instanceof WalletTabSelectedEvent) {
|
||||||
|
@ -944,12 +943,12 @@ public class AppController implements Initializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void psbtFinalizedEvent(PSBTFinalizedEvent event) {
|
public void transactionExtractedEvent(TransactionExtractedEvent event) {
|
||||||
for(Tab tab : tabs.getTabs()) {
|
for(Tab tab : tabs.getTabs()) {
|
||||||
TabData tabData = (TabData) tab.getUserData();
|
TabData tabData = (TabData) tab.getUserData();
|
||||||
if(tabData instanceof TransactionTabData) {
|
if(tabData instanceof TransactionTabData) {
|
||||||
TransactionTabData transactionTabData = (TransactionTabData)tabData;
|
TransactionTabData transactionTabData = (TransactionTabData)tabData;
|
||||||
if(Arrays.equals(transactionTabData.getTransaction().bitcoinSerialize(), event.getPsbt().getTransaction().bitcoinSerialize())) {
|
if(transactionTabData.getTransaction() == event.getFinalTransaction()) {
|
||||||
saveTransaction.setText("Save Transaction...");
|
saveTransaction.setText("Save Transaction...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,26 +2,25 @@ package com.sparrowwallet.sparrow;
|
||||||
|
|
||||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||||
import com.sparrowwallet.drongo.psbt.PSBT;
|
import com.sparrowwallet.drongo.psbt.PSBT;
|
||||||
|
import com.sparrowwallet.sparrow.transaction.TransactionData;
|
||||||
|
|
||||||
public class TransactionTabData extends TabData {
|
public class TransactionTabData extends TabData {
|
||||||
private final Transaction transaction;
|
private final TransactionData transactionData;
|
||||||
private final PSBT psbt;
|
|
||||||
|
|
||||||
public TransactionTabData(TabType type, Transaction transaction) {
|
public TransactionTabData(TabType type, TransactionData transactionData) {
|
||||||
this(type, transaction, null);
|
super(type);
|
||||||
|
this.transactionData = transactionData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransactionTabData(TabType type, Transaction transaction, PSBT psbt) {
|
public TransactionData getTransactionData() {
|
||||||
super(type);
|
return transactionData;
|
||||||
this.transaction = transaction;
|
|
||||||
this.psbt = psbt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Transaction getTransaction() {
|
public Transaction getTransaction() {
|
||||||
return transaction;
|
return transactionData.getTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PSBT getPsbt() {
|
public PSBT getPsbt() {
|
||||||
return psbt;
|
return transactionData.getPsbt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +1,22 @@
|
||||||
package com.sparrowwallet.sparrow;
|
package com.sparrowwallet.sparrow;
|
||||||
|
|
||||||
import com.google.common.eventbus.Subscribe;
|
|
||||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||||
import com.sparrowwallet.sparrow.event.WalletSettingsChangedEvent;
|
|
||||||
import com.sparrowwallet.sparrow.io.Storage;
|
import com.sparrowwallet.sparrow.io.Storage;
|
||||||
|
import com.sparrowwallet.sparrow.wallet.WalletForm;
|
||||||
|
|
||||||
public class WalletTabData extends TabData {
|
public class WalletTabData extends TabData {
|
||||||
private Wallet wallet;
|
private final WalletForm walletForm;
|
||||||
private final Storage storage;
|
|
||||||
|
|
||||||
public WalletTabData(TabType type, Wallet wallet, Storage storage) {
|
public WalletTabData(TabType type, WalletForm walletForm) {
|
||||||
super(type);
|
super(type);
|
||||||
this.wallet = wallet;
|
this.walletForm = walletForm;
|
||||||
this.storage = storage;
|
|
||||||
|
|
||||||
EventManager.get().register(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Wallet getWallet() {
|
public Wallet getWallet() {
|
||||||
return wallet;
|
return walletForm.getWallet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Storage getStorage() {
|
public Storage getStorage() {
|
||||||
return storage;
|
return walletForm.getStorage();
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void walletSettingsChanged(WalletSettingsChangedEvent event) {
|
|
||||||
if(event.getWalletFile().equals(storage.getWalletFile())) {
|
|
||||||
wallet = event.getWallet();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class PageForm extends IndexedTransactionForm {
|
||||||
private final int pageEnd;
|
private final int pageEnd;
|
||||||
|
|
||||||
public PageForm(TransactionView view, int pageStart, int pageEnd) {
|
public PageForm(TransactionView view, int pageStart, int pageEnd) {
|
||||||
super(new TransactionData(ElectrumServer.UNFETCHABLE_BLOCK_TRANSACTION), pageStart);
|
super(new TransactionData(pageStart + "-" + pageEnd, ElectrumServer.UNFETCHABLE_BLOCK_TRANSACTION), pageStart);
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.pageStart = pageStart;
|
this.pageStart = pageStart;
|
||||||
this.pageEnd = pageEnd;
|
this.pageEnd = pageEnd;
|
||||||
|
|
|
@ -363,34 +363,22 @@ public class TransactionController implements Initializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTransactionData(TransactionData transactionData) {
|
||||||
|
this.txdata = transactionData;
|
||||||
|
}
|
||||||
|
|
||||||
public Transaction getTransaction() {
|
public Transaction getTransaction() {
|
||||||
return txdata.getTransaction();
|
return txdata.getTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTransaction(Transaction transaction) {
|
|
||||||
this.txdata = new TransactionData(transaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.txdata.setName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PSBT getPSBT() {
|
public PSBT getPSBT() {
|
||||||
return txdata.getPsbt();
|
return txdata.getPsbt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPSBT(PSBT psbt) {
|
|
||||||
this.txdata = new TransactionData(psbt);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlockTransaction getBlockTransaction() {
|
public BlockTransaction getBlockTransaction() {
|
||||||
return txdata.getBlockTransaction();
|
return txdata.getBlockTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBlockTransaction(BlockTransaction blockTransaction) {
|
|
||||||
this.txdata = new TransactionData(blockTransaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInitialView(TransactionView initialView, Integer initialIndex) {
|
public void setInitialView(TransactionView initialView, Integer initialIndex) {
|
||||||
this.initialView = initialView;
|
this.initialView = initialView;
|
||||||
this.initialIndex = initialIndex;
|
this.initialIndex = initialIndex;
|
||||||
|
|
|
@ -32,17 +32,18 @@ public class TransactionData {
|
||||||
private final SimpleObjectProperty<Wallet> signingWallet = new SimpleObjectProperty<>(this, "signingWallet", null);
|
private final SimpleObjectProperty<Wallet> signingWallet = new SimpleObjectProperty<>(this, "signingWallet", null);
|
||||||
private final ObservableList<Keystore> signedKeystores = FXCollections.observableArrayList();
|
private final ObservableList<Keystore> signedKeystores = FXCollections.observableArrayList();
|
||||||
|
|
||||||
public TransactionData(PSBT psbt) {
|
public TransactionData(String name, PSBT psbt) {
|
||||||
this.transaction = psbt.getTransaction();
|
this(name, psbt.getTransaction());
|
||||||
this.psbt = psbt;
|
this.psbt = psbt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransactionData(BlockTransaction blockTransaction) {
|
public TransactionData(String name, BlockTransaction blockTransaction) {
|
||||||
this.transaction = blockTransaction.getTransaction();
|
this(name, blockTransaction.getTransaction());
|
||||||
this.blockTransaction = blockTransaction;
|
this.blockTransaction = blockTransaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransactionData(Transaction transaction) {
|
public TransactionData(String name, Transaction transaction) {
|
||||||
|
this.name = name;
|
||||||
this.transaction = transaction;
|
this.transaction = transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,10 +59,6 @@ public class TransactionData {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PSBT getPsbt() {
|
public PSBT getPsbt() {
|
||||||
return psbt;
|
return psbt;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue