2019-12-25 17:25:30 +01:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2020-07-15 19:32:59 +02:00
|
|
|
import { View, TouchableWithoutFeedback, StyleSheet } from 'react-native';
|
|
|
|
import { SafeBlueArea, BlueCard, BlueNavigationStyle, BlueListItemHooks, BlueTextHooks } from '../../BlueComponents';
|
2020-05-24 12:27:08 +02:00
|
|
|
import OnAppLaunch from '../../class/on-app-launch';
|
2020-05-27 13:12:17 +02:00
|
|
|
import { useNavigation } from '@react-navigation/native';
|
2019-10-03 05:06:47 +02:00
|
|
|
const BlueApp = require('../../BlueApp');
|
|
|
|
|
2020-05-24 11:17:26 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
flex: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-12-25 17:25:30 +01:00
|
|
|
const DefaultView = () => {
|
|
|
|
const [defaultWalletLabel, setDefaultWalletLabel] = useState('');
|
|
|
|
const [viewAllWalletsEnabled, setViewAllWalletsEnabled] = useState(true);
|
|
|
|
const { navigate, pop } = useNavigation();
|
2019-10-03 05:06:47 +02:00
|
|
|
|
2019-12-25 17:25:30 +01:00
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
const viewAllWalletsEnabled = await OnAppLaunch.isViewAllWalletsEnabled();
|
|
|
|
let defaultWalletLabel = '';
|
|
|
|
const wallet = await OnAppLaunch.getSelectedDefaultWallet();
|
|
|
|
if (wallet) {
|
|
|
|
defaultWalletLabel = wallet.getLabel();
|
|
|
|
}
|
|
|
|
setDefaultWalletLabel(defaultWalletLabel);
|
|
|
|
setViewAllWalletsEnabled(viewAllWalletsEnabled);
|
|
|
|
})();
|
|
|
|
});
|
2019-10-03 05:06:47 +02:00
|
|
|
|
2019-12-25 17:25:30 +01:00
|
|
|
const onViewAllWalletsSwitchValueChanged = async value => {
|
2019-10-03 05:06:47 +02:00
|
|
|
await OnAppLaunch.setViewAllWalletsEnabled(value);
|
|
|
|
if (value) {
|
2019-12-25 17:25:30 +01:00
|
|
|
setViewAllWalletsEnabled(true);
|
|
|
|
setDefaultWalletLabel('');
|
2019-10-03 05:06:47 +02:00
|
|
|
} else {
|
|
|
|
const selectedWallet = await OnAppLaunch.getSelectedDefaultWallet();
|
2019-12-25 17:25:30 +01:00
|
|
|
setDefaultWalletLabel(selectedWallet.getLabel());
|
|
|
|
setViewAllWalletsEnabled(false);
|
2019-10-03 05:06:47 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-25 17:25:30 +01:00
|
|
|
const selectWallet = () => {
|
|
|
|
navigate('SelectWallet', { onWalletSelect: onWalletSelectValueChanged });
|
|
|
|
};
|
|
|
|
|
|
|
|
const onWalletSelectValueChanged = async wallet => {
|
2019-10-03 05:06:47 +02:00
|
|
|
await OnAppLaunch.setViewAllWalletsEnabled(false);
|
|
|
|
await OnAppLaunch.setSelectedDefaultWallet(wallet.getID());
|
2019-12-25 17:25:30 +01:00
|
|
|
setDefaultWalletLabel(wallet.getLabel());
|
|
|
|
setViewAllWalletsEnabled(false);
|
|
|
|
pop();
|
2019-10-03 05:06:47 +02:00
|
|
|
};
|
|
|
|
|
2019-12-25 17:25:30 +01:00
|
|
|
return (
|
2020-05-24 11:17:26 +02:00
|
|
|
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={styles.flex}>
|
2019-12-25 17:25:30 +01:00
|
|
|
<View>
|
2020-07-15 19:32:59 +02:00
|
|
|
<BlueListItemHooks
|
2019-12-25 17:25:30 +01:00
|
|
|
title="View All Wallets"
|
2020-05-03 20:17:49 +02:00
|
|
|
Component={TouchableWithoutFeedback}
|
|
|
|
switch={{
|
|
|
|
onValueChange: onViewAllWalletsSwitchValueChanged,
|
|
|
|
value: viewAllWalletsEnabled,
|
|
|
|
disabled: BlueApp.getWallets().length <= 0,
|
|
|
|
}}
|
2019-12-25 17:25:30 +01:00
|
|
|
/>
|
2020-03-30 04:50:18 +02:00
|
|
|
<BlueCard>
|
2020-07-15 19:32:59 +02:00
|
|
|
<BlueTextHooks>When disabled, BlueWallet will immediately open the selected wallet at launch.</BlueTextHooks>
|
2020-03-30 04:50:18 +02:00
|
|
|
</BlueCard>
|
2019-12-25 17:25:30 +01:00
|
|
|
{!viewAllWalletsEnabled && (
|
2020-07-15 19:32:59 +02:00
|
|
|
<BlueListItemHooks title="Default into" onPress={selectWallet} rightTitle={defaultWalletLabel} chevron />
|
2019-12-25 17:25:30 +01:00
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
2019-10-03 05:06:47 +02:00
|
|
|
};
|
2019-12-25 17:25:30 +01:00
|
|
|
|
|
|
|
DefaultView.navigationOptions = () => ({
|
|
|
|
...BlueNavigationStyle(),
|
|
|
|
title: 'On Launch',
|
|
|
|
});
|
|
|
|
|
|
|
|
export default DefaultView;
|