BlueWallet/screen/settings/defaultView.js

79 lines
2.7 KiB
JavaScript
Raw Normal View History

import React, { useEffect, useState } from 'react';
2020-05-03 20:17:49 +02:00
import { TouchableOpacity, View, TouchableWithoutFeedback } from 'react-native';
import { SafeBlueArea, BlueCard, BlueText, BlueNavigationStyle, BlueListItem } from '../../BlueComponents';
2019-10-03 05:06:47 +02:00
import OnAppLaunch from '../../class/onAppLaunch';
import { useNavigation } from 'react-navigation-hooks';
2019-10-03 05:06:47 +02:00
const BlueApp = require('../../BlueApp');
const DefaultView = () => {
const [defaultWalletLabel, setDefaultWalletLabel] = useState('');
const [viewAllWalletsEnabled, setViewAllWalletsEnabled] = useState(true);
const { navigate, pop } = useNavigation();
2019-10-03 05:06:47 +02: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
const onViewAllWalletsSwitchValueChanged = async value => {
2019-10-03 05:06:47 +02:00
await OnAppLaunch.setViewAllWalletsEnabled(value);
if (value) {
setViewAllWalletsEnabled(true);
setDefaultWalletLabel('');
2019-10-03 05:06:47 +02:00
} else {
const selectedWallet = await OnAppLaunch.getSelectedDefaultWallet();
setDefaultWalletLabel(selectedWallet.getLabel());
setViewAllWalletsEnabled(false);
2019-10-03 05:06:47 +02: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());
setDefaultWalletLabel(wallet.getLabel());
setViewAllWalletsEnabled(false);
pop();
2019-10-03 05:06:47 +02:00
};
return (
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
<View>
<BlueListItem
title="View All Wallets"
2020-05-03 20:17:49 +02:00
Component={TouchableWithoutFeedback}
switch={{
onValueChange: onViewAllWalletsSwitchValueChanged,
value: viewAllWalletsEnabled,
disabled: BlueApp.getWallets().length <= 0,
}}
/>
<BlueCard>
<BlueText>When disabled, BlueWallet will immediately open the selected wallet at launch.</BlueText>
</BlueCard>
{!viewAllWalletsEnabled && (
2020-05-03 20:17:49 +02:00
<BlueListItem title="Default into" component={TouchableOpacity} onPress={selectWallet} rightTitle={defaultWalletLabel} chevron />
)}
</View>
</SafeBlueArea>
);
2019-10-03 05:06:47 +02:00
};
DefaultView.navigationOptions = () => ({
...BlueNavigationStyle(),
title: 'On Launch',
});
export default DefaultView;