mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-03 03:59:10 +01:00
ADD: Watch-only addresses
This commit is contained in:
parent
13beee33bf
commit
4349dd8f36
4 changed files with 61 additions and 4 deletions
28
App.test.js
28
App.test.js
|
@ -1,6 +1,6 @@
|
|||
/* global describe, it, expect, jest, jasmine */
|
||||
import React from 'react';
|
||||
import { LegacyWallet, SegwitP2SHWallet, AppStorage } from './class';
|
||||
import { WatchOnlyWallet, LegacyWallet, SegwitP2SHWallet, AppStorage } from './class';
|
||||
import renderer from 'react-test-renderer';
|
||||
import Settings from './screen/settings';
|
||||
import Selftest from './screen/selftest';
|
||||
|
@ -37,6 +37,15 @@ describe('unit - LegacyWallet', function() {
|
|||
|
||||
assert.equal(key, JSON.stringify(b));
|
||||
});
|
||||
|
||||
it('can validate addresses', () => {
|
||||
let w = new LegacyWallet();
|
||||
assert.ok(w.isAddressValid('12eQ9m4sgAwTSQoNXkRABKhCXCsjm2jdVG'));
|
||||
assert.ok(!w.isAddressValid('12eQ9m4sgAwTSQoNXkRABKhCXCsjm2j'));
|
||||
assert.ok(w.isAddressValid('3BDsBDxDimYgNZzsqszNZobqQq3yeUoJf2'));
|
||||
assert.ok(!w.isAddressValid('3BDsBDxDimYgNZzsqszNZobqQq3yeUo'));
|
||||
assert.ok(!w.isAddressValid('12345'));
|
||||
});
|
||||
});
|
||||
|
||||
it('BlueHeader works', () => {
|
||||
|
@ -214,7 +223,6 @@ it('Wallet can fetch TXs', async () => {
|
|||
let w = new LegacyWallet();
|
||||
w._address = '12eQ9m4sgAwTSQoNXkRABKhCXCsjm2jdVG';
|
||||
await w.fetchTransactions();
|
||||
console.log('txs num:', w.getTransactions().length);
|
||||
assert.equal(w.getTransactions().length, 2);
|
||||
|
||||
let tx0 = w.getTransactions()[0];
|
||||
|
@ -280,3 +288,19 @@ describe('currency', () => {
|
|||
assert.ok(cur[currency.STRUCT.BTC_USD] > 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Watch only wallet', () => {
|
||||
it('can fetch balance', async () => {
|
||||
let w = new WatchOnlyWallet();
|
||||
w.setSecret('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa');
|
||||
await w.fetchBalance();
|
||||
assert.ok(w.getBalance() > 16);
|
||||
});
|
||||
|
||||
it('can fetch tx', async () => {
|
||||
let w = new WatchOnlyWallet();
|
||||
w.setSecret('12eQ9m4sgAwTSQoNXkRABKhCXCsjm2jdVG');
|
||||
await w.fetchTransactions();
|
||||
assert.equal(w.getTransactions().length, 2);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@ import Ionicons from 'react-native-vector-icons/Ionicons';
|
|||
import { LinearGradient } from 'expo';
|
||||
import { Icon, Button, FormLabel, FormInput, Card, Text, Header, List, ListItem } from 'react-native-elements';
|
||||
import { TouchableOpacity, ActivityIndicator, View, StyleSheet, Dimensions, Image } from 'react-native';
|
||||
import { WatchOnlyWallet, LegacyWallet } from './class';
|
||||
import Carousel from 'react-native-snap-carousel';
|
||||
let loc = require('./loc/');
|
||||
/** @type {AppStorage} */
|
||||
|
@ -802,6 +803,20 @@ export class WalletsCarousel extends Component {
|
|||
/>
|
||||
);
|
||||
}
|
||||
|
||||
let gradient1 = '#65ceef';
|
||||
let gradient2 = '#68bbe1';
|
||||
|
||||
if (new WatchOnlyWallet().type === item.type) {
|
||||
gradient1 = '#7d7d7d';
|
||||
gradient2 = '#4a4a4a';
|
||||
}
|
||||
|
||||
if (new LegacyWallet().type === item.type) {
|
||||
gradient1 = '#40fad1';
|
||||
gradient2 = '#15be98';
|
||||
}
|
||||
|
||||
return (
|
||||
<TouchableOpacity
|
||||
activeOpacity={1}
|
||||
|
@ -812,7 +827,7 @@ export class WalletsCarousel extends Component {
|
|||
}
|
||||
}}
|
||||
>
|
||||
<LinearGradient colors={['#65ceef', '#68bbe1']} style={{ padding: 15, borderRadius: 10, height: 145 }}>
|
||||
<LinearGradient colors={[gradient1, gradient2]} style={{ padding: 15, borderRadius: 10, height: 145 }}>
|
||||
<Image
|
||||
source={require('./img/btc-shape.png')}
|
||||
style={{
|
||||
|
|
|
@ -61,6 +61,7 @@ module.exports = {
|
|||
with_address: ' with address ',
|
||||
imported_segwit: 'Imported SegWit',
|
||||
imported_legacy: 'Imported Legacy',
|
||||
imported_watchonly: 'Imported Watch-only',
|
||||
},
|
||||
},
|
||||
transactions: {
|
||||
|
|
|
@ -3,7 +3,7 @@ import React from 'react';
|
|||
import { Text, ActivityIndicator, Button, View, TouchableOpacity } from 'react-native';
|
||||
import { BlueText, SafeBlueArea, BlueButton } from '../../BlueComponents';
|
||||
import { Camera, Permissions } from 'expo';
|
||||
import { SegwitP2SHWallet, LegacyWallet } from '../../class';
|
||||
import { SegwitP2SHWallet, LegacyWallet, WatchOnlyWallet } from '../../class';
|
||||
import PropTypes from 'prop-types';
|
||||
/** @type {AppStorage} */
|
||||
let BlueApp = require('../../BlueApp');
|
||||
|
@ -69,6 +69,22 @@ export default class ScanQrWif extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
// is it just address..?
|
||||
let watchOnly = new WatchOnlyWallet();
|
||||
if (watchOnly.isAddressValid(ret.data)) {
|
||||
watchOnly.setSecret(ret.data);
|
||||
watchOnly.setLabel(loc.wallets.scanQrWif.imported_watchonly);
|
||||
BlueApp.wallets.push(watchOnly);
|
||||
alert(loc.wallets.scanQrWif.imported_watchonly + loc.wallets.scanQrWif.with_address + watchOnly.getAddress());
|
||||
await watchOnly.fetchBalance();
|
||||
await watchOnly.fetchTransactions();
|
||||
await BlueApp.saveToDisk();
|
||||
this.props.navigation.popToTop();
|
||||
setTimeout(() => EV(EV.enum.WALLETS_COUNT_CHANGED), 500);
|
||||
return;
|
||||
}
|
||||
// nope
|
||||
|
||||
let newWallet = new SegwitP2SHWallet();
|
||||
newWallet.setSecret(ret.data);
|
||||
let newLegacyWallet = new LegacyWallet();
|
||||
|
@ -87,6 +103,7 @@ export default class ScanQrWif extends React.Component {
|
|||
newLegacyWallet.setLabel(loc.wallets.scanQrWif.imported_legacy);
|
||||
BlueApp.wallets.push(newLegacyWallet);
|
||||
alert(loc.wallets.scanQrWif.imported_wif + ret.data + loc.wallets.scanQrWif.with_address + newLegacyWallet.getAddress());
|
||||
await newLegacyWallet.fetchTransactions();
|
||||
} else {
|
||||
await newWallet.fetchBalance();
|
||||
await newWallet.fetchTransactions();
|
||||
|
|
Loading…
Add table
Reference in a new issue