REF: OnAppLaunch to TS

This commit is contained in:
Marcos Rodriguez Velez 2023-10-22 13:00:42 -04:00
parent 1933481485
commit 8f4b71ff84
No known key found for this signature in database
GPG Key ID: 6030B2F48CCE86D7

View File

@ -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));
}
}