From e4ed62971c425d6b7d6f7bc15f31acf5cce31fb2 Mon Sep 17 00:00:00 2001 From: Josh Leonard <30185185+josheleonard@users.noreply.github.com> Date: Thu, 1 Aug 2024 14:29:13 -0600 Subject: [PATCH] fix(wallet): start interaction notifier on unlock and init (#24956) --- .../brave_wallet_ui/common/async/handlers.ts | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/components/brave_wallet_ui/common/async/handlers.ts b/components/brave_wallet_ui/common/async/handlers.ts index 10dbaec3d5ec..4f67aa4fadf6 100644 --- a/components/brave_wallet_ui/common/async/handlers.ts +++ b/components/brave_wallet_ui/common/async/handlers.ts @@ -5,7 +5,6 @@ import AsyncActionHandler from '../../../common/AsyncActionHandler' import * as WalletActions from '../actions/wallet_actions' -import { WalletState } from '../../constants/types' // Utils import getAPIProxy from './bridge' @@ -15,10 +14,6 @@ import { walletApi } from '../slices/api.slice' const handler = new AsyncActionHandler() -function getWalletState(store: Store): WalletState { - return store.getState().wallet -} - async function refreshWalletInfo(store: Store) { const apiProxy = getAPIProxy() @@ -60,7 +55,16 @@ handler.on( handler.on(WalletActions.initialize.type, async (store) => { const { walletHandler, keyringService } = getAPIProxy() const { walletInfo } = await walletHandler.getWalletInfo() + const { isWalletLocked } = walletInfo const { allAccounts } = await keyringService.getAllAccounts() + if (!isWalletLocked) { + keyringService.notifyUserInteraction() + } + interactionNotifier.beginWatchingForInteraction( + 50000, + isWalletLocked, + keyringService.notifyUserInteraction + ) store.dispatch(WalletActions.initialized({ walletInfo, allAccounts })) }) @@ -83,6 +87,13 @@ handler.on(WalletActions.locked.type, async (store) => { handler.on(WalletActions.unlocked.type, async (store) => { await refreshWalletInfo(store) + const { keyringService } = getAPIProxy() + keyringService.notifyUserInteraction() + interactionNotifier.beginWatchingForInteraction( + 50000, + false, + keyringService.notifyUserInteraction + ) }) handler.on(WalletActions.backedUp.type, async (store) => { @@ -101,22 +112,12 @@ handler.on( ) handler.on(WalletActions.refreshAll.type, async (store: Store) => { - const keyringService = getAPIProxy().keyringService - const state = getWalletState(store) - if (!state.isWalletLocked) { - keyringService.notifyUserInteraction() - } - interactionNotifier.beginWatchingForInteraction( - 50000, - state.isWalletLocked, - async () => { - keyringService.notifyUserInteraction() - } - ) - const braveWalletService = getAPIProxy().braveWalletService + const { braveWalletService, walletHandler } = getAPIProxy() + const { walletInfo } = await walletHandler.getWalletInfo() + const { isWalletCreated, isWalletLocked } = walletInfo store.dispatch(walletApi.util.invalidateTags(['DefaultFiatCurrency'])) // Fetch Balances and Prices - if (!state.isWalletLocked && state.isWalletCreated) { + if (!isWalletLocked && isWalletCreated) { // refresh networks registry & selected network await store .dispatch(walletApi.endpoints.refreshNetworkInfo.initiate())