Browse Source

import descriptor from qr

bwt
Craig Raw 4 years ago
parent
commit
37bb1c5d97
  1. 2
      src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java
  2. 56
      src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java
  3. 9
      src/main/resources/com/sparrowwallet/sparrow/wallet/settings.fxml

2
src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java

@ -289,7 +289,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
private Address getAddress(CryptoAddress cryptoAddress) {
Address address = null;
if(cryptoAddress.getType() == CryptoAddress.Type.P2PKH) {
if(cryptoAddress.getType() == null || cryptoAddress.getType() == CryptoAddress.Type.P2PKH) {
address = new P2PKHAddress(cryptoAddress.getData());
} else if(cryptoAddress.getType() == CryptoAddress.Type.P2SH) {
address = new P2SHAddress(cryptoAddress.getData());

56
src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java

@ -13,10 +13,7 @@ import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.drongo.wallet.WalletModel;
import com.sparrowwallet.sparrow.AppController;
import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.control.CopyableLabel;
import com.sparrowwallet.sparrow.control.DescriptorArea;
import com.sparrowwallet.sparrow.control.TextAreaDialog;
import com.sparrowwallet.sparrow.control.WalletPasswordDialog;
import com.sparrowwallet.sparrow.control.*;
import com.sparrowwallet.sparrow.event.RequestOpenWalletsEvent;
import com.sparrowwallet.sparrow.event.SettingsChangedEvent;
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) {
OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(walletForm.getWallet());
String outputDescriptorString = outputDescriptor.toString(walletForm.getWallet().isValid());
@ -260,22 +272,26 @@ public class SettingsController extends WalletFormController implements Initiali
dialog.getDialogPane().setHeaderText("Wallet output descriptor:");
Optional<String> text = dialog.showAndWait();
if(text.isPresent() && !text.get().isEmpty() && !text.get().equals(outputDescriptorString)) {
try {
OutputDescriptor editedOutputDescriptor = OutputDescriptor.getOutputDescriptor(text.get().trim().replace("\\", ""));
Wallet editedWallet = editedOutputDescriptor.toWallet();
editedWallet.setName(getWalletForm().getWallet().getName());
keystoreTabs.getTabs().removeAll(keystoreTabs.getTabs());
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());
}
setDescriptorText(text.get());
}
}
private void setDescriptorText(String text) {
try {
OutputDescriptor editedOutputDescriptor = OutputDescriptor.getOutputDescriptor(text.trim().replace("\\", ""));
Wallet editedWallet = editedOutputDescriptor.toWallet();
editedWallet.setName(getWalletForm().getWallet().getName());
keystoreTabs.getTabs().removeAll(keystoreTabs.getTabs());
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());
}
}

9
src/main/resources/com/sparrowwallet/sparrow/wallet/settings.fxml

@ -11,6 +11,7 @@
<?import com.sparrowwallet.drongo.protocol.ScriptType?>
<?import com.sparrowwallet.sparrow.control.DescriptorArea?>
<?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">
<center>
@ -79,6 +80,14 @@
<DescriptorArea fx:id="descriptor" editable="false" styleClass="uneditable-codearea" prefHeight="27" maxHeight="27" />
</content>
</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" />
</Field>
</Fieldset>

Loading…
Cancel
Save