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

Ledger live implementation #515

Merged
merged 32 commits into from
Aug 16, 2023
Merged

Ledger live implementation #515

merged 32 commits into from
Aug 16, 2023

Conversation

michalsmiarowski
Copy link
Contributor

@michalsmiarowski michalsmiarowski commented May 15, 2023

🔶 Ledger Live Implementation 🔶

This pull request introduces a new feature to support Ledger Live integration in web3 applications using the @ledgerhq/connect-kit-loader package. This newly created connector allows users to connect their wallets through
Ledger Live app directly to the application and sign transactions securely. It also allows them to connect their Ledger Nano device directly to the web3 app by using Ledger Extension (available only on Safari).

Changes

  1. Added a new LedgerConnector class in the connectors directory to handle the Ledger Live integration.
  2. Integrated the @ledgerhq/connect-kit-loader package as a dependency to facilitate communication with Ledger devices.
  3. Implemented necessary methods in the LedgerConnector class to handle connection, account retrieval etc.
  4. Added Ledger Live option in SelectWalletModal component so that the LedgerLive is displayed as one of the options when connecting to the dApp.

Ledger Live documentation

https://developers.ledger.com/docs/dapp-connect-kit/introduction/

Note: Most info down below are from the documentation. Check it out for more context!

The @ledgerhq/connect-kit-loader package provides a simple way to integrate Ledger Live into web3 applications. The package handles communication with Ledger devices, allowing users to manage accounts, sign transactions, and access other blockchain-related features. This pull request leverages the package to implement a web3-react connector for Ledger Live, providing a seamless experience for users with Ledger hardware wallets. For more info about the impementation see https://developers.ledger.com/docs/dapp-connect-kit/implementation/ (Custom integration chapter)

How it works

The DApp Connect Kit lets you connect your DApps to Ledger hardware wallets. It has two components:

  • Ledger Extension (intro video), that makes it easy to connect your Nano to Web3 directly from your browser, and also includes an advanced mechanism to verify the security of the DApp. See Web3 Check.
  • Ledger Live which is a mobile and desktop application working as hardware wallet synchronization manager and allowing Ledger users to buy, swap, grow, and manage their digital assets from the security of their hardware wallet.

Supported platforms

  • Ledger Extension: is available on Safari for all Apple devices (requires iOS16+ or MacOS 12+). Support for other desktop browsers will be added in 2023.

  • Ledger Live mobile app: Native mobile apps and other browsers on iOS and Android will trigger the Ledger Live app using a WalletConnect deeplink. Both Ledger Live on iOS and Android can also be used to connect on desktop via the WalletConnect QRcode.

  • Ledger Live desktop app: Used as a fall back on desktop browsers until the Ledger Extension support is added, and for USB connections.

If user is using Safari then he will be asked to use or install Ledger Extension. If he uses any other browser then the modal will let him use or install either Ledger Live mobile app or Ledger Live desktop app.

Example of usage

After clicking Connect wallet user will see the Ledger Live option as one of the methods to connect:

Screenshot

image

Case 1 - Safari browser

  • Case 1.1 - User doesn't have the extenstion installed.

Result: Display a modal to guide the user with the setup process of the browser extension, or the enable setting.

Screenshot

image

  • Case 1.2 - User has the extenstion installed.

Result: On the first use, user is prompted to select and account to connect to dApp. Otherwise it autoconnects with the preciously used account. If you want the dApp to ask you again then you need to press Clear storage in the extension options.

Screenshot

image

Case 2 - Browser other than Safari

  • Case 2.1 Ledger Live is installed

Result: Open a modal from which Ledger Live can be opened. If user is already connected through Ledger Live then we connect him automatically.

Screenshot

image

For more information about modal behaviour please check https://developers.ledger.com/docs/dapp-connect-kit/button-behaviour/

@github-actions
Copy link

For both dark mode and light mode.
Adds four listeners to the ledger live procider:
- networkChanged
- chainChanged
- accountsChanged
- close

Also removes them in `deactivate` method.
@github-actions
Copy link

1 similar comment
@github-actions
Copy link

There was an error which happened after clicking `Disconnect` while being
connected with a Ledger wallet. To fix that we simply remove the
`this.provider = undefined`
line form the `deactivate` method as it is not necessary.
@github-actions
Copy link

src/web3/connectors/ledger_live.ts Outdated Show resolved Hide resolved
src/web3/connectors/ledger_live.ts Outdated Show resolved Hide resolved
src/web3/connectors/ledger_live.ts Outdated Show resolved Hide resolved
src/web3/connectors/ledger_live.ts Outdated Show resolved Hide resolved
src/web3/connectors/ledger_live.ts Outdated Show resolved Hide resolved
@r-czajkowski r-czajkowski added this to the v1.9.0 milestone May 19, 2023
We call `activate` method in the `WalletConnectionModalBase` already.
ledger_live -> ledgerLive
The `provider` is already marked as `optional` so we don't have to type it as
possibly undefined.
@github-actions
Copy link

github-actions bot commented Jun 9, 2023

@michalsmiarowski
Copy link
Contributor Author

I've updated the @ledgerhq/connect-kit-loader version to 1.1.0 so that it supports wallet connect v2. You can see the changes in df848ca and 66224b1.

@github-actions
Copy link

@mhluongo mhluongo self-requested a review July 24, 2023 15:36
Adds `shouldForceCloseModal` property to `WalletConnectionModalBase` component.
@michalsmiarowski michalsmiarowski modified the milestones: v1.9.0, v1.10.0 Jul 25, 2023
@github-actions
Copy link

r-czajkowski
r-czajkowski previously approved these changes Jul 26, 2023
Copy link
Collaborator

@r-czajkowski r-czajkowski left a comment

Choose a reason for hiding this comment

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

Left one minor comment. Let's fix it and I'm good to merge.

@github-actions
Copy link

@michalsmiarowski michalsmiarowski force-pushed the ledger-live-implementation branch 3 times, most recently from 2b058ba to 98a6086 Compare July 27, 2023 07:39
@github-actions
Copy link

2 similar comments
@github-actions
Copy link

@github-actions
Copy link

@github-actions
Copy link

Pass wallet connect project id through ledger live constructor.
@github-actions
Copy link

1 similar comment
@github-actions
Copy link

Update `@ledgerhq/connect-kit-loader` lib to 1.1.2.
@github-actions
Copy link

Sometime there is an error "Cannot convert undefined or null to object"
when trying to connect to walletconnect or ledger live. To reproduce it
(before the fix in this commit of course) you should:
1. Connect through Ledger Live
2. Disconnect
3. Connect through Ledger Live again (with the same account)
4. Disconnect
5. Connect through WalletConnect (it should automatically connect with
the same account that you used while connecting to Ledger Live)
6. Disconnect
7. Connect again through Ledger Live
8. The error should appear

The similar issue was descibed here: WalletConnect/walletconnect-monorepo#3165

This commit fixes that issue by clearing out the local storage from the
walleconnect realted data.
Copy link
Collaborator

@r-czajkowski r-czajkowski left a comment

Choose a reason for hiding this comment

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

LGTM!

@github-actions
Copy link

@r-czajkowski r-czajkowski merged commit 22643ad into main Aug 16, 2023
5 checks passed
@r-czajkowski r-czajkowski deleted the ledger-live-implementation branch August 16, 2023 07:43
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.

3 participants