Skip to content

Conversation

@ByteZhang1024
Copy link
Contributor

@ByteZhang1024 ByteZhang1024 commented Dec 9, 2025

Summary by CodeRabbit

  • New Features
    • Detect and display device firmware type (Bitcoin-only or Universal) across device lists and wallet UIs.
    • Show Bitcoin network badge on account avatars for Bitcoin-only firmware devices.
    • Firmware-aware network selection for QR wallet address creation and wallet setup.
    • Device and wallet records now store app-level firmware type so firmware info is propagated during creation and updates.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 9, 2025

Walkthrough

This PR attaches an app-level firmware type to device features, adds helpers to compute and embed it, and propagates that data through device storage/update flows, QR-wallet network selection, firmware-aware UI badges, and related service logic.

Changes

Cohort / File(s) Change Summary
Firmware type types & helpers
packages/shared/src/types/device.ts, packages/shared/src/utils/deviceUtils.ts
Add IOneKeyDeviceFeaturesWithAppParams ($app_firmware_type?: EFirmwareType) and two helpers: getFirmwareTypeByCachedFeatures(...) and attachAppParamsToFeatures(...). Export helpers in module default.
Device persistence / versioning
packages/kit-bg/src/dbs/local/LocalDbBase.ts
Update updateDeviceVersionInfo signature to accept an object union where bitcoinOnlyFlag may include $app_firmware_type; use featuresInfo (app-augmented) when serializing/storing device features in update/create flows.
Hardware service firmware flags
packages/kit-bg/src/services/ServiceHardware/ServiceHardware.ts
Populate $app_firmware_type in bitcoinOnlyFlag for upgrade branches (Universal ↔ BitcoinOnly).
QR wallet / network selection
packages/kit-bg/src/services/ServiceQrWallet/ServiceQrWallet.ts
Make prepareQrcodeWalletAddressCreate firmware-aware: detect Bitcoin-only firmware via deviceUtils.getFirmwareType and, if so, use default BTC networks (allDefaultAddAccountNetworksIds) instead of the provided networkId.
UI — Account avatar badge
packages/kit/src/components/AccountAvatar/AccountAvatar.tsx
Infer firmware type from wallet.associatedDeviceInfo.featuresInfo and render a small BTC network overlay avatar when firmware is Bitcoin-only.
UI — Device management list & types
packages/kit/src/views/DeviceManagement/pages/DeviceManagementListModal/index.tsx
Add exported type IDeviceManagementListModalItem = IHwQrWalletWithDevice & { firmwareTypeBadge?: EFirmwareType }; asynchronously compute firmwareTypeBadge via deviceUtils.getFirmwareType for each device and pass it to wallet avatar.
UI — Wallet details header
packages/kit/src/views/AccountManagerStacks/pages/AccountSelectorStack/WalletDetails/WalletDetailsHeader/index.tsx
Compute firmware type from device?.featuresInfo and pass it as firmwareTypeBadge to WalletAvatar.
sequenceDiagram
  participant UI as App UI
  participant Service as Service (QR / Hardware)
  participant DeviceUtils as deviceUtils
  participant DB as LocalDb

  UI->>Service: Request prepare/create (QR or HW)
  Service->>DeviceUtils: attachAppParamsToFeatures / getFirmwareType
  DeviceUtils-->>Service: featuresInfo (includes $app_firmware_type)
  alt QR network selection
    Service->>Service: choose networks based on firmwareType
  end
  Service->>DB: updateDevice / createHwWallet with featuresInfo
  DB-->>Service: ack stored device (features include $app_firmware_type)
  Service-->>UI: return prepared data / networks / device info
  UI->>UI: render BTC badge/avatar when firmwareType == BitcoinOnly
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Pay attention to:
    • packages/kit-bg/src/dbs/local/LocalDbBase.ts: ensure feature serialization uses featuresInfo consistently and preserves existing fields.
    • packages/shared/src/utils/deviceUtils.ts: verify deterministic behavior and null/partial-feature handling in both helpers.
    • packages/kit-bg/src/services/ServiceQrWallet/ServiceQrWallet.ts: confirm network selection logic covers undefined features and isAllNetwork cases.
    • Async handling in DeviceManagementListModal/index.tsx and avatar components to avoid render race conditions or flicker.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title mentions BTC-only QR wallet creation with issue references, reflecting the main changes in feature implementation and issue resolutions.
Linked Issues check ✅ Passed PR implements BTC icon badges in device/wallet UIs (OK-47055), adds firmware-aware network selection to prevent non-BTC dApps without hardware calls (OK-47064), and modifies QR wallet creation logic (OK-47071).
Out of Scope Changes check ✅ Passed All changes directly support BTC-only firmware handling: new device feature integration, firmware type propagation, UI badges, and network filtering align with stated objectives.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch optimize/btcQr

Comment @coderabbitai help to get the list of available commands and usage tips.

@revan-zhang
Copy link
Contributor

revan-zhang commented Dec 9, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/kit-bg/src/services/ServiceQrWallet/ServiceQrWallet.ts (1)

238-256: Use cached firmware type instead of async SDK call for QR wallets

The new isBtcOnlyFirmware branch is useful for keeping BTC‑only QR wallets on BTC networks. However, deviceUtils.getFirmwareType will hit the hardware SDK and expects full device features, while byDevice?.featuresInfo for QR wallets is a small app-augmented object.

Since you already persist $app_firmware_type and have getFirmwareTypeByCachedFeatures, you can simplify and avoid unnecessary SDK usage:

-    const firmwareType = await deviceUtils.getFirmwareType({
-      features: byDevice?.featuresInfo,
-    });
-    const isBtcOnlyFirmware = firmwareType === EFirmwareType.BitcoinOnly;
+    const firmwareType = deviceUtils.getFirmwareTypeByCachedFeatures({
+      features: byDevice?.featuresInfo,
+    });
+    const isBtcOnlyFirmware = firmwareType === EFirmwareType.BitcoinOnly;

This keeps behavior the same for Bitcoin‑only (where $app_firmware_type is set) and treats missing/Universal types as “not BTC‑only” without involving the SDK.

packages/kit-bg/src/dbs/local/LocalDbBase.ts (1)

2359-2475: QR wallet firmware parsing is reasonable; consider documenting expected name format

createQrWallet now derives firmwareType from qrDevice.name (split on - for passphrase hash, then : for serialNo and firmwareStr) and stores it as $app_firmware_type inside featuresInfo. This is a neat, self-contained way to mark BTC-only QR devices.

Two small robustness points:

  • The code assumes a name:serial:fwType layout and treats only a third segment equal to 'btc' (case-insensitive) as Bitcoin-only. If the QR firmware ever tweaks this format, behavior will silently change.
  • For existing devices with non-empty features but no $app_firmware_type, the existingDevice branch only sets item.features when it was previously empty, so older QR devices won’t gain the new flag automatically.

If this format is stable, current code is fine. Otherwise, consider:

  • Adding a short comment about the expected qrDevice.name format, and/or
  • A small migration path that backfills $app_firmware_type for existing QR devices when you next see a firmwareStr.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a5e38ba and 2d2548e.

📒 Files selected for processing (7)
  • packages/kit-bg/src/dbs/local/LocalDbBase.ts (3 hunks)
  • packages/kit-bg/src/services/ServiceHardware/ServiceHardware.ts (3 hunks)
  • packages/kit-bg/src/services/ServiceQrWallet/ServiceQrWallet.ts (3 hunks)
  • packages/kit/src/components/AccountAvatar/AccountAvatar.tsx (4 hunks)
  • packages/kit/src/views/DeviceManagement/pages/DeviceManagementListModal/index.tsx (3 hunks)
  • packages/shared/src/utils/deviceUtils.ts (4 hunks)
  • packages/shared/types/device.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/kit/src/views/DeviceManagement/pages/DeviceManagementListModal/index.tsx (3)
packages/shared/types/account.ts (1)
  • IHwQrWalletWithDevice (56-59)
packages/kit/src/hooks/usePromiseResult.ts (1)
  • usePromiseResult (69-346)
packages/kit/src/components/WalletAvatar/WalletAvatar.tsx (1)
  • IWalletAvatarProps (22-26)
packages/kit/src/components/AccountAvatar/AccountAvatar.tsx (2)
packages/kit/src/components/NetworkAvatar/NetworkAvatar.tsx (1)
  • NetworkAvatar (82-127)
packages/shared/src/config/presetNetworks.ts (1)
  • presetNetworksMap (2897-3016)
packages/shared/src/utils/deviceUtils.ts (1)
packages/shared/types/device.ts (2)
  • IOneKeyDeviceFeatures (26-26)
  • IOneKeyDeviceFeaturesWithAppParams (28-30)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: lint (20.x)
  • GitHub Check: unittest (20.x)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (java-kotlin)
🔇 Additional comments (3)
packages/shared/types/device.ts (1)

28-30: New features-with-app-params type looks consistent

Extending IOneKeyDeviceFeatures with optional $app_firmware_type matches how you serialize features in LocalDbBase and consume them in deviceUtils. No issues from a typing or usage standpoint.

packages/kit-bg/src/services/ServiceHardware/ServiceHardware.ts (1)

1225-1279: Propagating $app_firmware_type on BTC-only transitions is correct

Setting $app_firmware_type when flipping between Universal and Bitcoin‑only keeps the cached featuresInfo in sync with the actual firmware type, and matches how updateDeviceVersionInfo merges bitcoinOnlyFlag into features. The logic for capabilities and vendor remains unchanged.

packages/kit-bg/src/dbs/local/LocalDbBase.ts (1)

2145-2156: Good centralization of app firmware type into stored features

Using deviceUtils.attachAppParamsToFeatures in both updateDevice and createHwWallet, then serializing via stableStringify, gives you a single, consistent place to derive and persist $app_firmware_type. Extending bitcoinOnlyFlag to carry $app_firmware_type also keeps version updates in sync with firmware transitions.

This wiring matches how deviceUtils.getFirmwareTypeByCachedFeatures and the various “is BTC-only” checks read from featuresInfo. No functional issues here.

Also applies to: 2224-2231, 2849-2853

import type { ReactElement } from 'react';
import { isValidElement, useMemo } from 'react';

import { EFirmwareType } from '@onekeyfe/hd-shared';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Tighten useMemo dependencies for firmwareType

firmwareType’s useMemo reads wallet but only depends on wallet?.associatedDeviceInfo?.featuresInfo. This can trip hook lint rules and, in edge cases, return stale values.

You can depend on wallet directly (or pre‑extract featuresInfo) to keep things in sync:

-  const firmwareType = useMemo(() => {
+  const firmwareType = useMemo(() => {
     if (!wallet) {
       return undefined;
     }
     return deviceUtils.getFirmwareTypeByCachedFeatures({
       features: wallet?.associatedDeviceInfo?.featuresInfo,
     });
-  }, [wallet?.associatedDeviceInfo?.featuresInfo]);
+  }, [wallet, wallet?.associatedDeviceInfo?.featuresInfo]);

Also applies to: 27-30, 150-157

Comment on lines +356 to +369
{firmwareType === EFirmwareType.BitcoinOnly ? (
<Stack
position="absolute"
h="$4"
px="$0.5"
justifyContent="center"
top={-4}
left={-4}
borderRadius="$full"
zIndex="$1"
>
<NetworkAvatar networkId={presetNetworksMap.btc.id} size={14} />
</Stack>
) : null}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Clarify when the BTC badge should render

The BTC NetworkAvatar badge always renders for Bitcoin‑only firmware, even if networkId is already BTC. This can lead to two BTC icons in the same corner.

If you want the badge to signal “BTC‑only device”, not duplicate the current network icon, guard on networkId:

-      {firmwareType === EFirmwareType.BitcoinOnly ? (
+      {firmwareType === EFirmwareType.BitcoinOnly &&
+      networkId !== presetNetworksMap.btc.id ? (
         <Stack
           position="absolute"
           h="$4"
           px="$0.5"
           justifyContent="center"
           top={-4}
           left={-4}
           borderRadius="$full"
           zIndex="$1"
         >
           <NetworkAvatar networkId={presetNetworksMap.btc.id} size={14} />
         </Stack>
       ) : null}
🤖 Prompt for AI Agents
In packages/kit/src/components/AccountAvatar/AccountAvatar.tsx around lines 356
to 369, the BTC NetworkAvatar badge is rendered for all Bitcoin‑only firmware
devices which can duplicate the visible network icon; change the render
condition to require both firmwareType === EFirmwareType.BitcoinOnly and
networkId !== presetNetworksMap.btc.id so the BTC badge only appears when the
current networkId is not already BTC (use the existing presetNetworksMap.btc.id
constant for the comparison).

Comment on lines +36 to +40
import type { EFirmwareType } from '@onekeyfe/hd-shared';

export type IDeviceManagementListModalItem = IHwQrWalletWithDevice & {
firmwareTypeBadge?: EFirmwareType;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Leverage cached firmware type to avoid async per-item SDK calls

Enriching each list item with firmwareTypeBadge is a good fit for DeviceManagementListModal. Right now you call deviceUtils.getFirmwareType in a for..of loop, which invokes the hardware SDK even though device.device?.featuresInfo already carries the app-level firmware type.

You can switch to the synchronous cache helper and drop the awaits:

-        const devices: Array<IDeviceManagementListModalItem> = Object.values(r)
+        const devices: Array<IDeviceManagementListModalItem> = Object.values(r)
           .filter(
             (item): item is IHwQrWalletWithDevice =>
               Boolean(item.device) && !item.wallet.deprecated,
           )
           .sort((a, b) => {
             // Sort by walletOrder or fallback to walletNo
             const orderA = a.wallet.walletOrder || a.wallet.walletNo;
             const orderB = b.wallet.walletOrder || b.wallet.walletNo;
             return orderA - orderB;
           });
 
-        for (const item of devices) {
-          const firmwareTypeBadge = await deviceUtils.getFirmwareType({
-            features: item.device?.featuresInfo,
-          });
-          item.firmwareTypeBadge = firmwareTypeBadge;
-        }
+        for (const item of devices) {
+          item.firmwareTypeBadge =
+            deviceUtils.getFirmwareTypeByCachedFeatures({
+              features: item.device?.featuresInfo,
+            });
+        }

This keeps UI behavior the same, avoids unnecessary async work in the render data path, and uses the same cached field you already store in featuresInfo.

Also applies to: 46-47, 53-71, 120-125

🤖 Prompt for AI Agents
In
packages/kit/src/views/DeviceManagement/pages/DeviceManagementListModal/index.tsx
around lines 36-40 (and also apply the same change at 46-47, 53-71, 120-125),
the code calls the async SDK helper to compute firmwareTypeBadge for each item;
instead, read the firmware type synchronously from device.device?.featuresInfo
(or use the synchronous cached helper provided in deviceUtils), remove the
awaits/async SDK calls inside the per-item loop and other locations, and set
firmwareTypeBadge directly from that cached value so the UI remains unchanged
while avoiding unnecessary async SDK calls.

Comment on lines +562 to +574
function getFirmwareTypeByCachedFeatures({
features,
}: {
features:
| (IOneKeyDeviceFeatures & { $app_firmware_type?: EFirmwareType })
| undefined;
}) {
if (!features) {
return EFirmwareType.Universal;
}

return features.$app_firmware_type;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Use cached $app_firmware_type more aggressively to avoid extra SDK calls

The new helpers are a solid addition:

  • getFirmwareTypeByCachedFeatures cleanly reads $app_firmware_type from stored features for UI and services.
  • attachAppParamsToFeatures centralizes augmenting features before persisting them.

Two refinements would reduce redundant SDK work and keep behavior simpler:

  1. Short-circuit getFirmwareType on any cached value, not just Bitcoin-only

Right now you only skip the SDK when $app_firmware_type === BitcoinOnly. For features that already carry Universal, you still call into sdkGetFirmwareType:

 async function getFirmwareType({
   features,
 }: {
   features:
     | (IOneKeyDeviceFeatures & { $app_firmware_type?: EFirmwareType })
     | undefined;
 }) {
   if (!features) {
     return EFirmwareType.Universal;
   }
 
-  if (
-    features.$app_firmware_type &&
-    features.$app_firmware_type === EFirmwareType.BitcoinOnly
-  ) {
-    return EFirmwareType.BitcoinOnly;
-  }
+  if (features.$app_firmware_type) {
+    return features.$app_firmware_type;
+  }
 
   const { getFirmwareType: sdkGetFirmwareType } = await CoreSDKLoader();
   return sdkGetFirmwareType(features);
 }
  1. Align getFirmwareTypeByCachedFeatures’s param type with IOneKeyDeviceFeaturesWithAppParams

You already declared IOneKeyDeviceFeaturesWithAppParams. Using it here makes the intent clearer and avoids duplicating the inline intersection:

-function getFirmwareTypeByCachedFeatures({
-  features,
-}: {
-  features:
-    | (IOneKeyDeviceFeatures & { $app_firmware_type?: EFirmwareType })
-    | undefined;
-}) {
+function getFirmwareTypeByCachedFeatures({
+  features,
+}: {
+  features: IOneKeyDeviceFeaturesWithAppParams | undefined;
+}) {

Both changes keep the external behavior the same but simplify the code path and reduce dependency on the hardware SDK for already-augmented feature blobs.

Also applies to: 576-596, 676-685, 687-722

🤖 Prompt for AI Agents
In packages/shared/src/utils/deviceUtils.ts around lines 562-574 (and similarly
apply the same changes to ranges 576-596, 676-685, 687-722), update
getFirmwareTypeByCachedFeatures to accept IOneKeyDeviceFeaturesWithAppParams as
its parameter type and to short-circuit whenever a cached $app_firmware_type
exists (return it directly) instead of only short-circuiting on BitcoinOnly;
then adjust callers that currently only bypass sdkGetFirmwareType for
BitcoinOnly so they use this helper to skip the SDK call whenever
$app_firmware_type is present, reducing duplicate SDK requests while preserving
existing behavior.

originalix
originalix previously approved these changes Dec 10, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (5)
packages/shared/src/utils/deviceUtils.ts (2)

576-596: Short-circuit on any cached firmware type.

Currently you only skip the SDK call when $app_firmware_type === BitcoinOnly. For features with Universal cached, you still hit the SDK.

Return any cached value directly:

 async function getFirmwareType({
   features,
 }: {
   features:
     | (IOneKeyDeviceFeatures & { $app_firmware_type?: EFirmwareType })
     | undefined;
 }) {
   if (!features) {
     return EFirmwareType.Universal;
   }

-  if (
-    features.$app_firmware_type &&
-    features.$app_firmware_type === EFirmwareType.BitcoinOnly
-  ) {
-    return EFirmwareType.BitcoinOnly;
+  if (features.$app_firmware_type) {
+    return features.$app_firmware_type;
   }

   const { getFirmwareType: sdkGetFirmwareType } = await CoreSDKLoader();
   return sdkGetFirmwareType(features);
 }

This reduces redundant SDK calls for already-augmented features.


562-574: Use the defined type instead of inline intersection.

You already declared IOneKeyDeviceFeaturesWithAppParams but duplicate the intersection inline.

Use the shared type for clarity:

 function getFirmwareTypeByCachedFeatures({
   features,
 }: {
-  features:
-    | (IOneKeyDeviceFeatures & { $app_firmware_type?: EFirmwareType })
-    | undefined;
+  features: IOneKeyDeviceFeaturesWithAppParams | undefined;
 }) {

Apply the same change to getFirmwareType (lines 576-596) and attachAppParamsToFeatures input (lines 676-685) for consistency.

packages/kit/src/components/AccountAvatar/AccountAvatar.tsx (2)

150-157: Tighten useMemo dependencies.

The hook depends on wallet?.associatedDeviceInfo but only reads wallet?.associatedDeviceInfo?.featuresInfo. This can cause stale values or unnecessary recalculations.

Depend on the specific nested field or the entire wallet:

  const firmwareType = useMemo(() => {
    if (!wallet?.associatedDeviceInfo) {
      return undefined;
    }
    return deviceUtils.getFirmwareTypeByCachedFeatures({
      features: wallet.associatedDeviceInfo?.featuresInfo,
    });
- }, [wallet?.associatedDeviceInfo]);
+ }, [wallet?.associatedDeviceInfo?.featuresInfo]);

356-369: Guard against duplicate BTC badge.

The badge renders for all Bitcoin-only firmware, even when networkId is already BTC. This can show two BTC icons in the same corner.

Only show the badge when the current network isn't BTC:

- {firmwareType === EFirmwareType.BitcoinOnly ? (
+ {firmwareType === EFirmwareType.BitcoinOnly &&
+  networkId !== presetNetworksMap.btc.id ? (
    <Stack
      position="absolute"
      h="$4"
      px="$0.5"
      justifyContent="center"
      top={-4}
      left={-4}
      borderRadius="$full"
      zIndex="$1"
    >
      <NetworkAvatar networkId={presetNetworksMap.btc.id} size={14} />
    </Stack>
  ) : null}
packages/kit/src/views/DeviceManagement/pages/DeviceManagementListModal/index.tsx (1)

65-71: Use cached firmware type to avoid async SDK calls.

The loop calls deviceUtils.getFirmwareType for each item, which hits the hardware SDK even though device.device?.featuresInfo already carries the app-level firmware type.

Switch to the synchronous cache helper:

        for (const item of devices) {
-         const firmwareTypeBadge = await deviceUtils.getFirmwareType({
+         item.firmwareTypeBadge =
+           deviceUtils.getFirmwareTypeByCachedFeatures({
            features: item.device?.featuresInfo,
          });
-         item.firmwareTypeBadge = firmwareTypeBadge;
        }

This avoids unnecessary async work in the render data path.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 502d734 and 4d11a00.

📒 Files selected for processing (8)
  • packages/kit-bg/src/dbs/local/LocalDbBase.ts (3 hunks)
  • packages/kit-bg/src/services/ServiceHardware/ServiceHardware.ts (3 hunks)
  • packages/kit-bg/src/services/ServiceQrWallet/ServiceQrWallet.ts (3 hunks)
  • packages/kit/src/components/AccountAvatar/AccountAvatar.tsx (4 hunks)
  • packages/kit/src/views/AccountManagerStacks/pages/AccountSelectorStack/WalletDetails/WalletDetailsHeader/index.tsx (3 hunks)
  • packages/kit/src/views/DeviceManagement/pages/DeviceManagementListModal/index.tsx (3 hunks)
  • packages/shared/src/utils/deviceUtils.ts (4 hunks)
  • packages/shared/types/device.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
packages/kit/src/views/AccountManagerStacks/pages/AccountSelectorStack/WalletDetails/WalletDetailsHeader/index.tsx (1)
packages/kit/src/components/WalletAvatar/WalletAvatar.tsx (1)
  • WalletAvatar (63-120)
packages/kit/src/components/AccountAvatar/AccountAvatar.tsx (2)
packages/kit/src/components/NetworkAvatar/NetworkAvatar.tsx (1)
  • NetworkAvatar (82-127)
packages/shared/src/config/presetNetworks.ts (1)
  • presetNetworksMap (2897-3016)
packages/shared/src/utils/deviceUtils.ts (1)
packages/shared/types/device.ts (2)
  • IOneKeyDeviceFeatures (26-26)
  • IOneKeyDeviceFeaturesWithAppParams (28-30)
packages/kit/src/views/DeviceManagement/pages/DeviceManagementListModal/index.tsx (3)
packages/shared/types/account.ts (1)
  • IHwQrWalletWithDevice (56-59)
packages/kit/src/hooks/usePromiseResult.ts (1)
  • usePromiseResult (69-346)
packages/kit/src/components/WalletAvatar/WalletAvatar.tsx (1)
  • IWalletAvatarProps (22-26)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: unittest (20.x)
  • GitHub Check: lint (20.x)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (java-kotlin)
🔇 Additional comments (5)
packages/shared/types/device.ts (1)

28-30: LGTM!

The type extension cleanly adds app-level firmware type tracking to device features.

packages/kit-bg/src/services/ServiceHardware/ServiceHardware.ts (1)

1225-1279: LGTM!

The firmware type propagation through upgrade flows is correct. The logic correctly assigns $app_firmware_type for both upgrade directions.

packages/kit-bg/src/services/ServiceQrWallet/ServiceQrWallet.ts (1)

252-256: LGTM!

The firmware-aware network selection correctly restricts to all default networks for BTC-only firmware, aligning with the PR objectives.

packages/kit-bg/src/dbs/local/LocalDbBase.ts (2)

2164-2177: Attaching app params before persisting features is a solid move

You now normalize features through attachAppParamsToFeatures and persist via stableStringify, which keeps device feature JSON consistent and makes change detection reliable. I don’t see functional issues here.


2246-2251: Extending bitcoinOnlyFlag with app firmware type matches the merge logic

Adding $app_firmware_type to the bitcoinOnlyFlag shape lines up with the spread into item.features and lets version updates override or inject firmware type cleanly. No problems spotted in this flow.

Comment on lines +2868 to 2872
const featuresInfo = await deviceUtils.attachAppParamsToFeatures({
features,
});
const featuresStr = JSON.stringify(featuresInfo);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider using stableStringify for HW featuresStr for consistency

Here you serialize featuresInfo with JSON.stringify, while updateDevice uses stringUtils.stableStringify. Using stableStringify here too would keep the stored features string canonical from first insert and avoid a one-time diff on the first updateDevice call.

-    const featuresInfo = await deviceUtils.attachAppParamsToFeatures({
-      features,
-    });
-    const featuresStr = JSON.stringify(featuresInfo);
+    const featuresInfo = await deviceUtils.attachAppParamsToFeatures({
+      features,
+    });
+    const featuresStr = stringUtils.stableStringify(featuresInfo);
🤖 Prompt for AI Agents
In packages/kit-bg/src/dbs/local/LocalDbBase.ts around lines 2868 to 2872, the
code uses JSON.stringify to serialize featuresInfo which causes a non-canonical
representation compared to updateDevice that uses stringUtils.stableStringify;
replace JSON.stringify(featuresInfo) with
stringUtils.stableStringify(featuresInfo) and ensure stringUtils is imported in
this file (or the correct stable stringify helper is referenced) so the stored
featuresStr is canonical from initial insert and avoids a one-time diff on first
updateDevice call.

Comment on lines +63 to +67
const firmwareType = useMemo(() => {
return deviceUtils.getFirmwareTypeByCachedFeatures({
features: device?.featuresInfo,
});
}, [device]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Tighten useMemo dependencies.

The hook depends on device but only reads device?.featuresInfo. This can cause stale closures or unnecessary recalculations.

Extract the nested value or depend on both for clarity:

  const firmwareType = useMemo(() => {
+   const features = device?.featuresInfo;
    return deviceUtils.getFirmwareTypeByCachedFeatures({
-     features: device?.featuresInfo,
+     features,
    });
- }, [device]);
+ }, [device?.featuresInfo]);
🤖 Prompt for AI Agents
In
packages/kit/src/views/AccountManagerStacks/pages/AccountSelectorStack/WalletDetails/WalletDetailsHeader/index.tsx
around lines 63 to 67, the useMemo currently lists [device] but only reads
device?.featuresInfo which can cause stale closures or extra recalcs; extract
the nested value (e.g. const features = device?.featuresInfo) and change the
useMemo dependency to that extracted value (or directly to device?.featuresInfo)
so the memo only reruns when features actually change.

@ByteZhang1024 ByteZhang1024 enabled auto-merge (squash) December 10, 2025 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants