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,22 +272,26 @@ 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)) {
|
||||||
try {
|
setDescriptorText(text.get());
|
||||||
OutputDescriptor editedOutputDescriptor = OutputDescriptor.getOutputDescriptor(text.get().trim().replace("\\", ""));
|
}
|
||||||
Wallet editedWallet = editedOutputDescriptor.toWallet();
|
}
|
||||||
|
|
||||||
editedWallet.setName(getWalletForm().getWallet().getName());
|
private void setDescriptorText(String text) {
|
||||||
keystoreTabs.getTabs().removeAll(keystoreTabs.getTabs());
|
try {
|
||||||
totalKeystores.unbind();
|
OutputDescriptor editedOutputDescriptor = OutputDescriptor.getOutputDescriptor(text.trim().replace("\\", ""));
|
||||||
totalKeystores.setValue(0);
|
Wallet editedWallet = editedOutputDescriptor.toWallet();
|
||||||
walletForm.setWallet(editedWallet);
|
|
||||||
initialising = true;
|
|
||||||
setFieldsFromWallet(editedWallet);
|
|
||||||
|
|
||||||
EventManager.get().post(new SettingsChangedEvent(editedWallet, SettingsChangedEvent.Type.POLICY));
|
editedWallet.setName(getWalletForm().getWallet().getName());
|
||||||
} catch(Exception e) {
|
keystoreTabs.getTabs().removeAll(keystoreTabs.getTabs());
|
||||||
AppController.showErrorDialog("Invalid output descriptor", e.getMessage());
|
totalKeystores.unbind();
|
||||||
}
|
totalKeystores.setValue(0);
|
||||||
|
walletForm.setWallet(editedWallet);
|
||||||
|
initialising = true;
|
||||||
|
setFieldsFromWallet(editedWallet);
|
||||||
|
|
||||||
|
EventManager.get().post(new SettingsChangedEvent(editedWallet, SettingsChangedEvent.Type.POLICY));
|
||||||
|
} catch(Exception e) {
|
||||||
|
AppController.showErrorDialog("Invalid output descriptor", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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