2020-12-16 04:15:57 +01:00
|
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
2019-10-03 05:06:47 +02:00
|
|
|
const BlueApp = require('../BlueApp');
|
|
|
|
|
|
|
|
export default class OnAppLaunch {
|
2019-10-06 03:12:55 +02:00
|
|
|
static STORAGE_KEY = 'ONAPP_LAUNCH_SELECTED_DEFAULT_WALLET_KEY';
|
2019-10-03 05:06:47 +02:00
|
|
|
|
|
|
|
static async isViewAllWalletsEnabled() {
|
|
|
|
try {
|
2019-10-06 03:12:55 +02:00
|
|
|
const selectedDefaultWallet = await AsyncStorage.getItem(OnAppLaunch.STORAGE_KEY);
|
|
|
|
return selectedDefaultWallet === '' || selectedDefaultWallet === null;
|
2019-10-03 05:06:47 +02:00
|
|
|
} catch (_e) {
|
2019-10-06 03:12:55 +02:00
|
|
|
return true;
|
2019-10-03 05:06:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static async setViewAllWalletsEnabled(value) {
|
|
|
|
if (!value) {
|
|
|
|
const selectedDefaultWallet = await OnAppLaunch.getSelectedDefaultWallet();
|
|
|
|
if (!selectedDefaultWallet) {
|
|
|
|
const firstWallet = BlueApp.getWallets()[0];
|
|
|
|
await OnAppLaunch.setSelectedDefaultWallet(firstWallet.getID());
|
|
|
|
}
|
2019-10-06 03:12:55 +02:00
|
|
|
} else {
|
|
|
|
await AsyncStorage.setItem(OnAppLaunch.STORAGE_KEY, '');
|
2019-10-03 05:06:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static async getSelectedDefaultWallet() {
|
|
|
|
let selectedWallet = false;
|
|
|
|
try {
|
2019-10-06 02:54:12 +02:00
|
|
|
const selectedWalletID = JSON.parse(await AsyncStorage.getItem(OnAppLaunch.STORAGE_KEY));
|
2019-10-03 05:06:47 +02:00
|
|
|
selectedWallet = BlueApp.getWallets().find(wallet => wallet.getID() === selectedWalletID);
|
|
|
|
if (!selectedWallet) {
|
2019-10-06 03:12:55 +02:00
|
|
|
await AsyncStorage.setItem(OnAppLaunch.STORAGE_KEY, '');
|
2019-10-03 05:06:47 +02:00
|
|
|
}
|
|
|
|
} catch (_e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return selectedWallet;
|
|
|
|
}
|
|
|
|
|
|
|
|
static async setSelectedDefaultWallet(value) {
|
2019-10-06 02:54:12 +02:00
|
|
|
await AsyncStorage.setItem(OnAppLaunch.STORAGE_KEY, JSON.stringify(value));
|
2019-10-03 05:06:47 +02:00
|
|
|
}
|
|
|
|
}
|