mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-22 23:08:07 +01:00
ADD: Default into wallet
This commit is contained in:
parent
68bb940a39
commit
e3a640cb59
8 changed files with 170 additions and 5 deletions
|
@ -10,6 +10,8 @@ import EncryptStorage from './screen/settings/encryptStorage';
|
||||||
import PlausibleDeniability from './screen/plausibledeniability';
|
import PlausibleDeniability from './screen/plausibledeniability';
|
||||||
import LightningSettings from './screen/settings/lightningSettings';
|
import LightningSettings from './screen/settings/lightningSettings';
|
||||||
import ElectrumSettings from './screen/settings/electrumSettings';
|
import ElectrumSettings from './screen/settings/electrumSettings';
|
||||||
|
import DefaultView from './screen/settings/defaultView';
|
||||||
|
|
||||||
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';
|
||||||
|
@ -98,6 +100,9 @@ const WalletsStackNavigator = createStackNavigator(
|
||||||
headerTintColor: '#0c2550',
|
headerTintColor: '#0c2550',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
SelectWallet: {
|
||||||
|
screen: SelectWallet,
|
||||||
|
},
|
||||||
Currency: {
|
Currency: {
|
||||||
screen: Currency,
|
screen: Currency,
|
||||||
},
|
},
|
||||||
|
@ -112,6 +117,10 @@ const WalletsStackNavigator = createStackNavigator(
|
||||||
Selftest: {
|
Selftest: {
|
||||||
screen: Selftest,
|
screen: Selftest,
|
||||||
},
|
},
|
||||||
|
DefaultView: {
|
||||||
|
screen: DefaultView,
|
||||||
|
path: 'DefaultView',
|
||||||
|
},
|
||||||
Language: {
|
Language: {
|
||||||
screen: Language,
|
screen: Language,
|
||||||
path: 'Language',
|
path: 'Language',
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { BitcoinUnit, Chain } from '../models/bitcoinUnits';
|
import { BitcoinUnit, Chain } from '../models/bitcoinUnits';
|
||||||
|
const createHash = require('create-hash');
|
||||||
export class AbstractWallet {
|
export class AbstractWallet {
|
||||||
static type = 'abstract';
|
static type = 'abstract';
|
||||||
static typeReadable = 'abstract';
|
static typeReadable = 'abstract';
|
||||||
|
@ -31,6 +31,13 @@ export class AbstractWallet {
|
||||||
this.hideBalance = false;
|
this.hideBalance = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getID() {
|
||||||
|
return createHash('sha256')
|
||||||
|
.update(this.getSecret())
|
||||||
|
.digest()
|
||||||
|
.toString('hex');
|
||||||
|
}
|
||||||
|
|
||||||
getTransactions() {
|
getTransactions() {
|
||||||
return this.transactions;
|
return this.transactions;
|
||||||
}
|
}
|
||||||
|
|
56
class/onAppLaunch.js
Normal file
56
class/onAppLaunch.js
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
import AsyncStorage from '@react-native-community/async-storage';
|
||||||
|
const BlueApp = require('../BlueApp');
|
||||||
|
|
||||||
|
export default class OnAppLaunch {
|
||||||
|
static StorageKey = 'OnAppLaunchKey';
|
||||||
|
static EnabledKey = 'OnAppLaunchEnabledKey';
|
||||||
|
|
||||||
|
static async isViewAllWalletsEnabled() {
|
||||||
|
let isEnabled = '1';
|
||||||
|
try {
|
||||||
|
const enabled = await AsyncStorage.getItem(OnAppLaunch.EnabledKey);
|
||||||
|
isEnabled = enabled;
|
||||||
|
if (!isEnabled) {
|
||||||
|
const selectedDefaultWallet = await OnAppLaunch.getSelectedDefaultWallet();
|
||||||
|
if (!selectedDefaultWallet) {
|
||||||
|
isEnabled = '1';
|
||||||
|
await AsyncStorage.setItem(OnAppLaunch.EnabledKey, isEnabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
isEnabled = '1';
|
||||||
|
await AsyncStorage.setItem(OnAppLaunch.EnabledKey, isEnabled);
|
||||||
|
}
|
||||||
|
return !!isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async setViewAllWalletsEnabled(value) {
|
||||||
|
if (!value) {
|
||||||
|
const selectedDefaultWallet = await OnAppLaunch.getSelectedDefaultWallet();
|
||||||
|
if (!selectedDefaultWallet) {
|
||||||
|
const firstWallet = BlueApp.getWallets()[0];
|
||||||
|
await OnAppLaunch.setSelectedDefaultWallet(firstWallet.getID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await AsyncStorage.setItem(OnAppLaunch.EnabledKey, value === false ? '' : '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getSelectedDefaultWallet() {
|
||||||
|
let selectedWallet = false;
|
||||||
|
try {
|
||||||
|
const selectedWalletID = JSON.parse(await AsyncStorage.getItem(OnAppLaunch.StorageKey));
|
||||||
|
selectedWallet = BlueApp.getWallets().find(wallet => wallet.getID() === selectedWalletID);
|
||||||
|
if (!selectedWallet) {
|
||||||
|
await AsyncStorage.setItem(OnAppLaunch.EnabledKey, '');
|
||||||
|
await AsyncStorage.removeItem(OnAppLaunch.StorageKey);
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return selectedWallet;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async setSelectedDefaultWallet(value) {
|
||||||
|
await AsyncStorage.setItem(OnAppLaunch.StorageKey, JSON.stringify(value));
|
||||||
|
}
|
||||||
|
}
|
80
screen/settings/defaultView.js
Normal file
80
screen/settings/defaultView.js
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { TouchableOpacity, View } from 'react-native';
|
||||||
|
import { SafeBlueArea, BlueNavigationStyle, BlueListItem } from '../../BlueComponents';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import OnAppLaunch from '../../class/onAppLaunch';
|
||||||
|
const BlueApp = require('../../BlueApp');
|
||||||
|
|
||||||
|
export default class DefaultView extends Component {
|
||||||
|
static navigationOptions = () => ({
|
||||||
|
...BlueNavigationStyle(),
|
||||||
|
title: 'On Launch',
|
||||||
|
});
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = { defaultWalletLabel: '', viewAllWalletsEnabled: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentDidMount() {
|
||||||
|
const viewAllWalletsEnabled = await OnAppLaunch.isViewAllWalletsEnabled();
|
||||||
|
let defaultWalletLabel = '';
|
||||||
|
const wallet = await OnAppLaunch.getSelectedDefaultWallet();
|
||||||
|
if (wallet) {
|
||||||
|
defaultWalletLabel = wallet.getLabel();
|
||||||
|
}
|
||||||
|
this.setState({ viewAllWalletsEnabled, defaultWalletLabel });
|
||||||
|
}
|
||||||
|
|
||||||
|
selectWallet = () => {
|
||||||
|
this.props.navigation.navigate('SelectWallet', { onWalletSelect: this.onWalletSelectValueChanged });
|
||||||
|
};
|
||||||
|
|
||||||
|
onViewAllWalletsSwitchValueChanged = async value => {
|
||||||
|
await OnAppLaunch.setViewAllWalletsEnabled(value);
|
||||||
|
if (value) {
|
||||||
|
return this.setState({ viewAllWalletsEnabled: true, defaultWalletLabel: '' });
|
||||||
|
} else {
|
||||||
|
const selectedWallet = await OnAppLaunch.getSelectedDefaultWallet();
|
||||||
|
return this.setState({ viewAllWalletsEnabled: false, defaultWalletLabel: selectedWallet.getLabel() });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onWalletSelectValueChanged = async wallet => {
|
||||||
|
await OnAppLaunch.setViewAllWalletsEnabled(false);
|
||||||
|
await OnAppLaunch.setSelectedDefaultWallet(wallet.getID());
|
||||||
|
this.setState({ defaultWalletLabel: wallet.getLabel(), viewAllWalletsEnabled: false }, () => this.props.navigation.pop());
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
|
||||||
|
<View>
|
||||||
|
<BlueListItem
|
||||||
|
title="View All Wallets"
|
||||||
|
hideChevron
|
||||||
|
switchButton
|
||||||
|
swithchEnabled={BlueApp.getWallets().length > 0}
|
||||||
|
switched={this.state.viewAllWalletsEnabled}
|
||||||
|
onSwitch={this.onViewAllWalletsSwitchValueChanged}
|
||||||
|
/>
|
||||||
|
{!this.state.viewAllWalletsEnabled && (
|
||||||
|
<BlueListItem
|
||||||
|
title="Default into"
|
||||||
|
component={TouchableOpacity}
|
||||||
|
onPress={this.selectWallet}
|
||||||
|
rightTitle={this.state.defaultWalletLabel}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</SafeBlueArea>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DefaultView.propTypes = {
|
||||||
|
navigation: PropTypes.shape({
|
||||||
|
navigate: PropTypes.func,
|
||||||
|
pop: PropTypes.func,
|
||||||
|
}),
|
||||||
|
};
|
|
@ -68,6 +68,7 @@ export default class Settings extends Component {
|
||||||
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
|
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
|
||||||
<BlueHeaderDefaultSub leftText={loc.settings.header} rightComponent={null} />
|
<BlueHeaderDefaultSub leftText={loc.settings.header} rightComponent={null} />
|
||||||
<ScrollView maxHeight={450}>
|
<ScrollView maxHeight={450}>
|
||||||
|
<BlueListItem component={TouchableOpacity} onPress={() => this.props.navigation.navigate('DefaultView')} title="On Launch" />
|
||||||
<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>
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { NavigationEvents } from 'react-navigation';
|
||||||
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import WalletGradient from '../../class/walletGradient';
|
import WalletGradient from '../../class/walletGradient';
|
||||||
|
import OnAppLaunch from '../../class/onAppLaunch';
|
||||||
let EV = require('../../events');
|
let EV = require('../../events');
|
||||||
let A = require('../../analytics');
|
let A = require('../../analytics');
|
||||||
/** @type {AppStorage} */
|
/** @type {AppStorage} */
|
||||||
|
@ -47,10 +48,16 @@ export default class WalletsList extends Component {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.redrawScreen();
|
this.redrawScreen();
|
||||||
|
|
||||||
// the idea is that upon wallet launch we will refresh
|
// the idea is that upon wallet launch we will refresh
|
||||||
// all balances and all transactions here:
|
// all balances and all transactions here:
|
||||||
InteractionManager.runAfterInteractions(async () => {
|
InteractionManager.runAfterInteractions(async () => {
|
||||||
|
const isViewAllWalletsEnabled = await OnAppLaunch.isViewAllWalletsEnabled();
|
||||||
|
if (!isViewAllWalletsEnabled) {
|
||||||
|
const selectedDefaultWallet = await OnAppLaunch.getSelectedDefaultWallet();
|
||||||
|
const walletIndex = this.state.wallets.findIndex(wallet => wallet.getID() === selectedDefaultWallet.getID());
|
||||||
|
this.handleClick(walletIndex);
|
||||||
|
}
|
||||||
|
|
||||||
let noErr = true;
|
let noErr = true;
|
||||||
try {
|
try {
|
||||||
await BlueElectrum.waitTillConnected();
|
await BlueElectrum.waitTillConnected();
|
||||||
|
|
|
@ -6,6 +6,7 @@ import PropTypes from 'prop-types';
|
||||||
import { LightningCustodianWallet } from '../../class/lightning-custodian-wallet';
|
import { LightningCustodianWallet } from '../../class/lightning-custodian-wallet';
|
||||||
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
||||||
import WalletGradient from '../../class/walletGradient';
|
import WalletGradient from '../../class/walletGradient';
|
||||||
|
import { Chain } from '../../models/bitcoinUnits';
|
||||||
/** @type {AppStorage} */
|
/** @type {AppStorage} */
|
||||||
let BlueApp = require('../../BlueApp');
|
let BlueApp = require('../../BlueApp');
|
||||||
let loc = require('../../loc');
|
let loc = require('../../loc');
|
||||||
|
@ -23,6 +24,7 @@ export default class SelectWallet extends Component {
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
data: [],
|
data: [],
|
||||||
};
|
};
|
||||||
|
this.chainType = props.navigation.getParam('chainType');
|
||||||
}
|
}
|
||||||
|
|
||||||
dismissComponent = () => {
|
dismissComponent = () => {
|
||||||
|
@ -30,7 +32,9 @@ export default class SelectWallet extends Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const wallets = BlueApp.getWallets().filter(item => item.chain === this.props.navigation.getParam('chainType') && item.allowSend());
|
const wallets = this.chainType
|
||||||
|
? BlueApp.getWallets().filter(item => item.chain === this.chainType && item.allowSend())
|
||||||
|
: BlueApp.getWallets();
|
||||||
this.setState({
|
this.setState({
|
||||||
data: wallets,
|
data: wallets,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
@ -165,6 +169,7 @@ export default class SelectWallet extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectWallet.propTypes = {
|
SelectWallet.propTypes = {
|
||||||
|
chainType: PropTypes.string,
|
||||||
navigation: PropTypes.shape({
|
navigation: PropTypes.shape({
|
||||||
navigate: PropTypes.func,
|
navigate: PropTypes.func,
|
||||||
goBack: PropTypes.func,
|
goBack: PropTypes.func,
|
||||||
|
|
|
@ -39,7 +39,7 @@ let BlueElectrum = require('../../BlueElectrum');
|
||||||
|
|
||||||
export default class WalletTransactions extends Component {
|
export default class WalletTransactions extends Component {
|
||||||
static navigationOptions = ({ navigation }) => {
|
static navigationOptions = ({ navigation }) => {
|
||||||
return {
|
return ({
|
||||||
headerRight: (
|
headerRight: (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
disabled={navigation.getParam('isLoading') === true}
|
disabled={navigation.getParam('isLoading') === true}
|
||||||
|
@ -60,7 +60,7 @@ export default class WalletTransactions extends Component {
|
||||||
shadowRadius: 0,
|
shadowRadius: 0,
|
||||||
},
|
},
|
||||||
headerTintColor: '#FFFFFF',
|
headerTintColor: '#FFFFFF',
|
||||||
};
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
walletBalanceText = null;
|
walletBalanceText = null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue