mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
allow crypto-output qr scanning from wallet import dialog
This commit is contained in:
parent
4ab33a373c
commit
90a9030ecb
4 changed files with 20 additions and 4 deletions
|
@ -162,8 +162,8 @@ public abstract class FileImportPane extends TitledDescriptionPane {
|
||||||
setError("Import Error", e.getMessage());
|
setError("Import Error", e.getMessage());
|
||||||
}
|
}
|
||||||
} else if(result.outputDescriptor != null) {
|
} else if(result.outputDescriptor != null) {
|
||||||
wallets = List.of(result.outputDescriptor.toKeystoreWallet(null));
|
|
||||||
try {
|
try {
|
||||||
|
wallets = List.of(result.outputDescriptor.toWallet());
|
||||||
importFile(importer.getName(), null, null);
|
importFile(importer.getName(), null, null);
|
||||||
} catch(ImportException e) {
|
} catch(ImportException e) {
|
||||||
log.error("Error importing QR", e);
|
log.error("Error importing QR", e);
|
||||||
|
@ -193,6 +193,10 @@ public abstract class FileImportPane extends TitledDescriptionPane {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected List<Wallet> getScannedWallets() {
|
||||||
|
return wallets;
|
||||||
|
}
|
||||||
|
|
||||||
protected Keystore getScannedKeystore(ScriptType scriptType) throws ImportException {
|
protected Keystore getScannedKeystore(ScriptType scriptType) throws ImportException {
|
||||||
if(wallets != null) {
|
if(wallets != null) {
|
||||||
for(Wallet wallet : wallets) {
|
for(Wallet wallet : wallets) {
|
||||||
|
|
|
@ -18,7 +18,13 @@ public class FileWalletImportPane extends FileImportPane {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void importFile(String fileName, InputStream inputStream, String password) throws ImportException {
|
protected void importFile(String fileName, InputStream inputStream, String password) throws ImportException {
|
||||||
Wallet wallet = importer.importWallet(inputStream, password);
|
Wallet wallet;
|
||||||
|
if(getScannedWallets() != null && !getScannedWallets().isEmpty()) {
|
||||||
|
wallet = getScannedWallets().iterator().next();
|
||||||
|
} else {
|
||||||
|
wallet = importer.importWallet(inputStream, password);
|
||||||
|
}
|
||||||
|
|
||||||
if(wallet.getName() == null) {
|
if(wallet.getName() == null) {
|
||||||
wallet.setName(fileName);
|
wallet.setName(fileName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ import java.util.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
@ -542,7 +543,12 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||||
|
|
||||||
private KeyDerivation getKeyDerivation(CryptoKeypath cryptoKeypath) {
|
private KeyDerivation getKeyDerivation(CryptoKeypath cryptoKeypath) {
|
||||||
if(cryptoKeypath != null) {
|
if(cryptoKeypath != null) {
|
||||||
return new KeyDerivation(Utils.bytesToHex(cryptoKeypath.getSourceFingerprint()), cryptoKeypath.getPath());
|
if(cryptoKeypath.getComponents().stream().anyMatch(PathComponent::isWildcard)) {
|
||||||
|
throw new IllegalArgumentException("Wildcard derivation paths are not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ChildNumber> path = cryptoKeypath.getComponents().stream().map(comp -> new ChildNumber(comp.getIndex(), comp.isHardened())).collect(Collectors.toList());
|
||||||
|
return new KeyDerivation(Utils.bytesToHex(cryptoKeypath.getSourceFingerprint()), KeyDerivation.writePath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -136,6 +136,6 @@ public class Descriptor implements WalletImport, WalletExport {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWalletImportScannable() {
|
public boolean isWalletImportScannable() {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue