Skip to content

Commit

Permalink
feat: auto reset to get-started screen on no account exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardo2016x committed Dec 2, 2024
1 parent 43a2e37 commit f079f09
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions apps/mobile/src/screens/Home/MultiAddressHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ import { Skeleton } from '@rneui/base';
import { transactionHistoryService } from '@/core/services';
import { eventBus, EVENTS } from '@/utils/events';
import { useSafeSizes } from '@/hooks/useAppLayout';
import { useMount } from 'ahooks';
import { useMemoizedFn, useMount } from 'ahooks';
import NormalScreenContainer2024 from '@/components2024/ScreenContainer/NormalScreenContainer';
import { useSwitchSceneCurrentAccount } from '@/hooks/accountsSwitcher';
import { matomoRequestEvent } from '@/utils/analytics';
import { apisAccount } from '@/core/apis';
import { resetNavigationTo } from '@/hooks/navigation';

const MENU_ARR = [
{
Expand Down Expand Up @@ -203,7 +205,7 @@ function MultiAddressHome(): JSX.Element {
}
const { pendingsLength, pendings } =
transactionHistoryService.getPendingsAddresses(addresses);
console.log('fetchHistory :', balanceCacheAccounts, pendings);
console.debug('fetchHistory :', balanceCacheAccounts, pendings);
setPendingTxCount(pendingsLength);
if (pendingsLength) {
if (!timeRef.current) {
Expand All @@ -215,6 +217,15 @@ function MultiAddressHome(): JSX.Element {
}
}, [balanceCacheAccounts]);

const detectHasAccounts = useMemoizedFn(async () => {
const hasAccountsInKeyring = await apisAccount.hasVisibleAccounts();
if (!hasAccountsInKeyring) {
resetNavigationTo(navigation, 'GetStarted2024');
}

return hasAccountsInKeyring;
});

// useMount(() => { no use ?
// eventBus.addListener(EVENTS.TX_COMPLETED, fetchHistory);
// return () => {
Expand All @@ -224,10 +235,13 @@ function MultiAddressHome(): JSX.Element {

useFocusEffect(
useCallback(() => {
if (!timeRef.current) {
fetchHistory();
}
}, [fetchHistory]),
(async () => {
const hasAccountsInKeyring = await detectHasAccounts();
if (hasAccountsInKeyring && !timeRef.current) {
fetchHistory();
}
})();
}, [detectHasAccounts, fetchHistory]),
);

useFocusEffect(
Expand Down

0 comments on commit f079f09

Please sign in to comment.