|
|
@ -5,6 +5,8 @@ import { BlueText, SafeBlueArea, BlueButton } from '../../BlueComponents'; |
|
|
|
import { Permissions, BarCodeScanner } from 'expo'; |
|
|
|
import { SegwitP2SHWallet, LegacyWallet, WatchOnlyWallet } from '../../class'; |
|
|
|
import PropTypes from 'prop-types'; |
|
|
|
import { HDSegwitP2SHWallet } from '../../class/hd-segwit-p2sh-wallet'; |
|
|
|
import { LightningCustodianWallet } from '../../class/lightning-custodian-wallet'; |
|
|
|
/** @type {AppStorage} */ |
|
|
|
let BlueApp = require('../../BlueApp'); |
|
|
|
let EV = require('../../events'); |
|
|
@ -61,13 +63,58 @@ export default class ScanQrWif extends React.Component { |
|
|
|
} |
|
|
|
|
|
|
|
for (let w of BlueApp.wallets) { |
|
|
|
// lookig for duplicates
|
|
|
|
if (w.getSecret() === ret.data) { |
|
|
|
alert(loc.wallets.scanQrWif.wallet_already_exists); |
|
|
|
return; // duplicate, not adding
|
|
|
|
// lookig for duplicates
|
|
|
|
return alert(loc.wallets.scanQrWif.wallet_already_exists); // duplicate, not adding
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// is it HD mnemonic?
|
|
|
|
let hd = new HDSegwitP2SHWallet(); |
|
|
|
hd.setSecret(ret.data); |
|
|
|
if (hd.validateMnemonic()) { |
|
|
|
for (let w of BlueApp.wallets) { |
|
|
|
if (w.getSecret() === hd.getSecret()) { |
|
|
|
// lookig for duplicates
|
|
|
|
return alert(loc.wallets.scanQrWif.wallet_already_exists); // duplicate, not adding
|
|
|
|
} |
|
|
|
} |
|
|
|
this.setState({ isLoading: true }); |
|
|
|
hd.setLabel(loc.wallets.import.imported + ' ' + hd.getTypeReadable()); |
|
|
|
BlueApp.wallets.push(hd); |
|
|
|
await hd.fetchBalance(); |
|
|
|
await hd.fetchTransactions(); |
|
|
|
await BlueApp.saveToDisk(); |
|
|
|
alert(loc.wallets.import.success); |
|
|
|
this.props.navigation.popToTop(); |
|
|
|
setTimeout(() => EV(EV.enum.WALLETS_COUNT_CHANGED), 500); |
|
|
|
return; |
|
|
|
} |
|
|
|
// nope
|
|
|
|
|
|
|
|
// is it blitzhub?
|
|
|
|
if (ret.data.indexOf('blitzhub://') !== -1) { |
|
|
|
this.setState({ isLoading: true }); |
|
|
|
let lnd = new LightningCustodianWallet(); |
|
|
|
lnd.setSecret(ret.data); |
|
|
|
try { |
|
|
|
await lnd.authorize(); |
|
|
|
await lnd.fetchTransactions(); |
|
|
|
await lnd.fetchBalance(); |
|
|
|
} catch (Err) { |
|
|
|
console.log(Err); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
BlueApp.wallets.push(lnd); |
|
|
|
lnd.setLabel(loc.wallets.import.imported + ' ' + lnd.getTypeReadable()); |
|
|
|
this.props.navigation.popToTop(); |
|
|
|
alert(loc.wallets.import.success); |
|
|
|
setTimeout(() => EV(EV.enum.WALLETS_COUNT_CHANGED), 500); |
|
|
|
return; |
|
|
|
} |
|
|
|
// nope
|
|
|
|
|
|
|
|
// is it just address..?
|
|
|
|
let watchOnly = new WatchOnlyWallet(); |
|
|
|
if (watchOnly.isAddressValid(ret.data)) { |
|
|
|