diff --git a/_raw/locales/en/messages.json b/_raw/locales/en/messages.json index 2230de39eb3..caf81392074 100644 --- a/_raw/locales/en/messages.json +++ b/_raw/locales/en/messages.json @@ -1823,7 +1823,8 @@ "manage-addresses-under-this-seed-phrase": "Manage addresses under this Seed Phrase", "safeModuleAddress": "Safe Module Address", "coboSafeErrorModule": "Address has expired, please delete and import the address again.", - "importedDelegatedAddress": "Imported Delegated address" + "importedDelegatedAddress": "Imported Delegated address", + "display-address-on-device": "Display address on device" }, "preferMetamaskDapps": { "title": "MetaMask Preferred Dapps", diff --git a/src/background/index.ts b/src/background/index.ts index 01dc06b7b58..1a920761599 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -11,6 +11,7 @@ import { EVENTS, EVENTS_IN_BG, KEYRING_CATEGORY_MAP, + KEYRING_CLASS, KEYRING_TYPE, } from 'consts'; import { storage } from './webapi'; @@ -138,6 +139,28 @@ async function restoreAppState() { }, }); } + if (message.type === 'displayAddressOnDevice') { + const ledgerKeyring = keyringService.getKeyringByType( + KEYRING_CLASS.HARDWARE.LEDGER + ); + if ( + ledgerKeyring && + typeof ledgerKeyring.displayAddressOnDevice === 'function' + ) { + ledgerKeyring + .displayAddressOnDevice(message.address) + .then(() => { + console.log('Address displayed successfully.'); + }) + .catch((error) => { + console.error('Error displaying address:', error); + }); + } else { + console.error( + 'LedgerBridgeKeyring instance not found or method unavailable.' + ); + } + } }); } diff --git a/src/background/service/keyring/eth-ledger-keyring.ts b/src/background/service/keyring/eth-ledger-keyring.ts index a6aa30d6996..a3e7f286aed 100644 --- a/src/background/service/keyring/eth-ledger-keyring.ts +++ b/src/background/service/keyring/eth-ledger-keyring.ts @@ -639,6 +639,18 @@ class LedgerBridgeKeyring { }; } + async displayAddressOnDevice(address: string) { + await this.makeApp(); + + const { hdPath } = this.accountDetails[ethUtil.toChecksumAddress(address)]; + if (!hdPath) { + throw new Error(`No HD path found for address: ${address}`); + } + + const result = await this.app!.getAddress(hdPath, true, true); + console.log('Address displayed on device:', result.address); + } + async getCurrentAccounts() { await this.unlock(); const addresses = await this.getAccounts(); diff --git a/src/ui/views/AddressDetail/AddressInfo.tsx b/src/ui/views/AddressDetail/AddressInfo.tsx index 0f2e5679718..d0956cd1bf6 100644 --- a/src/ui/views/AddressDetail/AddressInfo.tsx +++ b/src/ui/views/AddressDetail/AddressInfo.tsx @@ -274,6 +274,34 @@ const AddressInfo1 = ({ address, type, brandName, source }: Props) => { )} + {accountInfo && type === KEYRING_CLASS.HARDWARE.LEDGER && ( +