mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-05 05:46:44 +00:00
import descriptor from qr
This commit is contained in:
parent
68da8e6027
commit
37bb1c5d97
3 changed files with 44 additions and 19 deletions
|
@ -289,7 +289,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||||
|
|
||||||
private Address getAddress(CryptoAddress cryptoAddress) {
|
private Address getAddress(CryptoAddress cryptoAddress) {
|
||||||
Address address = null;
|
Address address = null;
|
||||||
if(cryptoAddress.getType() == CryptoAddress.Type.P2PKH) {
|
if(cryptoAddress.getType() == null || cryptoAddress.getType() == CryptoAddress.Type.P2PKH) {
|
||||||
address = new P2PKHAddress(cryptoAddress.getData());
|
address = new P2PKHAddress(cryptoAddress.getData());
|
||||||
} else if(cryptoAddress.getType() == CryptoAddress.Type.P2SH) {
|
} else if(cryptoAddress.getType() == CryptoAddress.Type.P2SH) {
|
||||||
address = new P2SHAddress(cryptoAddress.getData());
|
address = new P2SHAddress(cryptoAddress.getData());
|
||||||
|
|
|
@ -13,10 +13,7 @@ import com.sparrowwallet.drongo.wallet.Wallet;
|
||||||
import com.sparrowwallet.drongo.wallet.WalletModel;
|
import com.sparrowwallet.drongo.wallet.WalletModel;
|
||||||
import com.sparrowwallet.sparrow.AppController;
|
import com.sparrowwallet.sparrow.AppController;
|
||||||
import com.sparrowwallet.sparrow.EventManager;
|
import com.sparrowwallet.sparrow.EventManager;
|
||||||
import com.sparrowwallet.sparrow.control.CopyableLabel;
|
import com.sparrowwallet.sparrow.control.*;
|
||||||
import com.sparrowwallet.sparrow.control.DescriptorArea;
|
|
||||||
import com.sparrowwallet.sparrow.control.TextAreaDialog;
|
|
||||||
import com.sparrowwallet.sparrow.control.WalletPasswordDialog;
|
|
||||||
import com.sparrowwallet.sparrow.event.RequestOpenWalletsEvent;
|
import com.sparrowwallet.sparrow.event.RequestOpenWalletsEvent;
|
||||||
import com.sparrowwallet.sparrow.event.SettingsChangedEvent;
|
import com.sparrowwallet.sparrow.event.SettingsChangedEvent;
|
||||||
import com.sparrowwallet.sparrow.event.StorageEvent;
|
import com.sparrowwallet.sparrow.event.StorageEvent;
|
||||||
|
@ -251,6 +248,21 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void scanDescriptorQR(ActionEvent event) {
|
||||||
|
QRScanDialog qrScanDialog = new QRScanDialog();
|
||||||
|
Optional<QRScanDialog.Result> optionalResult = qrScanDialog.showAndWait();
|
||||||
|
if(optionalResult.isPresent()) {
|
||||||
|
QRScanDialog.Result result = optionalResult.get();
|
||||||
|
if(result.outputDescriptor != null) {
|
||||||
|
setDescriptorText(result.outputDescriptor.toString());
|
||||||
|
} else if(result.payload != null && !result.payload.isEmpty()) {
|
||||||
|
setDescriptorText(result.payload);
|
||||||
|
} else if(result.exception != null) {
|
||||||
|
AppController.showErrorDialog("Error scanning QR", result.exception.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void editDescriptor(ActionEvent event) {
|
public void editDescriptor(ActionEvent event) {
|
||||||
OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(walletForm.getWallet());
|
OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(walletForm.getWallet());
|
||||||
String outputDescriptorString = outputDescriptor.toString(walletForm.getWallet().isValid());
|
String outputDescriptorString = outputDescriptor.toString(walletForm.getWallet().isValid());
|
||||||
|
@ -260,8 +272,13 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||||
dialog.getDialogPane().setHeaderText("Wallet output descriptor:");
|
dialog.getDialogPane().setHeaderText("Wallet output descriptor:");
|
||||||
Optional<String> text = dialog.showAndWait();
|
Optional<String> text = dialog.showAndWait();
|
||||||
if(text.isPresent() && !text.get().isEmpty() && !text.get().equals(outputDescriptorString)) {
|
if(text.isPresent() && !text.get().isEmpty() && !text.get().equals(outputDescriptorString)) {
|
||||||
|
setDescriptorText(text.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDescriptorText(String text) {
|
||||||
try {
|
try {
|
||||||
OutputDescriptor editedOutputDescriptor = OutputDescriptor.getOutputDescriptor(text.get().trim().replace("\\", ""));
|
OutputDescriptor editedOutputDescriptor = OutputDescriptor.getOutputDescriptor(text.trim().replace("\\", ""));
|
||||||
Wallet editedWallet = editedOutputDescriptor.toWallet();
|
Wallet editedWallet = editedOutputDescriptor.toWallet();
|
||||||
|
|
||||||
editedWallet.setName(getWalletForm().getWallet().getName());
|
editedWallet.setName(getWalletForm().getWallet().getName());
|
||||||
|
@ -277,7 +294,6 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||||
AppController.showErrorDialog("Invalid output descriptor", e.getMessage());
|
AppController.showErrorDialog("Invalid output descriptor", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void showAdvanced(ActionEvent event) {
|
public void showAdvanced(ActionEvent event) {
|
||||||
AdvancedDialog advancedDialog = new AdvancedDialog(walletForm.getWallet());
|
AdvancedDialog advancedDialog = new AdvancedDialog(walletForm.getWallet());
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
<?import com.sparrowwallet.drongo.protocol.ScriptType?>
|
<?import com.sparrowwallet.drongo.protocol.ScriptType?>
|
||||||
<?import com.sparrowwallet.sparrow.control.DescriptorArea?>
|
<?import com.sparrowwallet.sparrow.control.DescriptorArea?>
|
||||||
<?import org.fxmisc.flowless.VirtualizedScrollPane?>
|
<?import org.fxmisc.flowless.VirtualizedScrollPane?>
|
||||||
|
<?import org.controlsfx.glyphfont.Glyph?>
|
||||||
|
|
||||||
<BorderPane stylesheets="@settings.css, @wallet.css, @../script.css, @../descriptor.css, @../general.css" styleClass="wallet-pane" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.wallet.SettingsController">
|
<BorderPane stylesheets="@settings.css, @wallet.css, @../script.css, @../descriptor.css, @../general.css" styleClass="wallet-pane" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.wallet.SettingsController">
|
||||||
<center>
|
<center>
|
||||||
|
@ -79,6 +80,14 @@
|
||||||
<DescriptorArea fx:id="descriptor" editable="false" styleClass="uneditable-codearea" prefHeight="27" maxHeight="27" />
|
<DescriptorArea fx:id="descriptor" editable="false" styleClass="uneditable-codearea" prefHeight="27" maxHeight="27" />
|
||||||
</content>
|
</content>
|
||||||
</VirtualizedScrollPane>
|
</VirtualizedScrollPane>
|
||||||
|
<Button onAction="#scanDescriptorQR">
|
||||||
|
<graphic>
|
||||||
|
<Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="12" icon="CAMERA" />
|
||||||
|
</graphic>
|
||||||
|
<tooltip>
|
||||||
|
<Tooltip text="Scan a QR code" />
|
||||||
|
</tooltip>
|
||||||
|
</Button>
|
||||||
<Button text="Edit..." onAction="#editDescriptor" />
|
<Button text="Edit..." onAction="#editDescriptor" />
|
||||||
</Field>
|
</Field>
|
||||||
</Fieldset>
|
</Fieldset>
|
||||||
|
|
Loading…
Reference in a new issue