-
Notifications
You must be signed in to change notification settings - Fork 521
fix: backport device capability tiers for v6.5.0 #12475
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
Merged
originalix
merged 8 commits into
release/v6.5.0
from
codex/hotfix-device-performance-tier-v650
Jul 17, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b9e2132
fix: backport device capability tiers for hot update
huhuanming 02cc9bf
fix: limit side panel tab preloading
huhuanming e9578be
Merge branch 'release/v6.5.0' into codex/hotfix-device-performance-ti…
huhuanming 0fe5480
Merge branch 'release/v6.5.0' into codex/hotfix-device-performance-ti…
huhuanming 02fe189
fix: report analytics device tier and wallet profile
huhuanming 45f460b
fix: refresh wallet profile analytics periodically
huhuanming 74f0b20
Merge branch 'release/v6.5.0' into codex/hotfix-device-performance-ti…
huhuanming 5a86925
Merge branch 'release/v6.5.0' into codex/hotfix-device-performance-ti…
huhuanming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
packages/kit-bg/src/services/ServiceAccount/analyticsWalletProfile.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| import type { IDBWallet } from '@onekeyhq/kit-bg/src/dbs/local/types'; | ||
| import { | ||
| BOT_WALLET_STATUS_ACTIVE, | ||
| BOT_WALLET_STATUS_DEACTIVATED, | ||
| } from '@onekeyhq/shared/src/consts/dbConsts'; | ||
| import type { IBotWalletMetadataMap } from '@onekeyhq/shared/types/botWallet'; | ||
| import { EHardwareVendor } from '@onekeyhq/shared/types/device'; | ||
|
|
||
| import { | ||
| WALLET_PROFILE_ANALYTICS_INTERVAL_MS, | ||
| buildAnalyticsWalletProfile, | ||
| computeHwVendorProfile, | ||
| shouldReportAnalyticsWalletProfile, | ||
| } from './analyticsWalletProfile'; | ||
|
|
||
| function createWallet({ | ||
| id, | ||
| type = 'hd', | ||
| isKeyless = false, | ||
| vendor, | ||
| }: { | ||
| id: string; | ||
| type?: IDBWallet['type']; | ||
| isKeyless?: boolean; | ||
| vendor?: EHardwareVendor; | ||
| }): IDBWallet { | ||
| return { | ||
| id, | ||
| name: id, | ||
| type, | ||
| isKeyless, | ||
| backuped: true, | ||
| accounts: [], | ||
| nextIds: {}, | ||
| walletNo: 1, | ||
| associatedDeviceInfo: vendor | ||
| ? ({ vendor } as IDBWallet['associatedDeviceInfo']) | ||
| : undefined, | ||
| } as IDBWallet; | ||
| } | ||
|
|
||
| function createBotMetadata( | ||
| entries: Array<[string, boolean]>, | ||
| ): IBotWalletMetadataMap { | ||
| return Object.fromEntries( | ||
| entries.map(([walletId, visible], index) => [ | ||
| walletId, | ||
| { | ||
| index, | ||
| name: walletId, | ||
| visible, | ||
| status: visible | ||
| ? BOT_WALLET_STATUS_ACTIVE | ||
| : BOT_WALLET_STATUS_DEACTIVATED, | ||
| createdAt: 1, | ||
| }, | ||
| ]), | ||
| ); | ||
| } | ||
|
|
||
| describe('buildAnalyticsWalletProfile', () => { | ||
| it('returns no profile when there are no visible wallets', () => { | ||
| expect( | ||
| buildAnalyticsWalletProfile({ | ||
| wallets: [], | ||
| botWalletMetadata: {}, | ||
| }), | ||
| ).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('aggregates the startup profile and excludes hidden bot wallets', () => { | ||
| const visibleBotId = 'hd-bot--hd-keyless-parent-1--0'; | ||
| const hiddenBotId = 'hd-bot--hd-keyless-parent-1--1'; | ||
| const profile = buildAnalyticsWalletProfile({ | ||
| wallets: [ | ||
| createWallet({ | ||
| id: 'hd-keyless-parent-1', | ||
| isKeyless: true, | ||
| }), | ||
| createWallet({ id: visibleBotId, isKeyless: true }), | ||
| createWallet({ id: hiddenBotId, isKeyless: true }), | ||
| createWallet({ id: 'imported-1', type: 'imported' }), | ||
| createWallet({ id: 'hw-onekey', type: 'hw' }), | ||
| createWallet({ | ||
| id: 'hw-ledger', | ||
| type: 'hw', | ||
| vendor: EHardwareVendor.ledger, | ||
| }), | ||
| ], | ||
| botWalletMetadata: createBotMetadata([ | ||
| [visibleBotId, true], | ||
| [hiddenBotId, false], | ||
| ]), | ||
| }); | ||
|
|
||
| expect(profile).toEqual({ | ||
| walletCount: 5, | ||
| hwWalletCount: 2, | ||
| appWalletCount: 3, | ||
| keylessWalletCount: 1, | ||
| hwVendors: ['ledger', 'onekey'], | ||
| primaryHwVendor: 'ledger', | ||
| }); | ||
| }); | ||
|
|
||
| it('keeps a visible orphan bot wallet in the keyless count', () => { | ||
| const orphanBotId = 'hd-bot--missing-parent--0'; | ||
|
|
||
| expect( | ||
| buildAnalyticsWalletProfile({ | ||
| wallets: [createWallet({ id: orphanBotId, isKeyless: true })], | ||
| botWalletMetadata: createBotMetadata([[orphanBotId, true]]), | ||
| }), | ||
| ).toEqual({ | ||
| walletCount: 1, | ||
| hwWalletCount: 0, | ||
| appWalletCount: 1, | ||
| keylessWalletCount: 1, | ||
| hwVendors: [], | ||
| primaryHwVendor: undefined, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('computeHwVendorProfile', () => { | ||
| it('returns an empty vendor profile without hardware wallets', () => { | ||
| expect(computeHwVendorProfile([createWallet({ id: 'hd-1' })])).toEqual({ | ||
| hwVendors: [], | ||
| primaryHwVendor: undefined, | ||
| }); | ||
| }); | ||
|
|
||
| it('falls back to OneKey for legacy hardware wallet records', () => { | ||
| expect( | ||
| computeHwVendorProfile([createWallet({ id: 'hw-legacy', type: 'hw' })]), | ||
| ).toEqual({ | ||
| hwVendors: ['onekey'], | ||
| primaryHwVendor: 'onekey', | ||
| }); | ||
| }); | ||
|
|
||
| it('returns sorted vendors and selects the majority vendor', () => { | ||
| const profile = computeHwVendorProfile([ | ||
| createWallet({ id: 'hw-legacy-1', type: 'hw' }), | ||
| createWallet({ id: 'hw-legacy-2', type: 'hw' }), | ||
| createWallet({ | ||
| id: 'hw-ledger', | ||
| type: 'hw', | ||
| vendor: EHardwareVendor.ledger, | ||
| }), | ||
| ]); | ||
|
|
||
| expect(profile).toEqual({ | ||
| hwVendors: ['ledger', 'onekey'], | ||
| primaryHwVendor: 'onekey', | ||
| }); | ||
| }); | ||
|
|
||
| it('breaks equal vendor counts by lexical order', () => { | ||
| const profile = computeHwVendorProfile([ | ||
| createWallet({ id: 'hw-onekey', type: 'hw' }), | ||
| createWallet({ | ||
| id: 'hw-ledger', | ||
| type: 'hw', | ||
| vendor: EHardwareVendor.ledger, | ||
| }), | ||
| ]); | ||
|
|
||
| expect(profile.primaryHwVendor).toBe('ledger'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('shouldReportAnalyticsWalletProfile', () => { | ||
| const now = 2 * WALLET_PROFILE_ANALYTICS_INTERVAL_MS; | ||
|
|
||
| it('allows the first report', () => { | ||
| expect( | ||
| shouldReportAnalyticsWalletProfile({ | ||
| lastReportedAt: undefined, | ||
| now, | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('limits reports to once per 24 hours', () => { | ||
| expect( | ||
| shouldReportAnalyticsWalletProfile({ | ||
| lastReportedAt: now - WALLET_PROFILE_ANALYTICS_INTERVAL_MS + 1, | ||
| now, | ||
| }), | ||
| ).toBe(false); | ||
| expect( | ||
| shouldReportAnalyticsWalletProfile({ | ||
| lastReportedAt: now - WALLET_PROFILE_ANALYTICS_INTERVAL_MS, | ||
| now, | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
| }); |
89 changes: 89 additions & 0 deletions
89
packages/kit-bg/src/services/ServiceAccount/analyticsWalletProfile.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import type { IDBWallet } from '@onekeyhq/kit-bg/src/dbs/local/types'; | ||
| import type { IAnalyticsUserProfile } from '@onekeyhq/shared/src/analytics/type'; | ||
| import { WALLET_TYPE_HW } from '@onekeyhq/shared/src/consts/dbConsts'; | ||
| import accountUtils from '@onekeyhq/shared/src/utils/accountUtils'; | ||
| import type { IBotWalletMetadataMap } from '@onekeyhq/shared/types/botWallet'; | ||
| import { EHardwareVendor } from '@onekeyhq/shared/types/device'; | ||
|
|
||
| type IHwVendorProfileWallet = Pick<IDBWallet, 'type' | 'associatedDeviceInfo'>; | ||
|
|
||
| export const WALLET_PROFILE_ANALYTICS_INTERVAL_MS = 24 * 60 * 60 * 1000; | ||
|
|
||
| export function shouldReportAnalyticsWalletProfile({ | ||
| lastReportedAt, | ||
| now, | ||
| }: { | ||
| lastReportedAt: number | undefined; | ||
| now: number; | ||
| }) { | ||
| return ( | ||
| lastReportedAt === undefined || | ||
| now - lastReportedAt >= WALLET_PROFILE_ANALYTICS_INTERVAL_MS | ||
| ); | ||
| } | ||
|
|
||
| export function computeHwVendorProfile( | ||
| wallets: readonly IHwVendorProfileWallet[], | ||
| ): { | ||
| hwVendors: string[]; | ||
| primaryHwVendor: string | undefined; | ||
| } { | ||
| const hwWallets = wallets.filter((wallet) => wallet.type === WALLET_TYPE_HW); | ||
| if (hwWallets.length === 0) { | ||
| return { hwVendors: [], primaryHwVendor: undefined }; | ||
| } | ||
| const counts = hwWallets.reduce<Record<string, number>>((acc, wallet) => { | ||
| const vendor = | ||
| wallet.associatedDeviceInfo?.vendor ?? EHardwareVendor.onekey; | ||
| acc[vendor] = (acc[vendor] ?? 0) + 1; | ||
| return acc; | ||
| }, {}); | ||
| const hwVendors = Object.keys(counts).toSorted(); | ||
| const primaryHwVendor = hwVendors.reduce((leader, vendor) => | ||
| counts[vendor] > counts[leader] ? vendor : leader, | ||
| ); | ||
| return { hwVendors, primaryHwVendor }; | ||
| } | ||
|
|
||
| export function buildAnalyticsWalletProfile({ | ||
| wallets, | ||
| botWalletMetadata, | ||
| }: { | ||
| wallets: readonly IDBWallet[]; | ||
| botWalletMetadata: IBotWalletMetadataMap; | ||
| }): IAnalyticsUserProfile | undefined { | ||
| const visibleWallets = wallets.filter((wallet) => { | ||
| if (!accountUtils.isBotWallet({ walletId: wallet.id })) { | ||
| return true; | ||
| } | ||
| return botWalletMetadata[wallet.id]?.visible === true; | ||
| }); | ||
| const walletCount = visibleWallets.length; | ||
| if (walletCount === 0) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const hwWalletCount = visibleWallets.filter( | ||
| (wallet) => wallet.type === WALLET_TYPE_HW, | ||
| ).length; | ||
| const visibleWalletMap = new Map( | ||
| visibleWallets.map((wallet) => [wallet.id, wallet]), | ||
| ); | ||
| const keylessWalletCount = visibleWallets.filter((wallet) => { | ||
| if (!wallet.isKeyless) { | ||
| return false; | ||
| } | ||
| const parentWalletId = accountUtils.parseBotWalletId(wallet.id)?.parentId; | ||
| return !parentWalletId || !visibleWalletMap.get(parentWalletId)?.isKeyless; | ||
| }).length; | ||
| const { hwVendors, primaryHwVendor } = computeHwVendorProfile(visibleWallets); | ||
|
|
||
| return { | ||
| walletCount, | ||
| hwWalletCount, | ||
| appWalletCount: walletCount - hwWalletCount, | ||
| keylessWalletCount, | ||
| hwVendors, | ||
| primaryHwVendor, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.