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: HardWallet connection tip #3326

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

fix: HardWallet connection tip #3326

wants to merge 2 commits into from

Conversation

devchenyan
Copy link
Collaborator

Comment on lines 419 to 421
error === ErrorCode.DeviceNotFound ||
error === ErrorCode.CkbAppNotFound ||
error === ErrorCode.DeviceNotMatchWallet
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can use [].includes(error) to avoid chained || conditions

@@ -424,14 +428,16 @@ export const useHardWallet = ({ wallet, t }: { wallet: State.WalletIdentity; t:
const ensureDeviceAvailable = useCallback(
async (device: State.DeviceInfo) => {
try {
const connectionRes = await connectDevice(device)
const connectionRes = await connectDevice({ ...device, walletID: wallet.id })
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why should walletID be overriden by wallet.id

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The device does not contain walletID field.

@Keith-CY Keith-CY requested a review from Copilot March 10, 2025 06:21

Choose a reason for hiding this comment

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

PR Overview

This PR adds a new error case to address mismatches between the connected hardware wallet and the expected wallet, ensuring that devices are correctly verified before further operations.

  • Introduces a new DeviceNotMatchWallet exception in the UI and wallet packages.
  • Updates API, controller, and remote services to handle an optional walletID parameter for device connection.
  • Modifies various hooks and components to incorporate the new error state and message for device-wallet mismatches.

Reviewed Changes

File Description
packages/neuron-ui/src/exceptions/hardware.ts Adds DeviceNotMatchWalletException with a static message for localization.
packages/neuron-wallet/src/controllers/hardware.ts Updates connectDevice to destructure and check walletID and validate the matching of public keys.
packages/neuron-wallet/src/exceptions/hardware.ts Introduces DeviceNotMatchWallet with an error code for wallet-device mismatches.
packages/neuron-ui/src/utils/enums.ts Adds a new error code (408) for DeviceNotMatchWallet.
packages/neuron-ui/src/components/CellManagement/hooks.ts, Receive/VerifyHardwareAddress.tsx, HardwareSign/hooks.ts Updates import and error handling to account for the new DeviceNotMatchWallet error condition.
packages/neuron-wallet/src/controllers/api.ts Adjusts the API handler to pass the walletID parameter when connecting devices.
packages/neuron-ui/src/services/remote/hardware.ts Updates the connectDevice API to support an extended payload with walletID.

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

packages/neuron-wallet/src/exceptions/hardware.ts:23

  • [nitpick] For consistency with the UI exception naming, consider renaming 'DeviceNotMatchWallet' to 'DeviceNotMatchWalletException' and adding a descriptive error message property similar to the pattern used in other exception classes.
export class DeviceNotMatchWallet extends Error {
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.

2 participants