mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-21 14:34:55 +01:00
ADD: blitzhub api URI settings
This commit is contained in:
parent
4e3d9ed8e1
commit
dc75511997
6 changed files with 154 additions and 5 deletions
|
@ -5,6 +5,7 @@ import About from './screen/settings/about';
|
||||||
import Selftest from './screen/selftest';
|
import Selftest from './screen/selftest';
|
||||||
import Language from './screen/settings/language';
|
import Language from './screen/settings/language';
|
||||||
import EncryptStorage from './screen/settings/encryptStorage';
|
import EncryptStorage from './screen/settings/encryptStorage';
|
||||||
|
import LightningSettings from './screen/settings/lightningSettings';
|
||||||
import WalletsList from './screen/wallets/list';
|
import WalletsList from './screen/wallets/list';
|
||||||
import WalletTransactions from './screen/wallets/transactions';
|
import WalletTransactions from './screen/wallets/transactions';
|
||||||
import AddWallet from './screen/wallets/add';
|
import AddWallet from './screen/wallets/add';
|
||||||
|
@ -75,6 +76,10 @@ const WalletsStackNavigator = createStackNavigator({
|
||||||
screen: EncryptStorage,
|
screen: EncryptStorage,
|
||||||
path: 'EncryptStorage',
|
path: 'EncryptStorage',
|
||||||
},
|
},
|
||||||
|
LightningSettings: {
|
||||||
|
screen: LightningSettings,
|
||||||
|
path: 'LightningSettings',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const CreateTransactionStackNavigator = createStackNavigator({
|
const CreateTransactionStackNavigator = createStackNavigator({
|
||||||
|
|
|
@ -16,6 +16,7 @@ export class AppStorage {
|
||||||
static LANG = 'lang';
|
static LANG = 'lang';
|
||||||
static CURRENCY = 'currency';
|
static CURRENCY = 'currency';
|
||||||
static ENTROPY = 'entropy';
|
static ENTROPY = 'entropy';
|
||||||
|
static BLITZHUB = 'blitzhub';
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
/** {Array.<AbstractWallet>} */
|
/** {Array.<AbstractWallet>} */
|
||||||
|
@ -150,7 +151,18 @@ export class AppStorage {
|
||||||
unserializedWallet = HDLegacyBreadwalletWallet.fromJson(key);
|
unserializedWallet = HDLegacyBreadwalletWallet.fromJson(key);
|
||||||
break;
|
break;
|
||||||
case new LightningCustodianWallet().type:
|
case new LightningCustodianWallet().type:
|
||||||
|
/** @type {LightningCustodianWallet} */
|
||||||
unserializedWallet = LightningCustodianWallet.fromJson(key);
|
unserializedWallet = LightningCustodianWallet.fromJson(key);
|
||||||
|
let blitzhub = false;
|
||||||
|
try {
|
||||||
|
blitzhub = await AsyncStorage.getItem(AppStorage.BLITZHUB);
|
||||||
|
} catch (Error) {
|
||||||
|
console.warn(Error);
|
||||||
|
}
|
||||||
|
if (blitzhub) {
|
||||||
|
unserializedWallet.setBaseURI(blitzhub);
|
||||||
|
unserializedWallet.init();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'legacy':
|
case 'legacy':
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -5,6 +5,7 @@ let BigNumber = require('bignumber.js');
|
||||||
export class LightningCustodianWallet extends LegacyWallet {
|
export class LightningCustodianWallet extends LegacyWallet {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
this.baseURI = 'https://api.blitzhub.io/';
|
||||||
this.init();
|
this.init();
|
||||||
this.type = 'lightningCustodianWallet';
|
this.type = 'lightningCustodianWallet';
|
||||||
this.refresh_token = '';
|
this.refresh_token = '';
|
||||||
|
@ -16,6 +17,23 @@ export class LightningCustodianWallet extends LegacyWallet {
|
||||||
this.info_raw = false;
|
this.info_raw = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* requires calling init() after setting
|
||||||
|
*
|
||||||
|
* @param URI
|
||||||
|
*/
|
||||||
|
setBaseURI(URI) {
|
||||||
|
if (URI) {
|
||||||
|
this.baseURI = URI;
|
||||||
|
} else {
|
||||||
|
this.baseURI = 'https://api.blitzhub.io/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getBaseURI() {
|
||||||
|
return this.baseURI;
|
||||||
|
}
|
||||||
|
|
||||||
allowSend() {
|
allowSend() {
|
||||||
console.log(this.getBalance(), this.getBalance() > 0);
|
console.log(this.getBalance(), this.getBalance() > 0);
|
||||||
return this.getBalance() > 0;
|
return this.getBalance() > 0;
|
||||||
|
@ -43,7 +61,7 @@ export class LightningCustodianWallet extends LegacyWallet {
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this._api = new Frisbee({
|
this._api = new Frisbee({
|
||||||
baseURI: 'https://api.blitzhub.io/',
|
baseURI: this.baseURI,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
100
screen/settings/lightningSettings.js
Normal file
100
screen/settings/lightningSettings.js
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { AsyncStorage, View, TextInput } from 'react-native';
|
||||||
|
import { AppStorage } from '../../class';
|
||||||
|
import { BlueLoading, BlueSpacing20, BlueButton, SafeBlueArea, BlueCard, BlueNavigationStyle, BlueSpacing40 } from '../../BlueComponents';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { LightningCustodianWallet } from '../../class/lightning-custodian-wallet';
|
||||||
|
/** @type {AppStorage} */
|
||||||
|
let BlueApp = require('../../BlueApp');
|
||||||
|
|
||||||
|
export default class LightningSettings extends Component {
|
||||||
|
static navigationOptions = () => ({
|
||||||
|
...BlueNavigationStyle(),
|
||||||
|
title: 'Lightning Settings',
|
||||||
|
});
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
isLoading: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentDidMount() {
|
||||||
|
let URI = await AsyncStorage.getItem(AppStorage.BLITZHUB);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
isLoading: false,
|
||||||
|
URI,
|
||||||
|
defaultURI: new LightningCustodianWallet().getBaseURI(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async save() {
|
||||||
|
this.state.URI = this.state.URI ? this.state.URI : '';
|
||||||
|
await AsyncStorage.setItem(AppStorage.BLITZHUB, this.state.URI);
|
||||||
|
|
||||||
|
// set each lnd wallets and re-init api
|
||||||
|
for (/** @type {LightningCustodianWallet} */ let w of BlueApp.getWallets()) {
|
||||||
|
if (w.type === new LightningCustodianWallet().type) {
|
||||||
|
w.setBaseURI(this.state.URI);
|
||||||
|
w.init();
|
||||||
|
console.log('inited');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
if (this.state.isLoading) {
|
||||||
|
return <BlueLoading />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
|
||||||
|
<BlueCard>
|
||||||
|
<BlueSpacing40 />
|
||||||
|
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flexDirection: 'row',
|
||||||
|
borderColor: '#d2d2d2',
|
||||||
|
borderBottomColor: '#d2d2d2',
|
||||||
|
borderWidth: 1.0,
|
||||||
|
borderBottomWidth: 0.5,
|
||||||
|
backgroundColor: '#f5f5f5',
|
||||||
|
minHeight: 44,
|
||||||
|
height: 44,
|
||||||
|
alignItems: 'center',
|
||||||
|
borderRadius: 4,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TextInput
|
||||||
|
placeholder={this.state.defaultURI}
|
||||||
|
value={this.state.URI}
|
||||||
|
onChangeText={text => this.setState({ URI: text })}
|
||||||
|
numberOfLines={1}
|
||||||
|
style={{ flex: 1, marginHorizontal: 8, minHeight: 33, height: 33 }}
|
||||||
|
editable={!this.state.isLoading}
|
||||||
|
underlineColorAndroid="transparent"
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<BlueSpacing20 />
|
||||||
|
<BlueButton
|
||||||
|
onPress={() => {
|
||||||
|
this.save();
|
||||||
|
}}
|
||||||
|
title={'Save'}
|
||||||
|
/>
|
||||||
|
</BlueCard>
|
||||||
|
</SafeBlueArea>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LightningSettings.propTypes = {
|
||||||
|
navigation: PropTypes.shape({
|
||||||
|
navigate: PropTypes.func,
|
||||||
|
goBack: PropTypes.func,
|
||||||
|
}),
|
||||||
|
};
|
|
@ -38,6 +38,9 @@ export default class Settings extends Component {
|
||||||
<TouchableOpacity onPress={() => this.props.navigation.navigate('EncryptStorage')}>
|
<TouchableOpacity onPress={() => this.props.navigation.navigate('EncryptStorage')}>
|
||||||
<BlueListItem title={loc.settings.encrypt_storage} />
|
<BlueListItem title={loc.settings.encrypt_storage} />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
<TouchableOpacity onPress={() => this.props.navigation.navigate('LightningSettings')}>
|
||||||
|
<BlueListItem title="Lightning settings" />
|
||||||
|
</TouchableOpacity>
|
||||||
<TouchableOpacity onPress={() => this.props.navigation.navigate('Language')}>
|
<TouchableOpacity onPress={() => this.props.navigation.navigate('Language')}>
|
||||||
<BlueListItem title={loc.settings.language} />
|
<BlueListItem title={loc.settings.language} />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
/* global alert */
|
/* global alert */
|
||||||
import { SegwitP2SHWallet } from '../../class';
|
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { ActivityIndicator, Dimensions, View, TextInput } from 'react-native';
|
import { AsyncStorage, ActivityIndicator, Dimensions, View, TextInput } from 'react-native';
|
||||||
import {
|
import {
|
||||||
BlueTextCentered,
|
BlueTextCentered,
|
||||||
BlueText,
|
BlueText,
|
||||||
|
@ -19,6 +18,7 @@ import { RadioGroup, RadioButton } from 'react-native-flexi-radio-button';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { HDSegwitP2SHWallet } from '../../class/hd-segwit-p2sh-wallet';
|
import { HDSegwitP2SHWallet } from '../../class/hd-segwit-p2sh-wallet';
|
||||||
import { LightningCustodianWallet } from '../../class/lightning-custodian-wallet';
|
import { LightningCustodianWallet } from '../../class/lightning-custodian-wallet';
|
||||||
|
import { AppStorage, SegwitP2SHWallet } from '../../class';
|
||||||
const entropy = require('../../entropy');
|
const entropy = require('../../entropy');
|
||||||
let EV = require('../../events');
|
let EV = require('../../events');
|
||||||
let A = require('../../analytics');
|
let A = require('../../analytics');
|
||||||
|
@ -203,8 +203,19 @@ export default class WalletsAdd extends Component {
|
||||||
|
|
||||||
w = new LightningCustodianWallet();
|
w = new LightningCustodianWallet();
|
||||||
w.setLabel(this.state.label || w.getTypeReadable());
|
w.setLabel(this.state.label || w.getTypeReadable());
|
||||||
await w.createAccount();
|
|
||||||
await w.authorize();
|
try {
|
||||||
|
let blitzhub = await AsyncStorage.getItem(AppStorage.BLITZHUB);
|
||||||
|
if (blitzhub) {
|
||||||
|
w.setBaseURI(blitzhub);
|
||||||
|
w.init();
|
||||||
|
}
|
||||||
|
await w.createAccount();
|
||||||
|
await w.authorize();
|
||||||
|
} catch (Err) {
|
||||||
|
console.warn('lnd create failure', Err);
|
||||||
|
return; // giving app, not adding anything
|
||||||
|
}
|
||||||
A(A.ENUM.CREATED_LIGHTNING_WALLET);
|
A(A.ENUM.CREATED_LIGHTNING_WALLET);
|
||||||
} else if (this.state.selectedIndex === 1) {
|
} else if (this.state.selectedIndex === 1) {
|
||||||
// btc was selected
|
// btc was selected
|
||||||
|
|
Loading…
Add table
Reference in a new issue