Skip to content

Commit

Permalink
fix(wallet): fix ledger live (#3505)
Browse files Browse the repository at this point in the history
* chore: update ledger package to latest

* chore: move WC_PROJECT_ID to constants file

* refactor: remove redundant variable

* refactor: remove redundant awaits

* chore: use enum rather than casting

* feat: upgrate to WCv2 according to Ledger migration guide

https://developers.ledger.com/docs/connectivity/connect-kit/implementation#walletconnect-v2-migration-guide
  • Loading branch information
alfetopito authored Dec 13, 2023
1 parent 5ef0da8 commit e7efb50
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
2 changes: 2 additions & 0 deletions libs/wallet/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const WC_DISABLED_TEXT =
'Wallet-connect based wallet is already in use. Please disconnect it to connect to this wallet.'

export const WC_PROJECT_ID = process.env.REACT_APP_WC_PROJECT_ID || 'a6cc11517a10f6f12953fd67b1eb67e7'
4 changes: 1 addition & 3 deletions libs/wallet/src/web3-react/connection/walletConnectV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
getIsTrustWallet,
getIsZengoWallet,
} from '../../api/utils/connection'
import { WC_DISABLED_TEXT } from '../../constants'
import { WC_DISABLED_TEXT, WC_PROJECT_ID } from '../../constants'
import { ConnectWalletOption } from '../../api/pure/ConnectWalletOption'

export const walletConnectV2Option = {
Expand All @@ -33,8 +33,6 @@ export const walletConnectV2Option = {
id: 'wallet-connect-v2',
}

const WC_PROJECT_ID = process.env.REACT_APP_WC_PROJECT_ID || 'a6cc11517a10f6f12953fd67b1eb67e7'

function createWalletConnectV2Connector(chainId: SupportedChainId): [AsyncConnector, Web3ReactHooks, Web3ReactStore] {
return initializeConnector<AsyncConnector>(
(actions) =>
Expand Down
19 changes: 10 additions & 9 deletions libs/wallet/src/web3-react/connectors/LedgerConnector.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Web3Provider, ExternalProvider } from '@ethersproject/providers'
import { ExternalProvider, Web3Provider } from '@ethersproject/providers'
import { Actions, Connector, Provider, RequestArguments } from '@web3-react/types'

import type { LedgerConnectKit, SupportedProviders } from '@ledgerhq/connect-kit-loader'
import { LedgerConnectKit, SupportedProviders } from '@ledgerhq/connect-kit-loader'
import { WC_PROJECT_ID } from '../../constants'

type LedgerProvider = Provider & {
connected: () => boolean
Expand Down Expand Up @@ -42,11 +43,9 @@ export class Ledger extends Connector {

async getAccounts() {
const provider = await this.getProvider()
const accounts = (await provider.request({
return (await provider.request({
method: 'eth_requestAccounts',
})) as string[]

return accounts
}

async getChainId() {
Expand Down Expand Up @@ -79,13 +78,15 @@ export class Ledger extends Connector {
async activateLedgerKit() {
const connectKit = this.kit

await connectKit.enableDebugLogs()
connectKit.enableDebugLogs()

await connectKit.checkSupport({
providerType: 'Ethereum' as SupportedProviders,
connectKit.checkSupport({
providerType: SupportedProviders.Ethereum,
walletConnectVersion: 2,
projectId: WC_PROJECT_ID,
chainId: this.options.chainId,
infuraId: this.options.infuraId,
rpc: this.options.rpc,
rpcMap: this.options.rpc,
})
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@ethvault/iframe-provider": "^0.1.10",
"@fontsource/ibm-plex-mono": "^4.5.1",
"@fontsource/inter": "^4.5.1",
"@ledgerhq/connect-kit-loader": "^1.0.2",
"@ledgerhq/connect-kit-loader": "^1.1.2",
"@lingui/cli": "^4.3.0",
"@lingui/core": "^4.3.0",
"@lingui/macro": "^4.3.0",
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3103,12 +3103,7 @@
resolved "https://registry.yarnpkg.com/@juggle/resize-observer/-/resize-observer-3.4.0.tgz#08d6c5e20cf7e4cc02fd181c4b0c225cd31dbb60"
integrity sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==

"@ledgerhq/connect-kit-loader@^1.0.2":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/connect-kit-loader/-/connect-kit-loader-1.1.0.tgz#10343b78ef13436818bf3453568a559c0eeb9d48"
integrity sha512-HUy12FEczoWY2FPubnsm1uOA8tkVWc0j90i47suThV3C9NL2xx69ZAIEU3Ytzs2bwLek9S1Q2S1VQJvA+3Ygkg==

"@ledgerhq/connect-kit-loader@^1.1.0":
"@ledgerhq/connect-kit-loader@^1.1.0", "@ledgerhq/connect-kit-loader@^1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@ledgerhq/connect-kit-loader/-/connect-kit-loader-1.1.2.tgz#d550e3c1f046e4c796f32a75324b03606b7e226a"
integrity sha512-mscwGroSJQrCTjtNGBu+18FQbZYA4+q6Tyx6K7CXHl6AwgZKbWfZYdgP2F+fyZcRUdGRsMX8QtvU61VcGGtO1A==
Expand Down

0 comments on commit e7efb50

Please sign in to comment.