mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-01-18 21:35:21 +01:00
REF: OnAppLaunch to TS
This commit is contained in:
parent
1933481485
commit
8f4b71ff84
@ -1,10 +1,11 @@
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { AbstractWallet } from './wallets/abstract-wallet';
|
||||
const BlueApp = require('../BlueApp');
|
||||
|
||||
export default class OnAppLaunch {
|
||||
static STORAGE_KEY = 'ONAPP_LAUNCH_SELECTED_DEFAULT_WALLET_KEY';
|
||||
|
||||
static async isViewAllWalletsEnabled() {
|
||||
static async isViewAllWalletsEnabled(): Promise<boolean> {
|
||||
try {
|
||||
const selectedDefaultWallet = await AsyncStorage.getItem(OnAppLaunch.STORAGE_KEY);
|
||||
return selectedDefaultWallet === '' || selectedDefaultWallet === null;
|
||||
@ -13,7 +14,7 @@ export default class OnAppLaunch {
|
||||
}
|
||||
}
|
||||
|
||||
static async setViewAllWalletsEnabled(value) {
|
||||
static async setViewAllWalletsEnabled(value: boolean) {
|
||||
if (!value) {
|
||||
const selectedDefaultWallet = await OnAppLaunch.getSelectedDefaultWallet();
|
||||
if (!selectedDefaultWallet) {
|
||||
@ -25,13 +26,15 @@ export default class OnAppLaunch {
|
||||
}
|
||||
}
|
||||
|
||||
static async getSelectedDefaultWallet() {
|
||||
let selectedWallet = false;
|
||||
static async getSelectedDefaultWallet(): Promise<AbstractWallet | false> {
|
||||
let selectedWallet: AbstractWallet | false = false;
|
||||
try {
|
||||
const selectedWalletID = JSON.parse(await AsyncStorage.getItem(OnAppLaunch.STORAGE_KEY));
|
||||
selectedWallet = BlueApp.getWallets().find(wallet => wallet.getID() === selectedWalletID);
|
||||
if (!selectedWallet) {
|
||||
await AsyncStorage.setItem(OnAppLaunch.STORAGE_KEY, '');
|
||||
const selectedWalletID = JSON.parse((await AsyncStorage.getItem(OnAppLaunch.STORAGE_KEY)) || 'null');
|
||||
if (selectedWalletID) {
|
||||
selectedWallet = BlueApp.getWallets().find((wallet: AbstractWallet) => wallet.getID() === selectedWalletID);
|
||||
if (!selectedWallet) {
|
||||
await AsyncStorage.setItem(OnAppLaunch.STORAGE_KEY, '');
|
||||
}
|
||||
}
|
||||
} catch (_e) {
|
||||
return false;
|
||||
@ -39,7 +42,7 @@ export default class OnAppLaunch {
|
||||
return selectedWallet;
|
||||
}
|
||||
|
||||
static async setSelectedDefaultWallet(value) {
|
||||
static async setSelectedDefaultWallet(value: string) {
|
||||
await AsyncStorage.setItem(OnAppLaunch.STORAGE_KEY, JSON.stringify(value));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user