mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2026-08-09 16:24:53 +00:00
wallet and settings initial work
This commit is contained in:
@@ -7,11 +7,14 @@ import com.sparrowwallet.drongo.Utils;
|
||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||
import com.sparrowwallet.drongo.psbt.PSBT;
|
||||
import com.sparrowwallet.drongo.psbt.PSBTParseException;
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.sparrow.control.TextAreaDialog;
|
||||
import com.sparrowwallet.sparrow.event.TabEvent;
|
||||
import com.sparrowwallet.sparrow.event.TransactionTabChangedEvent;
|
||||
import com.sparrowwallet.sparrow.event.TransactionTabSelectedEvent;
|
||||
import com.sparrowwallet.sparrow.transaction.TransactionController;
|
||||
import com.sparrowwallet.sparrow.wallet.WalletController;
|
||||
import com.sparrowwallet.sparrow.wallet.WalletForm;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
@@ -88,6 +91,8 @@ public class AppController implements Initializable {
|
||||
|
||||
showTxHex.setSelected(true);
|
||||
showTxHexProperty = true;
|
||||
|
||||
addWalletTab(null, new Wallet());
|
||||
}
|
||||
|
||||
public void openFromFile(ActionEvent event) {
|
||||
@@ -192,6 +197,36 @@ public class AppController implements Initializable {
|
||||
showTxHexProperty = item.isSelected();
|
||||
}
|
||||
|
||||
public void newWallet(ActionEvent event) {
|
||||
Tab tab = addWalletTab(null, new Wallet());
|
||||
tabs.getSelectionModel().select(tab);
|
||||
}
|
||||
|
||||
public Tab addWalletTab(String name, Wallet wallet) {
|
||||
try {
|
||||
String tabName = name;
|
||||
if(tabName == null || tabName.isEmpty()) {
|
||||
tabName = "New wallet";
|
||||
}
|
||||
|
||||
Tab tab = new Tab(tabName);
|
||||
TabData tabData = new TabData(TabData.TabType.WALLET);
|
||||
tab.setUserData(tabData);
|
||||
tab.setContextMenu(getTabContextMenu(tab));
|
||||
tab.setClosable(true);
|
||||
FXMLLoader walletLoader = new FXMLLoader(getClass().getResource("wallet/wallet.fxml"));
|
||||
tab.setContent(walletLoader.load());
|
||||
WalletController controller = walletLoader.getController();
|
||||
WalletForm walletForm = new WalletForm(wallet);
|
||||
controller.setWalletForm(walletForm);
|
||||
|
||||
tabs.getTabs().add(tab);
|
||||
return tab;
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void openExamples(ActionEvent event) {
|
||||
try {
|
||||
addTransactionTab("p2pkh", "01000000019c2e0f24a03e72002a96acedb12a632e72b6b74c05dc3ceab1fe78237f886c48010000006a47304402203da9d487be5302a6d69e02a861acff1da472885e43d7528ed9b1b537a8e2cac9022002d1bca03a1e9715a99971bafe3b1852b7a4f0168281cbd27a220380a01b3307012102c9950c622494c2e9ff5a003e33b690fe4832477d32c2d256c67eab8bf613b34effffffff02b6f50500000000001976a914bdf63990d6dc33d705b756e13dd135466c06b3b588ac845e0201000000001976a9145fb0e9755a3424efd2ba0587d20b1e98ee29814a88ac06241559");
|
||||
|
||||
@@ -32,6 +32,6 @@ public class TabData {
|
||||
}
|
||||
|
||||
public enum TabType {
|
||||
TRANSACTION
|
||||
WALLET, TRANSACTION
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.sparrowwallet.sparrow.control;
|
||||
|
||||
import javafx.beans.NamedArg;
|
||||
import javafx.scene.control.ChoiceBox;
|
||||
|
||||
public class EnumChoiceBox<E extends Enum<E>> extends ChoiceBox<E> {
|
||||
|
||||
public EnumChoiceBox(@NamedArg("enumType") String enumType) throws Exception {
|
||||
Class<E> enumClass = (Class<E>) Class.forName(enumType);
|
||||
getItems().setAll(enumClass.getEnumConstants());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import static org.fxmisc.richtext.model.TwoDimensional.Bias.Backward;
|
||||
import static com.sparrowwallet.drongo.protocol.ScriptType.*;
|
||||
|
||||
public abstract class TransactionFormController {
|
||||
protected void addPieData(PieChart pie, List<TransactionOutput> outputs) {
|
||||
@@ -57,7 +58,7 @@ public abstract class TransactionFormController {
|
||||
}
|
||||
|
||||
protected void appendScript(CodeArea codeArea, Script script, Script redeemScript, Script witnessScript) {
|
||||
if(ScriptPattern.isP2PKH(script)) {
|
||||
if(P2PKH.isScriptType(script)) {
|
||||
codeArea.append(script.getChunks().get(0).toString(), "script-opcode");
|
||||
codeArea.append(" ", "");
|
||||
codeArea.append(script.getChunks().get(1).toString(), "script-opcode");
|
||||
@@ -67,17 +68,17 @@ public abstract class TransactionFormController {
|
||||
codeArea.append(script.getChunks().get(3).toString(), "script-opcode");
|
||||
codeArea.append(" ", "");
|
||||
codeArea.append(script.getChunks().get(4).toString(), "script-opcode");
|
||||
} else if(ScriptPattern.isP2SH(script)) {
|
||||
} else if(P2SH.isScriptType(script)) {
|
||||
codeArea.append(script.getChunks().get(0).toString(), "script-opcode");
|
||||
codeArea.append(" ", "");
|
||||
codeArea.append("<sh>", "script-hash");
|
||||
codeArea.append(" ", "");
|
||||
codeArea.append(script.getChunks().get(2).toString(), "script-opcode");
|
||||
} else if(ScriptPattern.isP2WPKH(script)) {
|
||||
} else if(P2WPKH.isScriptType(script)) {
|
||||
codeArea.append(script.getChunks().get(0).toString(), "script-opcode");
|
||||
codeArea.append(" ", "");
|
||||
codeArea.append("<wpkh>", "script-hash");
|
||||
} else if(ScriptPattern.isP2WSH(script)) {
|
||||
} else if(P2WSH.isScriptType(script)) {
|
||||
codeArea.append(script.getChunks().get(0).toString(), "script-opcode");
|
||||
codeArea.append(" ", "");
|
||||
codeArea.append("<wsh>", "script-hash");
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.sparrowwallet.sparrow.wallet;
|
||||
|
||||
public enum Function {
|
||||
TRANSACTIONS, SEND, RECEIVE, ADDRESSES, POLICIES, SETTINGS;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.sparrowwallet.sparrow.wallet;
|
||||
|
||||
import com.sparrowwallet.drongo.policy.PolicyType;
|
||||
import com.sparrowwallet.drongo.protocol.ScriptType;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.control.CopyableLabel;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.*;
|
||||
import org.controlsfx.control.RangeSlider;
|
||||
import tornadofx.control.Fieldset;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class SettingsController extends WalletFormController implements Initializable {
|
||||
|
||||
@FXML
|
||||
private ComboBox<PolicyType> policyType;
|
||||
|
||||
@FXML
|
||||
private TextField policy;
|
||||
|
||||
@FXML
|
||||
private ComboBox<ScriptType> scriptType;
|
||||
|
||||
@FXML
|
||||
private Fieldset multisigFieldset;
|
||||
|
||||
@FXML
|
||||
private RangeSlider multisigControl;
|
||||
|
||||
@FXML
|
||||
private CopyableLabel multisigLowLabel;
|
||||
|
||||
@FXML
|
||||
private CopyableLabel multisigHighLabel;
|
||||
|
||||
@FXML
|
||||
private TabPane keystoreTabs;
|
||||
|
||||
@FXML ComboBox testType;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
EventManager.get().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeView() {
|
||||
policyType.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, policyType) -> {
|
||||
scriptType.getSelectionModel().select(policyType.getDefaultScriptType());
|
||||
multisigFieldset.setVisible(policyType.equals(PolicyType.MULTI));
|
||||
});
|
||||
|
||||
multisigLowLabel.textProperty().bind(multisigControl.lowValueProperty().asString("%.0f") );
|
||||
multisigHighLabel.textProperty().bind(multisigControl.highValueProperty().asString("%.0f"));
|
||||
|
||||
multisigFieldset.managedProperty().bind(multisigFieldset.visibleProperty());
|
||||
|
||||
if(walletForm.getWallet().getPolicyType() != null) {
|
||||
policyType.getSelectionModel().select(walletForm.getWallet().getPolicyType());
|
||||
} else {
|
||||
policyType.getSelectionModel().select(0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.sparrowwallet.sparrow.wallet;
|
||||
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.sparrow.AppController;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.ToggleGroup;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class WalletController extends WalletFormController implements Initializable {
|
||||
@FXML
|
||||
private BorderPane tabContent;
|
||||
|
||||
@FXML
|
||||
private StackPane walletPane;
|
||||
|
||||
@FXML
|
||||
private ToggleGroup walletMenu;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
EventManager.get().register(this);
|
||||
}
|
||||
|
||||
public void initializeView() {
|
||||
walletMenu.selectedToggleProperty().addListener((observable, oldValue, selectedToggle) -> {
|
||||
Function function = (Function)selectedToggle.getUserData();
|
||||
|
||||
boolean existing = false;
|
||||
for(Node walletFunction : walletPane.getChildren()) {
|
||||
if(walletFunction.getUserData().equals(function)) {
|
||||
existing = true;
|
||||
walletFunction.setViewOrder(1);
|
||||
} else {
|
||||
walletFunction.setViewOrder(0);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if(!existing) {
|
||||
FXMLLoader functionLoader = new FXMLLoader(AppController.class.getResource("wallet/" + function.toString().toLowerCase() + ".fxml"));
|
||||
Node walletFunction = functionLoader.load();
|
||||
WalletFormController controller = functionLoader.getController();
|
||||
controller.setWalletForm(getWalletForm());
|
||||
walletFunction.setViewOrder(1);
|
||||
walletPane.getChildren().add(walletFunction);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Can't find pane", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.sparrowwallet.sparrow.wallet;
|
||||
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
|
||||
public class WalletForm {
|
||||
private Wallet wallet;
|
||||
|
||||
public WalletForm(Wallet wallet) {
|
||||
this.wallet = wallet;
|
||||
}
|
||||
|
||||
public Wallet getWallet() {
|
||||
return wallet;
|
||||
}
|
||||
|
||||
public void setWallet(Wallet wallet) {
|
||||
this.wallet = wallet;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.sparrowwallet.sparrow.wallet;
|
||||
|
||||
public abstract class WalletFormController {
|
||||
public WalletForm walletForm;
|
||||
|
||||
public WalletForm getWalletForm() {
|
||||
return walletForm;
|
||||
}
|
||||
|
||||
public void setWalletForm(WalletForm walletForm) {
|
||||
this.walletForm = walletForm;
|
||||
initializeView();
|
||||
}
|
||||
|
||||
public abstract void initializeView();
|
||||
}
|
||||
@@ -8,4 +8,5 @@ open module com.sparrowwallet.sparrow {
|
||||
requires com.sparrowwallet.drongo;
|
||||
requires com.google.common;
|
||||
requires flowless;
|
||||
requires javafx.swing;
|
||||
}
|
||||
Reference in New Issue
Block a user