Skip to content

Commit

Permalink
fix: redirect to get-started-2024 on all wc accounts removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardo2016x committed Dec 2, 2024
1 parent f7d4b90 commit 2a8ec2b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
removeGlobalBottomSheetModal2024,
} from '../GlobalBottomSheetModal';
import { MODAL_ID, MODAL_NAMES } from '../GlobalBottomSheetModal/types';
import { apisAccount } from '@/core/apis';
import { redirectToAddAddressEntry } from '@/utils/navigation';

export const useNoLongerSupports = () => {
const { accounts } = useAccounts({
Expand All @@ -20,6 +22,12 @@ export const useNoLongerSupports = () => {
removeAccount(account);
}
});

apisAccount.hasVisibleAccounts().then(hasRestAccounts => {
if (!hasRestAccounts) {
redirectToAddAddressEntry({ action: 'resetTo' });
}
});
}, [accounts, removeAccount]);

React.useEffect(() => {
Expand Down
5 changes: 3 additions & 2 deletions apps/mobile/src/core/apis/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ function ensureDisplayKeyring(keyring: KeyringIntf | DisplayKeyring) {
}

export async function hasVisibleAccounts() {
return keyringService.getCountOfAccountsInKeyring() > 0;
const restAccountsCount = await keyringService.getCountOfAccountsInKeyring();
return restAccountsCount > 0;
}

export async function getAllVisibleAccounts(): Promise<DisplayedKeyring[]> {
async function getAllVisibleAccounts(): Promise<DisplayedKeyring[]> {
const typedAccounts = await keyringService.getAllTypedVisibleAccounts();

return typedAccounts.map(account => ({
Expand Down
3 changes: 1 addition & 2 deletions apps/mobile/src/screens/Home/MultiAddressHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ function MultiAddressHome(): JSX.Element {

const detectHasAccounts = useMemoizedFn(async () => {
const result = { redirectAction: null as Function | null };
const hasAccountsInKeyring =
(await apisAccount.getAllVisibleAccounts()).length > 0;
const hasAccountsInKeyring = await apisAccount.hasVisibleAccounts();

if (!hasAccountsInKeyring) {
result.redirectAction = () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/service-keyring/src/keyringService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ export class KeyringService extends RNEventEmitter {
// }

async getCountOfAccountsInKeyring() {
const accus = await this.getAllTypedVisibleAccounts();
return accus.length;
const accounts = await this.getAllTypedVisibleAccounts();
return accounts.length;
}

/**
Expand Down

0 comments on commit 2a8ec2b

Please sign in to comment.