diff --git a/src/components/App.tsx b/src/components/App.tsx index 55ce1ad7..e4d028ec 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -16,11 +16,11 @@ import { FocusClaimCtx } from '@src/context/FocusClaim' import { KeyboardProvider } from '@src/context/Keyboard' import { PinCtx } from '@src/context/Pin' import { ThemeContext } from '@src/context/Theme' -import { AsyncStore, secureStore } from '@store' +import { secureStore,store } from '@store' import { addToHistory } from '@store/HistoryStore' import { dark, globals, light } from '@styles' import { formatInt, formatMintUrl, hasTrustedMint, isCashuToken, isErr, isNull, isStr, sleep } from '@util' -import { initCrashReporting, routingInstrumentation } from '@util/crashReporting' +import { routingInstrumentation } from '@util/crashReporting' import { claimToken, isTokenSpendable, runRequestTokenLoop } from '@wallet' import { getTokenInfo } from '@wallet/proofs' import * as Clipboard from 'expo-clipboard' @@ -45,8 +45,6 @@ interface ILockData { timestamp: number } -initCrashReporting() - void SplashScreen.preventAutoHideAsync() export default function App(){ @@ -86,7 +84,7 @@ function _App() { const handlePinForeground = async () => { // check if app is locked const now = Math.ceil(Date.now() / 1000) - const lockData = await AsyncStore.getObj('lock') + const lockData = await store.getObj('lock') if (lockData) { // set state acccording to lockData timestamp const secsPassed = now - lockData.timestamp @@ -98,7 +96,7 @@ function _App() { }) } // handle app was longer than 5 mins in the background - const bgTimestamp = await AsyncStore.get('authBg') + const bgTimestamp = await store.get('authBg') if (isStr(bgTimestamp) && bgTimestamp.length > 0) { if (now - +bgTimestamp > FiveMins) { setBgAuth(true) @@ -259,8 +257,8 @@ function _App() { } async function initAuth() { // await secureStore.delete('pin') - // await AsyncStore.delete('pinSkipped') - const skipped = await AsyncStore.get('pinSkipped') + // await store.delete('pinSkipped') + const skipped = await store.get('pinSkipped') const pinHash = await secureStore.get('pin') setAuth({ shouldAuth: isNull(pinHash) ? '' : pinHash, @@ -273,7 +271,7 @@ function _App() { await initDB() await initContacts() await initPreferences() - const storedLng = await AsyncStore.get('settings:lang') + const storedLng = await store.get('settings:lang') if (storedLng?.length) { await i18n.changeLanguage(storedLng) } @@ -309,7 +307,7 @@ function _App() { } else { l('App has gone to the background!') // store timestamp to activate auth after > 5mins in background - await AsyncStore.set('authBg', `${Math.ceil(Date.now() / 1000)}`) + await store.set('authBg', `${Math.ceil(Date.now() / 1000)}`) } appState.current = nextAppState }) diff --git a/src/components/screens/Auth/index.tsx b/src/components/screens/Auth/index.tsx index 89b15f69..73d0a085 100644 --- a/src/components/screens/Auth/index.tsx +++ b/src/components/screens/Auth/index.tsx @@ -4,7 +4,7 @@ import { MinuteInS } from '@consts/time' import type { TAuthPageProps } from '@model/nav' import { PinCtx } from '@src/context/Pin' import { ThemeContext } from '@src/context/Theme' -import { AsyncStore, secureStore } from '@store' +import { secureStore,store } from '@store' import { globals, highlight as hi } from '@styles' import { formatSeconds, vib } from '@util' import { hash256 } from '@util/crypto' @@ -64,7 +64,7 @@ export default function AuthPage({ navigation, route }: TAuthPageProps) { } // store this info to avoid bypass state on app restart if (!isConfirm) { - await AsyncStore.setObj('lock', { ...attemptState, timestamp: Math.ceil(Date.now() / 1000) }) + await store.setObj('lock', { ...attemptState, timestamp: Math.ceil(Date.now() / 1000) }) } setAttempts(attemptState) // reset mismatch state @@ -98,14 +98,14 @@ export default function AuthPage({ navigation, route }: TAuthPageProps) { if (shouldRemove) { await Promise.all([ secureStore.delete('pin'), - AsyncStore.set('pinSkipped', '1') + store.set('pinSkipped', '1') ]) setAuth('') } // remove the lock data and authbg in storage await Promise.all([ - AsyncStore.delete('lock'), - AsyncStore.delete('authBg') + store.delete('lock'), + store.delete('authBg') ]) resetStates() // User wants to edit his PIN, do not navigate away, just update the state as he had no PIN so he can enter a new PIN @@ -130,7 +130,7 @@ export default function AuthPage({ navigation, route }: TAuthPageProps) { const hash = hash256(pinStr) await Promise.all([ secureStore.set('pin', hash), - AsyncStore.delete('lock') + store.delete('lock') ]) resetStates() setSuccess(true) @@ -172,7 +172,7 @@ export default function AuthPage({ navigation, route }: TAuthPageProps) { return } // skip pin setup - await AsyncStore.set('pinSkipped', '1') + await store.set('pinSkipped', '1') navigation.navigate('dashboard') } // conditional rendering dots of pin input diff --git a/src/components/screens/Settings/Language.tsx b/src/components/screens/Settings/Language.tsx index e9ae1b70..d859afea 100644 --- a/src/components/screens/Settings/Language.tsx +++ b/src/components/screens/Settings/Language.tsx @@ -2,7 +2,7 @@ import Separator from '@comps/Separator' import Txt from '@comps/Txt' import TopNav from '@nav/TopNav' import { ThemeContext } from '@src/context/Theme' -import { AsyncStore } from '@store' +import { store } from '@store' import { globals, highlight as hi } from '@styles' import { useContext } from 'react' import { useTranslation } from 'react-i18next' @@ -41,7 +41,7 @@ function LangSelection({ code, name, selected, hasSeparator }: ILangSelectionPro const { color, highlight } = useContext(ThemeContext) const handleLangChange = async () => { await i18n.changeLanguage(code) - await AsyncStore.set('settings:lang', code) + await store.set('settings:lang', code) } return ( <> diff --git a/src/storage/store/SimpleKeyValueStore.ts b/src/storage/store/SimpleKeyValueStore.ts index f9d66bda..07785d2f 100644 --- a/src/storage/store/SimpleKeyValueStore.ts +++ b/src/storage/store/SimpleKeyValueStore.ts @@ -50,4 +50,7 @@ export class SimpleKeyValueStore extends StoreBase { } public clear(): Promise { return super.clear() } public close(): void { return super.close() } + public delete(key: string): Promise { + return super.removeItem(key) + } } diff --git a/src/storage/store/StoreBase.ts b/src/storage/store/StoreBase.ts index 199acc39..6c3ba5c9 100644 --- a/src/storage/store/StoreBase.ts +++ b/src/storage/store/StoreBase.ts @@ -106,18 +106,18 @@ export abstract class StoreBase { ) return result?.item?.(0)?.value } - protected async updateByValue(oldValue: string, newValue: string) :Promise { + protected async updateByValue(oldValue: string, newValue: string): Promise { if (!this._isReady) { await this._createStore() if (!this._isReady) { return false } } const result = await this._db.exec({ sql: `UPDATE ${this._name} SET value = ? WHERE KEY in (SELECT KEY FROM ${this._name} WHERE value = ? LIMIT 1)`, - args:[newValue,oldValue] + args: [newValue, oldValue] }) - return !!(result && 'rowsAffected' in result && result?.rowsAffected===1) + return !!(result && 'rowsAffected' in result && result?.rowsAffected === 1) } - protected async updateObjByValue(oldValue: T, newValue: T): Promise{ + protected async updateObjByValue(oldValue: T, newValue: T): Promise { if (!this._isReady) { await this._createStore() if (!this._isReady) { return false } @@ -235,4 +235,8 @@ export abstract class StoreBase { return !!(result?.insertId || result?.rowsAffected) } protected close(): void { return this._db.close() } + protected async removeItem(key: string) { + const result = await this._db.execTx({ sql: `delete from ${this._name} where key = ?`, args: [key] }) + return result?.rowsAffected === 1 + } } \ No newline at end of file diff --git a/src/storage/store/index.ts b/src/storage/store/index.ts index 908a56cd..4fec6def 100644 --- a/src/storage/store/index.ts +++ b/src/storage/store/index.ts @@ -1,4 +1,3 @@ -import { AsyncStore } from './AsyncStore' import { historyStore } from './HistoryStore' import { SecureStore } from './SecureStore' import { SimpleKeyValueStore } from './SimpleKeyValueStore' @@ -7,4 +6,4 @@ const store = new SimpleKeyValueStore('__store__') const secureStore = new SecureStore() -export { AsyncStore, historyStore, secureStore, SimpleKeyValueStore, store } \ No newline at end of file +export { historyStore, secureStore, SimpleKeyValueStore, store } \ No newline at end of file