Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: send page select account support derivation selector OK-35146 #6605

Merged
merged 5 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions packages/kit-bg/src/dbs/local/LocalDbBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2735,9 +2735,7 @@ export abstract class LocalDbBase extends LocalDbBaseContainer {

async getAllDevices(): Promise<{ devices: IDBDevice[] }> {
const cacheKey = 'allDbDevices';
const allDevicesInCache = this.dbAllRecordsCache.get(
cacheKey,
) as IDBDevice[];
const allDevicesInCache = this.getAllRecordsByCache<IDBDevice>(cacheKey);
if (allDevicesInCache && allDevicesInCache.length) {
return { devices: allDevicesInCache };
}
Expand All @@ -2753,9 +2751,7 @@ export abstract class LocalDbBase extends LocalDbBaseContainer {
wallets: IDBWallet[];
}> {
const cacheKey = 'allDbWallets';
const allWalletsInCache = this.dbAllRecordsCache.get(
cacheKey,
) as IDBWallet[];
const allWalletsInCache = this.getAllRecordsByCache<IDBWallet>(cacheKey);
if (allWalletsInCache && allWalletsInCache.length) {
return { wallets: allWalletsInCache };
}
Expand Down Expand Up @@ -2796,9 +2792,8 @@ export abstract class LocalDbBase extends LocalDbBaseContainer {
indexedAccounts: IDBIndexedAccount[];
}> {
const cacheKey = 'allDbIndexedAccounts';
const allIndexedAccountsInCache = this.dbAllRecordsCache.get(
cacheKey,
) as IDBIndexedAccount[];
const allIndexedAccountsInCache =
this.getAllRecordsByCache<IDBIndexedAccount>(cacheKey);
if (allIndexedAccountsInCache && allIndexedAccountsInCache.length) {
return { indexedAccounts: allIndexedAccountsInCache };
}
Expand All @@ -2814,9 +2809,8 @@ export abstract class LocalDbBase extends LocalDbBaseContainer {
}> {
const cacheKey = 'allDbAccounts';
if (!ids) {
const allDbAccountsInCache = this.dbAllRecordsCache.get(
cacheKey,
) as IDBAccount[];
const allDbAccountsInCache =
this.getAllRecordsByCache<IDBAccount>(cacheKey);
if (allDbAccountsInCache && allDbAccountsInCache?.length) {
return { accounts: allDbAccountsInCache };
}
Expand Down
19 changes: 18 additions & 1 deletion packages/kit-bg/src/dbs/local/LocalDbBaseContainer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { cloneDeep } from 'lodash';

import accountUtils from '@onekeyhq/shared/src/utils/accountUtils';
import cacheUtils, { memoizee } from '@onekeyhq/shared/src/utils/cacheUtils';
import timerUtils from '@onekeyhq/shared/src/utils/timerUtils';
Expand Down Expand Up @@ -73,7 +75,8 @@ export abstract class LocalDbBaseContainer implements ILocalDBAgent {
// shouldUseCache = false;
}
if (shouldUseCache) {
return this.getRecordByIdWithCache(params);
const cache = await this.getRecordByIdWithCache(params);
return cloneDeep(cache);
}

const db = await this.readyDb;
Expand Down Expand Up @@ -110,6 +113,20 @@ export abstract class LocalDbBaseContainer implements ILocalDBAgent {
ttl: timerUtils.getTimeDurationMs({ seconds: 5 }),
});

getAllRecordsByCache<T>(
cacheKey:
| 'allDbAccounts'
| 'allDbIndexedAccounts'
| 'allDbWallets'
| 'allDbDevices',
) {
const allItemsInCache = this.dbAllRecordsCache.get(cacheKey) as T[];
if (allItemsInCache && allItemsInCache.length) {
sidmorizon marked this conversation as resolved.
Show resolved Hide resolved
return cloneDeep(allItemsInCache);
}
return undefined;
}

clearStoreCachedDataIfMatch(storeName: ELocalDBStoreNames) {
if (this.isCachedStoreName(storeName)) {
this.clearStoreCachedData();
Expand Down
9 changes: 8 additions & 1 deletion packages/kit-bg/src/services/ServiceAccountSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ class ServiceAccountSelector extends ServiceBase {
if (!(await this.shouldUseGlobalDeriveType({ sceneName }))) {
return;
}
if (
!accountSelectorUtils.isSceneAutoSaveToGlobalDeriveType({
sceneName,
})
) {
return;
}
const { serviceNetwork } = this.backgroundApi;
// TODO add whitelist
const { networkId, deriveType, walletId } = selectedAccount;
Expand Down Expand Up @@ -702,7 +709,7 @@ class ServiceAccountSelector extends ServiceBase {
});
indexedAccount.associateAccount = realAccount;
} catch (e) {
//
indexedAccount.associateAccount = undefined;
}
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ export function WalletDetailsHeader({
) : null}
{linkedNetworkId &&
!isNil(num) &&
accountSelectorContextData?.sceneName ===
EAccountSelectorSceneName.discover ? (
[
EAccountSelectorSceneName.discover,
EAccountSelectorSceneName.addressInput,
].includes(accountSelectorContextData?.sceneName as any) ? (
<DeriveTypeSelectorTriggerForDapp
num={num}
focusedWalletId={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,36 @@ import { useDebouncedCallback } from 'use-debounce';

import type { ISortableSectionListRef } from '@onekeyhq/components';
import {
Icon,
InputUnControlled,
SectionList,
Stack,
useSafeAreaInsets,
useSafelyScrollToLocation,
} from '@onekeyhq/components';
import backgroundApiProxy from '@onekeyhq/kit/src/background/instance/backgroundApiProxy';
import { ListItem } from '@onekeyhq/kit/src/components/ListItem';
import useAppNavigation from '@onekeyhq/kit/src/hooks/useAppNavigation';
import { usePromiseResult } from '@onekeyhq/kit/src/hooks/usePromiseResult';
import {
useAccountSelectorActions,
useAccountSelectorEditModeAtom,
useSelectedAccount,
} from '@onekeyhq/kit/src/states/jotai/contexts/accountSelector';
import type {
IDBAccount,
IDBDevice,
IDBIndexedAccount,
IDBWallet,
} from '@onekeyhq/kit-bg/src/dbs/local/types';
import type { IAccountSelectorAccountsListSectionData } from '@onekeyhq/kit-bg/src/dbs/simple/entity/SimpleDbEntityAccountSelector';
import { accountSelectorAccountsListIsLoadingAtom } from '@onekeyhq/kit-bg/src/states/jotai/atoms';
import backgroundApiProxy from '@onekeyhq/kit/src/background/instance/backgroundApiProxy';
import useAppNavigation from '@onekeyhq/kit/src/hooks/useAppNavigation';
import { usePromiseResult } from '@onekeyhq/kit/src/hooks/usePromiseResult';
import {
accountSelectorAccountsListIsLoadingAtom,
indexedAccountAddressCreationStateAtom,
} from '@onekeyhq/kit-bg/src/states/jotai/atoms';
useAccountSelectorActions,
useAccountSelectorEditModeAtom,
useSelectedAccount,
} from '@onekeyhq/kit/src/states/jotai/contexts/accountSelector';
import { emptyArray } from '@onekeyhq/shared/src/consts';
import {
WALLET_TYPE_EXTERNAL,
WALLET_TYPE_IMPORTED,
WALLET_TYPE_WATCHING,
} from '@onekeyhq/shared/src/consts/dbConsts';
import {
EAppEventBusNames,
appEventBus,
} from '@onekeyhq/shared/src/eventBus/appEventBus';
import { ETranslations } from '@onekeyhq/shared/src/locale';
import { defaultLogger } from '@onekeyhq/shared/src/logger/logger';
import { EModalRoutes, EOnboardingPages } from '@onekeyhq/shared/src/routes';
import accountUtils from '@onekeyhq/shared/src/utils/accountUtils';
import networkUtils from '@onekeyhq/shared/src/utils/networkUtils';

import { useAccountSelectorRoute } from '../../../router/useAccountSelectorRoute';

Expand Down Expand Up @@ -111,12 +99,15 @@ function WalletDetailsView({ num }: IWalletDetailsProps) {
return Promise.resolve(undefined);
}
// await timerUtils.wait(1000);
return serviceAccountSelector.buildAccountSelectorAccountsListData({
focusedWallet: selectedAccount?.focusedWallet,
linkedNetworkId,
deriveType: selectedAccount.deriveType,
othersNetworkId: selectedAccount?.networkId,
});
const accountSelectorAccountsListData =
await serviceAccountSelector.buildAccountSelectorAccountsListData({
focusedWallet: selectedAccount?.focusedWallet,
linkedNetworkId,
deriveType: selectedAccount.deriveType,
othersNetworkId: selectedAccount?.networkId,
});

return accountSelectorAccountsListData;
},
[
linkedNetworkId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export function SentryCrashSettings() {
const [state, setState] = useState({ text: 'Error Boundary' });
const sections = [
<SectionPressItem
key="SentryCrashTest"
key="SentryCrashTest1"
title="Sentry Crash Test"
onPress={() => {
captureException(new Error('First error'));
}}
/>,
<SectionPressItem
key="SentryCrashTest"
key="SentryCrashTest2"
title={`Sentry Crash Test With ${state.text}`}
onPress={() => {
setState(null as any);
Expand All @@ -29,6 +29,7 @@ export function SentryCrashSettings() {
if (platformEnv.isNative) {
sections.push(
<SectionPressItem
key="SentryCrashTest3"
title="Sentry Native Crash"
onPress={() => {
nativeCrash();
Expand All @@ -38,6 +39,7 @@ export function SentryCrashSettings() {
} else if (platformEnv.isDesktop) {
sections.push(
<SectionPressItem
key="SentryCrashTest4"
title="Sentry Native Crash"
onPress={() => {
globalThis.desktopApi.testCrash();
Expand Down
18 changes: 18 additions & 0 deletions packages/shared/src/utils/accountSelectorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ function isSceneUseGlobalDeriveType({
return true;
}

function isSceneAutoSaveToGlobalDeriveType({
sceneName,
}: {
sceneName: EAccountSelectorSceneName | undefined;
}) {
if (
sceneName &&
[
EAccountSelectorSceneName.discover,
EAccountSelectorSceneName.addressInput,
].includes(sceneName)
) {
return false;
}
return true;
}

export default {
isEqualAccountSelectorScene,
buildAccountSelectorSaveKey,
Expand All @@ -166,4 +183,5 @@ export default {
isSceneCanAutoSelect,
isSceneCanPersist,
isSceneUseGlobalDeriveType,
isSceneAutoSaveToGlobalDeriveType,
};
Loading