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

Feat: Add Button to Display Address on Ledger #2591

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion _raw/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 23 additions & 0 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
EVENTS,
EVENTS_IN_BG,
KEYRING_CATEGORY_MAP,
KEYRING_CLASS,
KEYRING_TYPE,
} from 'consts';
import { storage } from './webapi';
Expand Down Expand Up @@ -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.'
);
}
}
});
}

Expand Down
12 changes: 12 additions & 0 deletions src/background/service/keyring/eth-ledger-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
28 changes: 28 additions & 0 deletions src/ui/views/AddressDetail/AddressInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,34 @@ const AddressInfo1 = ({ address, type, brandName, source }: Props) => {
</div>
)}

{accountInfo && type === KEYRING_CLASS.HARDWARE.LEDGER && (
<div className="rabby-list-item">
<div
className="rabby-list-item-content cursor-pointer"
onClick={() => {
chrome.runtime.sendMessage(
{
type: 'displayAddressOnDevice',
address: address,
},
(response) => {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
} else {
console.log('Response:', response);
}
}
);
}}
>
<div className="rabby-list-item-label">
{t('page.addressDetail.display-address-on-device')}
</div>
<div className="rabby-list-item-extra"></div>
</div>
</div>
)}

{isGnosis ? (
<GnonisSafeInfo address={address} type={type} brandName={brandName} />
) : null}
Expand Down