2020-10-24 13:20:59 -04:00
|
|
|
import React, { useContext, useEffect, useState } from 'react';
|
2024-01-13 10:56:29 -04:00
|
|
|
import { View, TouchableWithoutFeedback, ScrollView } from 'react-native';
|
2020-07-20 16:38:46 +03:00
|
|
|
import { useNavigation } from '@react-navigation/native';
|
2020-12-25 19:09:53 +03:00
|
|
|
|
|
|
|
import navigationStyle from '../../components/navigationStyle';
|
2023-12-27 13:52:11 +07:00
|
|
|
import { BlueCard, BlueText } from '../../BlueComponents';
|
2020-05-24 06:27:08 -04:00
|
|
|
import OnAppLaunch from '../../class/on-app-launch';
|
2020-07-20 16:38:46 +03:00
|
|
|
import loc from '../../loc';
|
2020-10-24 13:20:59 -04:00
|
|
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
2023-12-16 17:44:35 -04:00
|
|
|
import ListItem from '../../components/ListItem';
|
2019-10-02 23:06:47 -04:00
|
|
|
|
2019-12-25 10:25:30 -06:00
|
|
|
const DefaultView = () => {
|
|
|
|
const [defaultWalletLabel, setDefaultWalletLabel] = useState('');
|
|
|
|
const [viewAllWalletsEnabled, setViewAllWalletsEnabled] = useState(true);
|
|
|
|
const { navigate, pop } = useNavigation();
|
2020-10-24 13:20:59 -04:00
|
|
|
const { wallets } = useContext(BlueStorageContext);
|
2019-10-02 23:06:47 -04:00
|
|
|
|
2019-12-25 10:25:30 -06:00
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
2023-07-25 14:50:04 +01:00
|
|
|
const newViewAllWalletsEnabled = await OnAppLaunch.isViewAllWalletsEnabled();
|
|
|
|
let newDefaultWalletLabel = '';
|
2019-12-25 10:25:30 -06:00
|
|
|
const wallet = await OnAppLaunch.getSelectedDefaultWallet();
|
|
|
|
if (wallet) {
|
2023-07-25 14:50:04 +01:00
|
|
|
newDefaultWalletLabel = wallet.getLabel();
|
2019-12-25 10:25:30 -06:00
|
|
|
}
|
2023-07-25 14:50:04 +01:00
|
|
|
setDefaultWalletLabel(newDefaultWalletLabel);
|
|
|
|
setViewAllWalletsEnabled(newViewAllWalletsEnabled);
|
2019-12-25 10:25:30 -06:00
|
|
|
})();
|
|
|
|
});
|
2019-10-02 23:06:47 -04:00
|
|
|
|
2019-12-25 10:25:30 -06:00
|
|
|
const onViewAllWalletsSwitchValueChanged = async value => {
|
2019-10-02 23:06:47 -04:00
|
|
|
await OnAppLaunch.setViewAllWalletsEnabled(value);
|
|
|
|
if (value) {
|
2019-12-25 10:25:30 -06:00
|
|
|
setViewAllWalletsEnabled(true);
|
|
|
|
setDefaultWalletLabel('');
|
2019-10-02 23:06:47 -04:00
|
|
|
} else {
|
|
|
|
const selectedWallet = await OnAppLaunch.getSelectedDefaultWallet();
|
2019-12-25 10:25:30 -06:00
|
|
|
setDefaultWalletLabel(selectedWallet.getLabel());
|
|
|
|
setViewAllWalletsEnabled(false);
|
2019-10-02 23:06:47 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-25 10:25:30 -06:00
|
|
|
const selectWallet = () => {
|
|
|
|
navigate('SelectWallet', { onWalletSelect: onWalletSelectValueChanged });
|
|
|
|
};
|
|
|
|
|
|
|
|
const onWalletSelectValueChanged = async wallet => {
|
2019-10-02 23:06:47 -04:00
|
|
|
await OnAppLaunch.setViewAllWalletsEnabled(false);
|
|
|
|
await OnAppLaunch.setSelectedDefaultWallet(wallet.getID());
|
2019-12-25 10:25:30 -06:00
|
|
|
setDefaultWalletLabel(wallet.getLabel());
|
|
|
|
setViewAllWalletsEnabled(false);
|
|
|
|
pop();
|
2019-10-02 23:06:47 -04:00
|
|
|
};
|
|
|
|
|
2019-12-25 10:25:30 -06:00
|
|
|
return (
|
2024-01-13 10:56:29 -04:00
|
|
|
<ScrollView automaticallyAdjustContentInsets contentInsetAdjustmentBehavior="automatic">
|
2019-12-25 10:25:30 -06:00
|
|
|
<View>
|
2023-12-16 17:44:35 -04:00
|
|
|
<ListItem
|
2020-07-20 16:38:46 +03:00
|
|
|
title={loc.settings.default_wallets}
|
2020-05-03 14:17:49 -04:00
|
|
|
Component={TouchableWithoutFeedback}
|
|
|
|
switch={{
|
|
|
|
onValueChange: onViewAllWalletsSwitchValueChanged,
|
|
|
|
value: viewAllWalletsEnabled,
|
2020-10-24 13:20:59 -04:00
|
|
|
disabled: wallets.length <= 0,
|
2020-05-03 14:17:49 -04:00
|
|
|
}}
|
2019-12-25 10:25:30 -06:00
|
|
|
/>
|
2020-03-29 22:50:18 -04:00
|
|
|
<BlueCard>
|
2020-11-22 03:04:04 -05:00
|
|
|
<BlueText>{loc.settings.default_desc}</BlueText>
|
2020-03-29 22:50:18 -04:00
|
|
|
</BlueCard>
|
2019-12-25 10:25:30 -06:00
|
|
|
{!viewAllWalletsEnabled && (
|
2023-12-16 17:44:35 -04:00
|
|
|
<ListItem title={loc.settings.default_info} onPress={selectWallet} rightTitle={defaultWalletLabel} chevron />
|
2019-12-25 10:25:30 -06:00
|
|
|
)}
|
|
|
|
</View>
|
2024-01-13 10:56:29 -04:00
|
|
|
</ScrollView>
|
2019-12-25 10:25:30 -06:00
|
|
|
);
|
2019-10-02 23:06:47 -04:00
|
|
|
};
|
2019-12-25 10:25:30 -06:00
|
|
|
|
2021-02-15 11:03:54 +03:00
|
|
|
DefaultView.navigationOptions = navigationStyle({}, opts => ({ ...opts, title: loc.settings.default_title }));
|
2019-12-25 10:25:30 -06:00
|
|
|
|
|
|
|
export default DefaultView;
|