2020-10-24 19:20:59 +02:00
|
|
|
import React, { useContext, useEffect, useState } from 'react';
|
2021-03-22 12:54:17 +01:00
|
|
|
import { View, TouchableWithoutFeedback } from 'react-native';
|
2020-07-20 15:38:46 +02:00
|
|
|
import { useNavigation } from '@react-navigation/native';
|
2020-12-25 17:09:53 +01:00
|
|
|
|
|
|
|
import navigationStyle from '../../components/navigationStyle';
|
|
|
|
import { SafeBlueArea, BlueCard, BlueListItem, BlueText } from '../../BlueComponents';
|
2020-05-24 12:27:08 +02:00
|
|
|
import OnAppLaunch from '../../class/on-app-launch';
|
2020-07-20 15:38:46 +02:00
|
|
|
import loc from '../../loc';
|
2020-10-24 19:20:59 +02:00
|
|
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
2019-10-03 05:06:47 +02:00
|
|
|
|
2019-12-25 17:25:30 +01:00
|
|
|
const DefaultView = () => {
|
|
|
|
const [defaultWalletLabel, setDefaultWalletLabel] = useState('');
|
|
|
|
const [viewAllWalletsEnabled, setViewAllWalletsEnabled] = useState(true);
|
|
|
|
const { navigate, pop } = useNavigation();
|
2020-10-24 19:20:59 +02:00
|
|
|
const { wallets } = useContext(BlueStorageContext);
|
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 (
|
2021-03-22 12:54:17 +01:00
|
|
|
<SafeBlueArea>
|
2019-12-25 17:25:30 +01:00
|
|
|
<View>
|
2020-09-22 03:53:28 +02:00
|
|
|
<BlueListItem
|
2020-07-20 15:38:46 +02:00
|
|
|
title={loc.settings.default_wallets}
|
2020-05-03 20:17:49 +02:00
|
|
|
Component={TouchableWithoutFeedback}
|
|
|
|
switch={{
|
|
|
|
onValueChange: onViewAllWalletsSwitchValueChanged,
|
|
|
|
value: viewAllWalletsEnabled,
|
2020-10-24 19:20:59 +02:00
|
|
|
disabled: wallets.length <= 0,
|
2020-05-03 20:17:49 +02:00
|
|
|
}}
|
2019-12-25 17:25:30 +01:00
|
|
|
/>
|
2020-03-30 04:50:18 +02:00
|
|
|
<BlueCard>
|
2020-11-22 09:04:04 +01:00
|
|
|
<BlueText>{loc.settings.default_desc}</BlueText>
|
2020-03-30 04:50:18 +02:00
|
|
|
</BlueCard>
|
2019-12-25 17:25:30 +01:00
|
|
|
{!viewAllWalletsEnabled && (
|
2020-09-22 03:53:28 +02:00
|
|
|
<BlueListItem title={loc.settings.default_info} 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
|
|
|
|
2021-02-15 09:03:54 +01:00
|
|
|
DefaultView.navigationOptions = navigationStyle({}, opts => ({ ...opts, title: loc.settings.default_title }));
|
2019-12-25 17:25:30 +01:00
|
|
|
|
|
|
|
export default DefaultView;
|