Skip to content

Commit

Permalink
ADD: Apple Watch support
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosrdz authored and Overtorment committed May 2, 2019
1 parent c17ad26 commit 33bffaa
Show file tree
Hide file tree
Showing 148 changed files with 19,770 additions and 2,778 deletions.
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[version]
^0.86.0
^0.97.0
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ buck-out/

#BlueWallet
release-notes.json
release-notes.txt
release-notes.txt

ios/Pods/
3 changes: 2 additions & 1 deletion App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Linking, AppState, Clipboard, StyleSheet, KeyboardAvoidingView, Platform, View, AsyncStorage } from 'react-native';
import { Linking, AppState, Clipboard, StyleSheet, KeyboardAvoidingView, Platform, View } from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
import Modal from 'react-native-modal';
import { NavigationActions } from 'react-navigation';
import MainBottomTabs from './MainBottomTabs';
Expand Down
22 changes: 8 additions & 14 deletions App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import TestRenderer from 'react-test-renderer';
import Settings from './screen/settings/settings';
import Selftest from './screen/selftest';
import { BlueHeader } from './BlueComponents';
import MockStorage from './MockStorage';
import { FiatUnit } from './models/fiatUnit';
import AsyncStorage from '@react-native-community/async-storage';
global.crypto = require('crypto'); // shall be used by tests under nodejs CLI, but not in RN environment
let assert = require('assert');
jest.mock('react-native-qrcode-svg', () => 'Video');
const AsyncStorage = new MockStorage();
jest.setMock('AsyncStorage', AsyncStorage);
jest.useFakeTimers();
jest.mock('Picker', () => {
// eslint-disable-next-line import/no-unresolved
Expand Down Expand Up @@ -105,7 +103,6 @@ it('Selftest work', () => {
});

it('Appstorage - loadFromDisk works', async () => {
AsyncStorage.storageCache = {}; // cleanup from other tests
/** @type {AppStorage} */
let Storage = new AppStorage();
let w = new SegwitP2SHWallet();
Expand All @@ -125,16 +122,14 @@ it('Appstorage - loadFromDisk works', async () => {

// emulating encrypted storage (and testing flag)

AsyncStorage.storageCache.data = false;
AsyncStorage.storageCache.data_encrypted = '1'; // flag
await AsyncStorage.setItem('data', false);
await AsyncStorage.setItem(AppStorage.FLAG_ENCRYPTED, '1');
let Storage3 = new AppStorage();
isEncrypted = await Storage3.storageIsEncrypted();
assert.ok(isEncrypted);
});

it('Appstorage - encryptStorage & load encrypted storage works', async () => {
AsyncStorage.storageCache = {}; // cleanup from other tests

/** @type {AppStorage} */
let Storage = new AppStorage();
let w = new SegwitP2SHWallet();
Expand Down Expand Up @@ -236,7 +231,7 @@ it('Wallet can fetch balance', async () => {
assert.ok(w.getUnconfirmedBalance() === 0);
assert.ok(w._lastBalanceFetch === 0);
await w.fetchBalance();
assert.ok(w.getBalance() === 0.18262);
assert.ok(w.getBalance() === 18262000);
assert.ok(w.getUnconfirmedBalance() === 0);
assert.ok(w._lastBalanceFetch > 0);
});
Expand Down Expand Up @@ -302,27 +297,26 @@ it('Wallet can fetch TXs', async () => {
describe('currency', () => {
it('fetches exchange rate and saves to AsyncStorage', async () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 15000;
AsyncStorage.storageCache = {}; // cleanup from other tests
let currency = require('./currency');
await currency.startUpdater();
let cur = AsyncStorage.storageCache[AppStorage.EXCHANGE_RATES];
let cur = await AsyncStorage.getItem(AppStorage.EXCHANGE_RATES);
cur = JSON.parse(cur);
assert.ok(Number.isInteger(cur[currency.STRUCT.LAST_UPDATED]));
assert.ok(cur[currency.STRUCT.LAST_UPDATED] > 0);
assert.ok(cur['BTC_USD'] > 0);

// now, setting other currency as default
AsyncStorage.storageCache[AppStorage.PREFERRED_CURRENCY] = JSON.stringify(FiatUnit.JPY);
await AsyncStorage.setItem(AppStorage.PREFERRED_CURRENCY, JSON.stringify(FiatUnit.JPY));
await currency.startUpdater();
cur = JSON.parse(AsyncStorage.storageCache[AppStorage.EXCHANGE_RATES]);
cur = JSON.parse(await AsyncStorage.getItem(AppStorage.EXCHANGE_RATES));
assert.ok(cur['BTC_JPY'] > 0);

// now setting with a proper setter
await currency.setPrefferedCurrency(FiatUnit.EUR);
await currency.startUpdater();
let preferred = await currency.getPreferredCurrency();
assert.strictEqual(preferred.endPointKey, 'EUR');
cur = JSON.parse(AsyncStorage.storageCache[AppStorage.EXCHANGE_RATES]);
cur = JSON.parse(await AsyncStorage.getItem(AppStorage.EXCHANGE_RATES));
assert.ok(cur['BTC_EUR'] > 0);
});
});
2 changes: 1 addition & 1 deletion BlueApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let A = require('./analytics');
let BlueElectrum = require('./BlueElectrum'); // eslint-disable-line

/** @type {AppStorage} */
let BlueApp = new AppStorage();
const BlueApp = new AppStorage();

async function startAndDecrypt(retry) {
console.log('startAndDecrypt');
Expand Down
61 changes: 20 additions & 41 deletions BlueComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import LinearGradient from 'react-native-linear-gradient';
import { LightningCustodianWallet } from './class';
import Carousel from 'react-native-snap-carousel';
import DeviceInfo from 'react-native-device-info';
import { BitcoinUnit } from './models/bitcoinUnits';
import NavigationService from './NavigationService';
import ImagePicker from 'react-native-image-picker';
Expand All @@ -36,6 +35,7 @@ let loc = require('./loc/');
let BlueApp = require('./BlueApp');
const { height, width } = Dimensions.get('window');
const aspectRatio = height / width;
const BigNumber = require('bignumber.js');
let isIpad;
if (aspectRatio > 1.6) {
isIpad = false;
Expand Down Expand Up @@ -241,6 +241,14 @@ export class BlueCopyTextToClipboard extends Component {
this.state = { hasTappedText: false, address: props.text };
}

static getDerivedStateFromProps(props, state) {
if (state.hasTappedText) {
return { hasTappedText: state.hasTappedText, address: state.address };
} else {
return { hasTappedText: state.hasTappedText, address: props.text };
}
}

copyToClipboard = () => {
this.setState({ hasTappedText: true }, () => {
Clipboard.setString(this.props.text);
Expand Down Expand Up @@ -404,29 +412,6 @@ export class BlueFormMultiInput extends Component {
}
}

export class BlueFormInputAddress extends Component {
render() {
return (
<FormInput
{...this.props}
inputStyle={{
maxWidth: width - 110,
color: BlueApp.settings.foregroundColor,
fontSize: (isIpad && 10) || ((is.iphone8() && 12) || 14),
}}
containerStyle={{
marginTop: 5,
borderColor: BlueApp.settings.inputBorderColor,
borderBottomColor: BlueApp.settings.inputBorderColor,
borderWidth: 0.5,
borderBottomWidth: 0.5,
backgroundColor: BlueApp.settings.inputBackgroundColor,
}}
/>
);
}
}

export class BlueHeader extends Component {
render() {
return (
Expand Down Expand Up @@ -560,13 +545,6 @@ export class is {
static ipad() {
return isIpad;
}

static iphone8() {
if (Platform.OS !== 'ios') {
return false;
}
return DeviceInfo.getDeviceId() === 'iPhone10,4';
}
}

export class BlueSpacing20 extends Component {
Expand Down Expand Up @@ -1733,7 +1711,7 @@ export class BlueAddressInput extends Component {
export class BlueBitcoinAmount extends Component {
static propTypes = {
isLoading: PropTypes.bool,
amount: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
amount: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
onChangeText: PropTypes.func,
disabled: PropTypes.bool,
unit: PropTypes.string,
Expand All @@ -1744,8 +1722,15 @@ export class BlueBitcoinAmount extends Component {
};

render() {
const amount = typeof this.props.amount === 'number' ? this.props.amount.toString() : this.props.amount;

const amount = this.props.amount || 0;
let localCurrency = loc.formatBalanceWithoutSuffix(amount, BitcoinUnit.LOCAL_CURRENCY, false);
if (this.props.unit === BitcoinUnit.BTC) {
let sat = new BigNumber(amount);
sat = sat.multipliedBy(100000000).toString();
localCurrency = loc.formatBalanceWithoutSuffix(sat, BitcoinUnit.LOCAL_CURRENCY, false);
} else {
localCurrency = loc.formatBalanceWithoutSuffix(amount.toString(), BitcoinUnit.LOCAL_CURRENCY, false);
}
return (
<TouchableWithoutFeedback disabled={this.props.pointerEvents === 'none'} onPress={() => this.textInput.focus()}>
<View>
Expand Down Expand Up @@ -1788,13 +1773,7 @@ export class BlueBitcoinAmount extends Component {
</Text>
</View>
<View style={{ alignItems: 'center', marginBottom: 22, marginTop: 4 }}>
<Text style={{ fontSize: 18, color: '#d4d4d4', fontWeight: '600' }}>
{loc.formatBalance(
this.props.unit === BitcoinUnit.BTC ? amount || 0 : loc.formatBalanceWithoutSuffix(amount || 0, BitcoinUnit.BTC, false),
BitcoinUnit.LOCAL_CURRENCY,
false,
)}
</Text>
<Text style={{ fontSize: 18, color: '#d4d4d4', fontWeight: '600' }}>{localCurrency}</Text>
</View>
</View>
</TouchableWithoutFeedback>
Expand Down
8 changes: 4 additions & 4 deletions BlueElectrum.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AsyncStorage } from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
const ElectrumClient = require('electrum-client');
let bitcoin = require('bitcoinjs-lib');
let reverse = require('buffer-reverse');

const storageKey = 'ELECTRUM_PEERS';
const defaultPeer = { host: 'electrum1.bluewallet.io', tcp: 50001 };
const defaultPeer = { host: 'electrum1.bluewallet.io', tcp: '50001' };
const hardcodedPeers = [
// { host: 'noveltybobble.coinjoined.com', tcp: '50001' }, // down
// { host: 'electrum.be', tcp: '50001' },
Expand Down Expand Up @@ -170,8 +170,8 @@ async function waitTillConnected() {
async function estimateFees() {
if (!mainClient) throw new Error('Electrum client is not connected');
const fast = await mainClient.blockchainEstimatefee(1);
const medium = await mainClient.blockchainEstimatefee(6);
const slow = await mainClient.blockchainEstimatefee(12);
const medium = await mainClient.blockchainEstimatefee(5);
const slow = await mainClient.blockchainEstimatefee(10);
return { fast, medium, slow };
}

Expand Down
5 changes: 2 additions & 3 deletions Electrum.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ beforeAll(async () => {
// while app starts up, but for tests we need to wait for it
try {
await BlueElectrum.waitTillConnected();
} catch (Err) {
console.log('failed to connect to Electrum:', Err);
} catch (err) {
console.log('failed to connect to Electrum:', err);
process.exit(1);
}
});
Expand Down Expand Up @@ -52,7 +52,6 @@ describe('Electrum', () => {
hash = bitcoin.crypto.sha256(script);
reversedHash = Buffer.from(hash.reverse());
balance = await mainClient.blockchainScripthash_getBalance(reversedHash.toString('hex'));
assert.ok(balance.confirmed === 51432);

// let peers = await mainClient.serverPeers_subscribe();
// console.log(peers);
Expand Down
2 changes: 1 addition & 1 deletion HDWallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ it('Segwit HD (BIP49) can fetch balance with many used addresses in hierarchy',
let end = +new Date();
const took = (end - start) / 1000;
took > 15 && console.warn('took', took, "sec to fetch huge HD wallet's balance");
assert.strictEqual(hd.getBalance(), 0.00051432);
assert.strictEqual(hd.getBalance(), 51432);

await hd.fetchUtxo();
assert.ok(hd.utxo.length > 0);
Expand Down
Loading

0 comments on commit 33bffaa

Please sign in to comment.