Merge pull request #2577 from BlueWallet/jsonim

ADD:  Standard wallet type Electrum JSON import
This commit is contained in:
GLaDOS 2021-02-09 14:21:08 +00:00 committed by GitHub
commit 0b859a10b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 3 deletions

View File

@ -164,12 +164,25 @@ export class AbstractWallet {
} }
try { try {
const parsedSecret = JSON.parse(this.secret); let parsedSecret;
// regex might've matched invalid data. if so, parse newSecret.
if (this.secret.trim().length > 0) {
try {
parsedSecret = JSON.parse(this.secret);
} catch (e) {
console.log(e);
parsedSecret = JSON.parse(newSecret);
}
} else {
parsedSecret = JSON.parse(newSecret);
}
if (parsedSecret && parsedSecret.keystore && parsedSecret.keystore.xpub) { if (parsedSecret && parsedSecret.keystore && parsedSecret.keystore.xpub) {
let masterFingerprint = false; let masterFingerprint = false;
if (parsedSecret.keystore.ckcc_xfp) { if (parsedSecret.keystore.ckcc_xfp) {
// It is a ColdCard Hardware Wallet // It is a ColdCard Hardware Wallet
masterFingerprint = Number(parsedSecret.keystore.ckcc_xfp); masterFingerprint = Number(parsedSecret.keystore.ckcc_xfp);
} else if (parsedSecret.keystore.root_fingerprint) {
masterFingerprint = Number(parsedSecret.keystore.root_fingerprint);
} }
if (parsedSecret.keystore.label) { if (parsedSecret.keystore.label) {
this.setLabel(parsedSecret.keystore.label); this.setLabel(parsedSecret.keystore.label);

View File

@ -480,7 +480,7 @@ export class MultisigHDWallet extends AbstractHDElectrumWallet {
} }
// is it electrum json? // is it electrum json?
if (json && json.wallet_type) { if (json && json.wallet_type && json.wallet_type !== 'standard') {
const mofn = json.wallet_type.split('of'); const mofn = json.wallet_type.split('of');
this.setM(parseInt(mofn[0].trim())); this.setM(parseInt(mofn[0].trim()));
const n = parseInt(mofn[1].trim()); const n = parseInt(mofn[1].trim());

View File

@ -141,7 +141,6 @@ const WalletsImport = () => {
<BlueDoneAndDismissKeyboardInputAccessory <BlueDoneAndDismissKeyboardInputAccessory
onClearTapped={() => { onClearTapped={() => {
setImportText(''); setImportText('');
Keyboard.dismiss();
}} }}
onPasteTapped={text => { onPasteTapped={text => {
setImportText(text); setImportText(text);

File diff suppressed because one or more lines are too long