Skip to content

Devop/trezor conditional#699

Merged
kvhnuke merged 11 commits intodevop/release-v-2-7-0from
devop/trezor-conditional
May 29, 2025
Merged

Devop/trezor conditional#699
kvhnuke merged 11 commits intodevop/release-v-2-7-0from
devop/trezor-conditional

Conversation

@kvhnuke
Copy link
Contributor

@kvhnuke kvhnuke commented May 22, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced transaction verification UI to display both sender and recipient addresses with identicons, improving transaction detail visibility.
  • Style

    • Updated transaction verification styles for improved readability, including new label styling and font adjustments.
  • Chores

    • Updated hardware wallet package dependencies and version.
    • Improved hardware wallet integration for Trezor devices, centralizing and streamlining initialization and usage.

@github-actions
Copy link

github-actions bot commented May 22, 2025

💼 Build Files
chrome: enkrypt-chrome-5892e972.zip
firefox: enkrypt-firefox-5892e972.zip

💉 Virus total analysis
chrome: 5892e972
firefox: 5892e972

@coderabbitai
Copy link

coderabbitai bot commented May 22, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (3)
  • main
  • develop
  • devop/vite-migrate

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce a new dynamic initialization approach for TrezorConnect in the hardware wallet package, centralizing environment-specific logic in a new helper. The Ethereum extension UI is updated to display both sender and recipient addresses with identicons, and related styles are adjusted. Dependency versions are updated in the hardware wallet package.

Changes

File(s) Change Summary
packages/hw-wallets/src/trezor/trezorConnect.ts Added a new helper function getTrezorConnect to dynamically import and initialize TrezorConnect based on the runtime environment (web extension or web), with appropriate manifest and transport options.
packages/hw-wallets/src/trezor/bitcoin/index.ts,
.../ethereum/index.ts,
.../solana/index.ts
Refactored to use the new getTrezorConnect helper for dynamic initialization and instance-based access to TrezorConnect. Removed direct imports and static initialization. Updated all method calls to use the instance property. Some error handling and response payload access were slightly adjusted.
packages/hw-wallets/package.json Updated version from 0.0.4 to 0.0.6. Added @trezor/connect-web as a dev dependency. Changed @ledgerhq/live-common from a caret version to a fixed version.
packages/extension/src/providers/ethereum/ui/eth-verify-transaction.vue Enhanced the transaction verification UI to show both "From" and "To" sections with labels and identicons. Introduced a new reactive variable for the recipient's identicon and updated the logic to display it. Explicitly sized the favicon image.
packages/extension/src/providers/common/ui/styles/verify-transaction.less Added and updated CSS classes for labels and account info, adjusting font sizes, weights, colors, and spacing for improved transaction detail visibility.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Extension UI
    participant eth-verify-transaction.vue

    User->>Extension UI: Initiate transaction verification
    Extension UI->>eth-verify-transaction.vue: Render verification component
    eth-verify-transaction.vue->>eth-verify-transaction.vue: Decode transaction
    eth-verify-transaction.vue->>eth-verify-transaction.vue: Generate identicon for "From" address
    eth-verify-transaction.vue->>eth-verify-transaction.vue: Generate identicon for "To" address
    eth-verify-transaction.vue-->>Extension UI: Display "From" and "To" sections with identicons
    Extension UI-->>User: Show enhanced transaction verification UI
Loading
sequenceDiagram
    participant App
    participant TrezorEthereum/Solana/Bitcoin
    participant getTrezorConnect
    participant TrezorConnect

    App->>TrezorEthereum/Solana/Bitcoin: Call init()
    TrezorEthereum/Solana/Bitcoin->>getTrezorConnect: await getTrezorConnect()
    getTrezorConnect->>TrezorConnect: Import & initialize (env-specific)
    getTrezorConnect-->>TrezorEthereum/Solana/Bitcoin: Return TrezorConnect instance
    TrezorEthereum/Solana/Bitcoin-->>App: TrezorConnect ready for use (instance property)
Loading

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kvhnuke kvhnuke changed the base branch from develop to feat/add-to-address May 22, 2025 21:32
Copy link

@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: 5

🧹 Nitpick comments (1)
packages/extension/src/providers/ethereum/ui/eth-verify-transaction.vue (1)

203-203: Consider improving the default identicon initialization.

The identicon is initialized with an empty address. Consider using a placeholder or loading state until the actual recipient address is known.

-const identiconTo = ref<string>(network.value.identicon(''));
+const identiconTo = ref<string>(network.value.identicon('0x0000000000000000000000000000000000000000'));
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97bd787 and a375ae9.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (7)
  • packages/extension/src/providers/common/ui/styles/verify-transaction.less (2 hunks)
  • packages/extension/src/providers/ethereum/ui/eth-verify-transaction.vue (5 hunks)
  • packages/hw-wallets/package.json (3 hunks)
  • packages/hw-wallets/src/trezor/bitcoin/index.ts (6 hunks)
  • packages/hw-wallets/src/trezor/ethereum/index.ts (7 hunks)
  • packages/hw-wallets/src/trezor/solana/index.ts (4 hunks)
  • packages/hw-wallets/src/trezor/trezorConnect.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/hw-wallets/src/trezor/solana/index.ts (3)
packages/hw-wallets/src/types.ts (3)
  • getAddressRequest (74-76)
  • AddressResponse (31-34)
  • SolSignTransaction (61-63)
packages/hw-wallets/src/trezor/solana/configs.ts (1)
  • supportedPaths (8-8)
packages/utils/src/index.ts (1)
  • bufferToHex (38-38)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: buildAll
🔇 Additional comments (19)
packages/extension/src/providers/common/ui/styles/verify-transaction.less (2)

10-16: Good addition of consistent label styling.

The new label styling provides proper visual hierarchy and consistency with app design language. The margins (44px left) align properly with the layout structure, ensuring the labels are positioned correctly relative to the account icons.


177-182: Font styling adjustments improve readability of transaction addresses.

The font weight, size, and color changes make the recipient address more prominent and readable. The use of !important flags ensures these styles take precedence over inherited styles, which is appropriate in this case for ensuring consistent display.

packages/extension/src/providers/ethereum/ui/eth-verify-transaction.vue (4)

14-16: Good addition of proper section labeling.

Adding a clear "From" label improves UI clarity and matches the new "To" section structure, creating a consistent transaction verification interface.


40-40: Explicit image dimensions prevent layout shifts.

Adding width and height attributes to the favicon is good practice as it prevents layout shifts during image loading and ensures consistent sizing.


83-96: Great addition of recipient address display.

Adding a dedicated "To" section with identicon significantly improves transaction verification by making the recipient address clearly visible. This is an important security improvement as it helps users verify they're sending funds to the correct address.


237-239: Properly updates recipient identicon during transaction decoding.

Good implementation of updating the recipient's identicon when the transaction is decoded, ensuring the visual representation matches the actual recipient address.

packages/hw-wallets/src/trezor/trezorConnect.ts (1)

23-24: Inconsistent appUrl value between environments

The appUrl for the web environment is set to "http://www.myetherwallet.com" while the extension environment uses "https://www.enkrypt.com".

Verify if this inconsistency is intentional. If it's not, consider updating both environments to use the same appUrl value.

packages/hw-wallets/package.json (3)

3-3: Version bump from 0.0.4 to 0.0.6

The package version has been bumped from 0.0.4 to 0.0.6, skipping 0.0.5.

This is acceptable assuming there's a reason for skipping version 0.0.5, such as a previous unreleased change.


25-25: Added @trezor/connect-web dependency

Adding the @trezor/connect-web dependency is necessary to support the new dynamic import mechanism.


61-61: Fixed @ledgerhq/live-common version

The version specification for @ledgerhq/live-common was changed from a caret range (^34.20.0) to a fixed version (34.20.0).

Was this change intentional? Using a fixed version prevents receiving bug fixes from patch releases. Consider keeping the caret range unless there's a specific reason to pin this version.

packages/hw-wallets/src/trezor/bitcoin/index.ts (3)

5-6: Updated imports for dynamic TrezorConnect loading

The imports have been properly updated to support dynamic TrezorConnect loading, replacing the direct import with a type import and the helper function.

Also applies to: 16-16


19-20: Added TrezorConnect class property

Adding the TrezorConnect property to the class is the correct approach for storing the dynamically imported instance.


38-38: Updated TrezorConnect method calls

All calls to TrezorConnect methods now correctly use the instance property.

Also applies to: 78-78, 93-93

packages/hw-wallets/src/trezor/ethereum/index.ts (4)

6-6: Updated imports for dynamic TrezorConnect loading

The imports have been properly updated to support dynamic TrezorConnect loading, replacing the direct import with a type import and the helper function.

Also applies to: 16-16


19-20: Added TrezorConnect class property

Adding the TrezorConnect property to the class is the correct approach for storing the dynamically imported instance.


38-45: Updated error handling style

The error handling has been updated to cast the payload as any before accessing the error property.


74-79: Updated TrezorConnect method calls

All calls to TrezorConnect methods now correctly use the instance property, and error handling has been updated consistently.

Also applies to: 96-103, 115-123

packages/hw-wallets/src/trezor/solana/index.ts (2)

1-1: Good architectural change: centralized TrezorConnect initialization

The refactoring to use an asynchronous helper function (getTrezorConnect) for initializing TrezorConnect improves code organization by centralizing environment-specific logic. This pattern allows the same code to work across different environments (web vs extension) without duplicating initialization logic.

Also applies to: 15-15, 19-19, 28-28


40-41:

Details

✅ Verification successful

Use different variables for address and publicKey

It appears that both address and publicKey are set to the same value. Is this intentional? Typically, an address and a public key are different (an address is often derived from a public key but in a different format).


🏁 Script executed:

#!/bin/bash
# Verify if address and publicKey should be different in Solana
grep -r "address.*publicKey" --include="*.ts" --include="*.js" packages/hw-wallets/src/

Length of output: 186


I’d like to inspect the surrounding context in both files to confirm intended behavior:


🏁 Script executed:

#!/bin/bash
# Show 3 lines of context around address/publicKey in both Ledger-Bitcoin and Trezor-Solana adapters
rg -n -C3 "address:" packages/hw-wallets/src/ledger/bitcoin/index.ts
rg -n -C3 "publicKey:" packages/hw-wallets/src/ledger/bitcoin/index.ts
rg -n -C3 "address:" packages/hw-wallets/src/trezor/solana/index.ts
rg -n -C3 "publicKey:" packages/hw-wallets/src/trezor/solana/index.ts

Length of output: 1571


No changes required: Solana addresses are the public key

In Solana, the “address” is just the public key encoded in Base58. Decoding that address and converting to hex for both address and publicKey is intentional and mirrors the Ledger-Bitcoin adapter’s approach.

Comment on lines 3 to 28
const getTrezorConnect = async () => {
if (chrome.runtime) {
const TrezorConnect = (await import("@trezor/connect-webextension"))
.default;
await TrezorConnect.init({
manifest: {
email: "info@enkrypt.com",
appUrl: "https://www.enkrypt.com",
},
transports: ["BridgeTransport", "WebUsbTransport"],
connectSrc: "https://connect.trezor.io/9/",
_extendWebextensionLifetime: true,
});
return TrezorConnect as TrezorConnectType;
} else {
const TrezorConnect = (await import("@trezor/connect-web")).default;
await TrezorConnect.init({
lazyLoad: true,
manifest: {
email: "info@enkrypt.com",
appUrl: "http://www.myetherwallet.com",
},
});
return TrezorConnect as TrezorConnectType;
}
};
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance error handling and add environment check safety

The implementation of the getTrezorConnect function is well-structured, but it lacks error handling for potential failures during initialization and has an unsafe environment check.

Consider implementing these improvements:

 const getTrezorConnect = async () => {
-  if (chrome.runtime) {
+  if (typeof chrome !== 'undefined' && chrome.runtime) {
     const TrezorConnect = (await import("@trezor/connect-webextension"))
       .default;
-    await TrezorConnect.init({
-      manifest: {
-        email: "info@enkrypt.com",
-        appUrl: "https://www.enkrypt.com",
-      },
-      transports: ["BridgeTransport", "WebUsbTransport"],
-      connectSrc: "https://connect.trezor.io/9/",
-      _extendWebextensionLifetime: true,
-    });
-    return TrezorConnect as TrezorConnectType;
+    try {
+      await TrezorConnect.init({
+        manifest: {
+          email: "info@enkrypt.com",
+          appUrl: "https://www.enkrypt.com",
+        },
+        transports: ["BridgeTransport", "WebUsbTransport"],
+        connectSrc: "https://connect.trezor.io/9/",
+        _extendWebextensionLifetime: true,
+      });
+      return TrezorConnect as TrezorConnectType;
+    } catch (error) {
+      console.error("Failed to initialize Trezor Connect WebExtension:", error);
+      throw error;
+    }
   } else {
     const TrezorConnect = (await import("@trezor/connect-web")).default;
-    await TrezorConnect.init({
-      lazyLoad: true,
-      manifest: {
-        email: "info@enkrypt.com",
-        appUrl: "http://www.myetherwallet.com",
-      },
-    });
-    return TrezorConnect as TrezorConnectType;
+    try {
+      await TrezorConnect.init({
+        lazyLoad: true,
+        manifest: {
+          email: "info@enkrypt.com",
+          appUrl: "http://www.myetherwallet.com",
+        },
+      });
+      return TrezorConnect as TrezorConnectType;
+    } catch (error) {
+      console.error("Failed to initialize Trezor Connect Web:", error);
+      throw error;
+    }
   }
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const getTrezorConnect = async () => {
if (chrome.runtime) {
const TrezorConnect = (await import("@trezor/connect-webextension"))
.default;
await TrezorConnect.init({
manifest: {
email: "info@enkrypt.com",
appUrl: "https://www.enkrypt.com",
},
transports: ["BridgeTransport", "WebUsbTransport"],
connectSrc: "https://connect.trezor.io/9/",
_extendWebextensionLifetime: true,
});
return TrezorConnect as TrezorConnectType;
} else {
const TrezorConnect = (await import("@trezor/connect-web")).default;
await TrezorConnect.init({
lazyLoad: true,
manifest: {
email: "info@enkrypt.com",
appUrl: "http://www.myetherwallet.com",
},
});
return TrezorConnect as TrezorConnectType;
}
};
const getTrezorConnect = async () => {
if (typeof chrome !== 'undefined' && chrome.runtime) {
const TrezorConnect = (await import("@trezor/connect-webextension")).default;
try {
await TrezorConnect.init({
manifest: {
email: "info@enkrypt.com",
appUrl: "https://www.enkrypt.com",
},
transports: ["BridgeTransport", "WebUsbTransport"],
connectSrc: "https://connect.trezor.io/9/",
_extendWebextensionLifetime: true,
});
return TrezorConnect as TrezorConnectType;
} catch (error) {
console.error("Failed to initialize Trezor Connect WebExtension:", error);
throw error;
}
} else {
const TrezorConnect = (await import("@trezor/connect-web")).default;
try {
await TrezorConnect.init({
lazyLoad: true,
manifest: {
email: "info@enkrypt.com",
appUrl: "http://www.myetherwallet.com",
},
});
return TrezorConnect as TrezorConnectType;
} catch (error) {
console.error("Failed to initialize Trezor Connect Web:", error);
throw error;
}
}
};
🤖 Prompt for AI Agents
In packages/hw-wallets/src/trezor/trezorConnect.ts around lines 3 to 28, the
getTrezorConnect function lacks error handling for initialization failures and
uses an unsafe environment check with chrome.runtime. Wrap the import and
initialization code in try-catch blocks to handle and log errors gracefully.
Replace the direct chrome.runtime check with a safer environment detection
method to avoid runtime errors in non-browser contexts.

Comment on lines 28 to 30
async init(): Promise<boolean> {
TrezorConnect.init({
manifest: {
email: "info@enkrypt.com",
appUrl: "https://www.enkrypt.com",
},
transports: ["BridgeTransport", "WebUsbTransport"],
connectSrc: "https://connect.trezor.io/9/",
_extendWebextensionLifetime: true,
});
this.TrezorConnect = await getTrezorConnect();
return true;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Updated init method for dynamic loading

The init method now properly uses the getTrezorConnect helper to dynamically load and initialize TrezorConnect.

Consider adding error handling to gracefully handle initialization failures:

 async init(): Promise<boolean> {
-   this.TrezorConnect = await getTrezorConnect();
-   return true;
+   try {
+     this.TrezorConnect = await getTrezorConnect();
+     return true;
+   } catch (error) {
+     console.error("Failed to initialize Trezor Connect:", error);
+     return false;
+   }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async init(): Promise<boolean> {
TrezorConnect.init({
manifest: {
email: "info@enkrypt.com",
appUrl: "https://www.enkrypt.com",
},
transports: ["BridgeTransport", "WebUsbTransport"],
connectSrc: "https://connect.trezor.io/9/",
_extendWebextensionLifetime: true,
});
this.TrezorConnect = await getTrezorConnect();
return true;
async init(): Promise<boolean> {
try {
this.TrezorConnect = await getTrezorConnect();
return true;
} catch (error) {
console.error("Failed to initialize Trezor Connect:", error);
return false;
}
}
🤖 Prompt for AI Agents
In packages/hw-wallets/src/trezor/bitcoin/index.ts around lines 28 to 30, the
init method currently calls getTrezorConnect without error handling. Update the
method to include a try-catch block around the await getTrezorConnect() call to
catch any initialization errors. In the catch block, log the error and return
false to indicate failure, ensuring the method gracefully handles initialization
failures.

Comment on lines 28 to 30
async init(): Promise<boolean> {
TrezorConnect.init({
manifest: {
email: "info@enkrypt.com",
appUrl: "https://www.enkrypt.com",
},
transports: ["BridgeTransport", "WebUsbTransport"],
connectSrc: "https://connect.trezor.io/9/",
_extendWebextensionLifetime: true,
});
this.TrezorConnect = await getTrezorConnect();
return true;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Updated init method for dynamic loading

The init method now properly uses the getTrezorConnect helper to dynamically load and initialize TrezorConnect.

Consider adding error handling to gracefully handle initialization failures:

 async init(): Promise<boolean> {
-   this.TrezorConnect = await getTrezorConnect();
-   return true;
+   try {
+     this.TrezorConnect = await getTrezorConnect();
+     return true;
+   } catch (error) {
+     console.error("Failed to initialize Trezor Connect:", error);
+     return false;
+   }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async init(): Promise<boolean> {
TrezorConnect.init({
manifest: {
email: "info@enkrypt.com",
appUrl: "https://www.enkrypt.com",
},
transports: ["BridgeTransport", "WebUsbTransport"],
connectSrc: "https://connect.trezor.io/9/",
_extendWebextensionLifetime: true,
});
this.TrezorConnect = await getTrezorConnect();
return true;
async init(): Promise<boolean> {
try {
this.TrezorConnect = await getTrezorConnect();
return true;
} catch (error) {
console.error("Failed to initialize Trezor Connect:", error);
return false;
}
}
🤖 Prompt for AI Agents
In packages/hw-wallets/src/trezor/ethereum/index.ts around lines 28 to 30, the
init method currently calls getTrezorConnect without error handling. Modify the
init method to include a try-catch block that attempts to assign
this.TrezorConnect using await getTrezorConnect(), and returns true if
successful. In the catch block, log or handle the error appropriately and return
false to indicate initialization failure.

Comment on lines +40 to +41
address: bufferToHex(base58.decode((res.payload as any).address)),
publicKey: bufferToHex(base58.decode((res.payload as any).address)),
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid type casting to any - define proper types instead

Type casting to any bypasses TypeScript's type checking system, which can lead to runtime errors if the expected properties don't exist. Consider creating proper interfaces that extend the TrezorConnect response types.

- address: bufferToHex(base58.decode((res.payload as any).address)),
- publicKey: bufferToHex(base58.decode((res.payload as any).address)),
+ address: bufferToHex(base58.decode((res.payload as SolanaGetAddressResponse).address)),
+ publicKey: bufferToHex(base58.decode((res.payload as SolanaGetAddressResponse).address)),

And similarly for the transaction signature:

- }).then((result) => (result.payload as any).signature);
+ }).then((result) => (result.payload as SolanaSignTransactionResponse).signature);

You'll need to define these interfaces (if they don't already exist in the TrezorConnect types):

interface SolanaGetAddressResponse {
  address: string;
  // other properties...
}

interface SolanaSignTransactionResponse {
  signature: string;
  // other properties...
}

Also applies to: 67-67

🤖 Prompt for AI Agents
In packages/hw-wallets/src/trezor/solana/index.ts around lines 40-41 and line
67, avoid using type casting to 'any' for the TrezorConnect response payload.
Instead, define proper TypeScript interfaces representing the expected response
structure, such as SolanaGetAddressResponse with an 'address' property and
SolanaSignTransactionResponse with a 'signature' property. Then, use these
interfaces to type the response payloads, enabling type-safe access to
properties without bypassing TypeScript's checks.

Comment on lines +28 to 30
return true;
}

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling to init() method

The init() method doesn't handle potential errors from getTrezorConnect(). In production environments, initialization could fail for various reasons (connection issues, permissions, etc.).

async init(): Promise<boolean> {
-  this.TrezorConnect = await getTrezorConnect();
-  return true;
+  try {
+    this.TrezorConnect = await getTrezorConnect();
+    return true;
+  } catch (error) {
+    console.error('Failed to initialize TrezorConnect:', error);
+    return false;
+  }
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this.TrezorConnect = await getTrezorConnect();
return true;
}
async init(): Promise<boolean> {
try {
this.TrezorConnect = await getTrezorConnect();
return true;
} catch (error) {
console.error('Failed to initialize TrezorConnect:', error);
return false;
}
}
🤖 Prompt for AI Agents
In packages/hw-wallets/src/trezor/solana/index.ts around lines 28 to 30, the
init() method calls getTrezorConnect() without handling possible errors. Modify
the init() method to wrap the await getTrezorConnect() call in a try-catch
block, catch any errors thrown during the call, and handle them appropriately,
such as logging the error or rethrowing it, to ensure the method fails
gracefully in case of initialization issues.

@kvhnuke kvhnuke changed the base branch from feat/add-to-address to devop/release-v-2-7-0 May 29, 2025 18:17
@kvhnuke kvhnuke merged commit 1c2c7f6 into devop/release-v-2-7-0 May 29, 2025
4 of 5 checks passed
@kvhnuke kvhnuke deleted the devop/trezor-conditional branch May 29, 2025 18:19
@coderabbitai coderabbitai bot mentioned this pull request May 29, 2025
@kvhnuke kvhnuke restored the devop/trezor-conditional branch May 29, 2025 21:50
This was referenced May 29, 2025
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