-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #515 from threshold-network/ledger-live-implementa…
…tion 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](https://www.ledger.com/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/](https://developers.ledger.com/docs/dapp-connect-kit/introduction/) Note: Most info down below are from [the documentation](https://developers.ledger.com/docs/dapp-connect-kit/introduction/). 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)](https://www.youtube.com/watch?v=YbsrsbodpzQ), 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](https://developers.ledger.com/docs/dapp-connect-kit/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: #### 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. - 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. #### 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. For more information about modal behaviour please check [https://developers.ledger.com/docs/dapp-connect-kit/button-behaviour/](https://developers.ledger.com/docs/dapp-connect-kit/button-behaviour/).
- Loading branch information
Showing
19 changed files
with
354 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/components/Modal/SelectWalletModal/ConnectLedgerLive.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { FC } from "react" | ||
import { useWeb3React } from "@web3-react/core" | ||
import { ledgerLive } from "../../../web3/connectors" | ||
import { WalletConnectionModalBase } from "./components" | ||
import { ConnectionError, WalletType } from "../../../enums" | ||
import doesErrorInclude from "../../../web3/utils/doesErrorInclude" | ||
import { LedgerLight } from "../../../static/icons/LedgerLight" | ||
import { LedgerDark } from "../../../static/icons/LedgerDark" | ||
import { useColorModeValue } from "@threshold-network/components" | ||
|
||
const ConnectLedgerLive: FC<{ goBack: () => void; closeModal: () => void }> = ({ | ||
goBack, | ||
closeModal, | ||
}) => { | ||
const { activate, error } = useWeb3React() | ||
|
||
const connectionRejected = doesErrorInclude( | ||
error, | ||
ConnectionError.RejectedMetamaskConnection | ||
) | ||
|
||
const walletIcon = useColorModeValue(LedgerLight, LedgerDark) | ||
|
||
return ( | ||
<WalletConnectionModalBase | ||
connector={ledgerLive} | ||
goBack={goBack} | ||
closeModal={closeModal} | ||
WalletIcon={walletIcon} | ||
title="Ledger Live" | ||
subTitle={ | ||
!error | ||
? "The Ledger Live extension will open in an external window." | ||
: "" | ||
} | ||
tryAgain={connectionRejected ? () => activate(ledgerLive) : undefined} | ||
walletType={WalletType.LedgerLive} | ||
shouldForceCloseModal | ||
/> | ||
) | ||
} | ||
|
||
export default ConnectLedgerLive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { createIcon } from "@chakra-ui/icons" | ||
|
||
export const LedgerDark = createIcon({ | ||
displayName: "Ledger", | ||
viewBox: "0 0 160 160", | ||
path: ( | ||
<svg | ||
width="160" | ||
height="160" | ||
viewBox="0 0 160 160" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<rect width="160" height="160" rx="16" fill="#00000D" /> | ||
<path | ||
d="M93.1482 119.207V125H135V98.8769H128.902V119.207H93.1482ZM93.1482 33V38.792H128.902V59.1231H135V33H93.1482ZM74.0104 59.1231H67.9125V98.8769H95.4153V93.6539H74.0104V59.1231ZM26 98.8769V125H67.8518V119.207H32.0979V98.8769H26ZM26 33V59.1231H32.0979V38.792H67.8518V33H26Z" | ||
fill="white" | ||
/> | ||
</svg> | ||
), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { createIcon } from "@chakra-ui/icons" | ||
|
||
export const LedgerLight = createIcon({ | ||
displayName: "Ledger", | ||
viewBox: "0 0 160 160", | ||
path: ( | ||
<svg | ||
width="160" | ||
height="160" | ||
viewBox="0 0 160 160" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<rect width="160" height="160" rx="16" fill="white" /> | ||
<path | ||
d="M93.1482 119.207V125H135V98.8769H128.902V119.207H93.1482ZM93.1482 33V38.792H128.902V59.1231H135V33H93.1482ZM74.0104 59.1231H67.9125V98.8769H95.4153V93.6539H74.0104V59.1231ZM26 98.8769V125H67.8518V119.207H32.0979V98.8769H26ZM26 33V59.1231H32.0979V38.792H67.8518V33H26Z" | ||
fill="#00000D" | ||
/> | ||
</svg> | ||
), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.