Skip to content

Commit

Permalink
feat: useMountEffect to direct connect ledgerlive if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Oct 5, 2023
1 parent 94af0a2 commit 063edbd
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 33 deletions.
12 changes: 11 additions & 1 deletion src/contexts/useWeb3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {createContext, useCallback, useContext, useMemo, useState} from '
import assert from 'assert';
import {useAccount, useConnect, useDisconnect, useEnsName, useNetwork, usePublicClient, useSwitchNetwork, useWalletClient, WagmiConfig} from 'wagmi';
import * as _RainbowKitProvider from '@rainbow-me/rainbowkit';
import {useIsMounted, useUpdateEffect} from '@react-hookz/web';
import {useIsMounted, useMountEffect, useUpdateEffect} from '@react-hookz/web';

import {toast} from '../components/yToast.js';
import {toAddress} from '../utils/address.js';
Expand Down Expand Up @@ -72,6 +72,16 @@ export const Web3ContextAppWrapper = ({children, options}: {children: ReactEleme
set_currentChainID(chain?.id);
}, [chain]);

useMountEffect(async (): Promise<void> => {
if (isIframe()) {
const ledgerConnector = connectors.find((c): boolean => c.id === 'ledgerLive');
if (ledgerConnector) {
await connectAsync({connector: ledgerConnector, chainId: chain?.id || 1});
return;
}
}
});

const onConnect = useCallback(async (): Promise<void> => {
const ledgerConnector = connectors.find((c): boolean => c.id === 'ledgerLive');
if (isIframe() && ledgerConnector) {
Expand Down
2 changes: 0 additions & 2 deletions src/utils/wagmi/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export const localhost = {
rpcUrls: {
default: {http: ['http://localhost:8545', 'http://0.0.0.0:8545']},
public: {http: ['http://localhost:8545', 'http://0.0.0.0:8545']}
// default: {http: ['http://168.119.147.211:4200']},
// public: {http: ['http://168.119.147.211:4200']}
},
contracts: {
ensRegistry: {
Expand Down
197 changes: 167 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,22 @@
abitype "0.8.7"
eventemitter3 "^4.0.7"

"@wagmi/[email protected]":
version "3.1.2"
resolved "https://registry.yarnpkg.com/@wagmi/connectors/-/connectors-3.1.2.tgz#4fd33fc4061ffb53c68860a203f099c6cac649c3"
integrity sha512-IlLKErqCzQRBUcCvXGPowcczbWcvJtEG006gPsAoePNJEXCHEWoKASghgu+L/bqD7006Z6mW6zlTNjcSQJvFAg==
dependencies:
"@coinbase/wallet-sdk" "^3.6.6"
"@ledgerhq/connect-kit-loader" "^1.1.0"
"@safe-global/safe-apps-provider" "^0.17.1"
"@safe-global/safe-apps-sdk" "^8.0.0"
"@walletconnect/ethereum-provider" "2.10.1"
"@walletconnect/legacy-provider" "^2.0.0"
"@walletconnect/modal" "2.6.2"
"@walletconnect/utils" "2.10.1"
abitype "0.8.7"
eventemitter3 "^4.0.7"

"@wagmi/[email protected]":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@wagmi/core/-/core-1.4.1.tgz#808a44260e1149709649b6ab2b4425988edbdd02"
Expand All @@ -1940,6 +1956,16 @@
eventemitter3 "^4.0.7"
zustand "^4.3.1"

"@wagmi/core@^1.4.2":
version "1.4.3"
resolved "https://registry.yarnpkg.com/@wagmi/core/-/core-1.4.3.tgz#1dfe1492b3cc1579d18fa07c88a9cfb82111ffcc"
integrity sha512-CIV9jwv5ue+WpqmA3FvwGa+23cppe7oIaz6TRnlGm0Hm0wDImSaQSWqcsFyOPvleD29oOIJ8e3KnHINEvI64AA==
dependencies:
"@wagmi/connectors" "3.1.2"
abitype "0.8.7"
eventemitter3 "^4.0.7"
zustand "^4.3.1"

"@walletconnect/[email protected]":
version "2.10.0"
resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.10.0.tgz#b659de4dfb374becd938964abd4f2150d410e617"
Expand All @@ -1962,6 +1988,28 @@
lodash.isequal "4.5.0"
uint8arrays "^3.1.0"

"@walletconnect/[email protected]":
version "2.10.1"
resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.10.1.tgz#d1fb442bd77424666bacdb0f5a07f7708fb3d984"
integrity sha512-WAoXfmj+Zy5q48TnrKUjmHXJCBahzKwbul+noepRZf7JDtUAZ9IOWpUjg+UPRbfK5EiWZ0TF42S6SXidf7EHoQ==
dependencies:
"@walletconnect/heartbeat" "1.2.1"
"@walletconnect/jsonrpc-provider" "1.0.13"
"@walletconnect/jsonrpc-types" "1.0.3"
"@walletconnect/jsonrpc-utils" "1.0.8"
"@walletconnect/jsonrpc-ws-connection" "1.0.13"
"@walletconnect/keyvaluestorage" "^1.0.2"
"@walletconnect/logger" "^2.0.1"
"@walletconnect/relay-api" "^1.0.9"
"@walletconnect/relay-auth" "^1.0.4"
"@walletconnect/safe-json" "^1.0.2"
"@walletconnect/time" "^1.0.2"
"@walletconnect/types" "2.10.1"
"@walletconnect/utils" "2.10.1"
events "^3.3.0"
lodash.isequal "4.5.0"
uint8arrays "^3.1.0"

"@walletconnect/crypto@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@walletconnect/crypto/-/crypto-1.0.3.tgz#7b8dd4d7e2884fe3543c7c07aea425eef5ef9dd4"
Expand Down Expand Up @@ -2005,6 +2053,21 @@
"@walletconnect/utils" "2.10.0"
events "^3.3.0"

"@walletconnect/[email protected]":
version "2.10.1"
resolved "https://registry.yarnpkg.com/@walletconnect/ethereum-provider/-/ethereum-provider-2.10.1.tgz#4733a98f0b388cf5ae6c2b269f50da87da432ee5"
integrity sha512-Yhoz8EXkKzxOlBT6G+elphqCx/gkH6RxD9/ZAiy9lLc8Ng5p1gvKCVVP5zsGNE9FbkKmHd+J9JJRzn2Bw2yqtQ==
dependencies:
"@walletconnect/jsonrpc-http-connection" "^1.0.7"
"@walletconnect/jsonrpc-provider" "^1.0.13"
"@walletconnect/jsonrpc-types" "^1.0.3"
"@walletconnect/jsonrpc-utils" "^1.0.8"
"@walletconnect/sign-client" "2.10.1"
"@walletconnect/types" "2.10.1"
"@walletconnect/universal-provider" "2.10.1"
"@walletconnect/utils" "2.10.1"
events "^3.3.0"

"@walletconnect/events@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@walletconnect/events/-/events-1.0.1.tgz#2b5f9c7202019e229d7ccae1369a9e86bda7816c"
Expand Down Expand Up @@ -2152,6 +2215,13 @@
dependencies:
valtio "1.11.0"

"@walletconnect/[email protected]":
version "2.6.2"
resolved "https://registry.yarnpkg.com/@walletconnect/modal-core/-/modal-core-2.6.2.tgz#d73e45d96668764e0c8668ea07a45bb8b81119e9"
integrity sha512-cv8ibvdOJQv2B+nyxP9IIFdxvQznMz8OOr/oR/AaUZym4hjXNL/l1a2UlSQBXrVjo3xxbouMxLb3kBsHoYP2CA==
dependencies:
valtio "1.11.2"

"@walletconnect/[email protected]":
version "2.6.1"
resolved "https://registry.yarnpkg.com/@walletconnect/modal-ui/-/modal-ui-2.6.1.tgz#200c54c8dfe3c71321abb2724e18bb357dfd6371"
Expand All @@ -2162,6 +2232,16 @@
motion "10.16.2"
qrcode "1.5.3"

"@walletconnect/[email protected]":
version "2.6.2"
resolved "https://registry.yarnpkg.com/@walletconnect/modal-ui/-/modal-ui-2.6.2.tgz#fa57c087c57b7f76aaae93deab0f84bb68b59cf9"
integrity sha512-rbdstM1HPGvr7jprQkyPggX7rP4XiCG85ZA+zWBEX0dVQg8PpAgRUqpeub4xQKDgY7pY/xLRXSiCVdWGqvG2HA==
dependencies:
"@walletconnect/modal-core" "2.6.2"
lit "2.8.0"
motion "10.16.2"
qrcode "1.5.3"

"@walletconnect/[email protected]":
version "2.6.1"
resolved "https://registry.yarnpkg.com/@walletconnect/modal/-/modal-2.6.1.tgz#066fdbfcff83b58c8a9da66ab4af0eb93e3626de"
Expand All @@ -2170,6 +2250,14 @@
"@walletconnect/modal-core" "2.6.1"
"@walletconnect/modal-ui" "2.6.1"

"@walletconnect/[email protected]":
version "2.6.2"
resolved "https://registry.yarnpkg.com/@walletconnect/modal/-/modal-2.6.2.tgz#4b534a836f5039eeb3268b80be7217a94dd12651"
integrity sha512-eFopgKi8AjKf/0U4SemvcYw9zlLpx9njVN8sf6DAkowC2Md0gPU/UNEbH1Wwj407pEKnEds98pKWib1NN1ACoA==
dependencies:
"@walletconnect/modal-core" "2.6.2"
"@walletconnect/modal-ui" "2.6.2"

"@walletconnect/randombytes@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@walletconnect/randombytes/-/randombytes-1.0.3.tgz#e795e4918367fd1e6a2215e075e64ab93e23985b"
Expand Down Expand Up @@ -2222,6 +2310,21 @@
"@walletconnect/utils" "2.10.0"
events "^3.3.0"

"@walletconnect/[email protected]":
version "2.10.1"
resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.10.1.tgz#db60bc9400cd79f0cb2380067343512b21ee4749"
integrity sha512-iG3eJGi1yXeG3xGeVSSMf8wDFyx239B0prLQfy1uYDtYFb2ynnH/09oqAZyKn96W5nfQzUgM2Mz157PVdloH3Q==
dependencies:
"@walletconnect/core" "2.10.1"
"@walletconnect/events" "^1.0.1"
"@walletconnect/heartbeat" "1.2.1"
"@walletconnect/jsonrpc-utils" "1.0.8"
"@walletconnect/logger" "^2.0.1"
"@walletconnect/time" "^1.0.2"
"@walletconnect/types" "2.10.1"
"@walletconnect/utils" "2.10.1"
events "^3.3.0"

"@walletconnect/time@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@walletconnect/time/-/time-1.0.2.tgz#6c5888b835750ecb4299d28eecc5e72c6d336523"
Expand All @@ -2241,6 +2344,18 @@
"@walletconnect/logger" "^2.0.1"
events "^3.3.0"

"@walletconnect/[email protected]":
version "2.10.1"
resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.10.1.tgz#1355bce236f3eef575716ea3efe4beed98a873ef"
integrity sha512-7pccAhajQdiH2kYywjE1XI64IqRI+4ioyGy0wvz8d0UFQ/DSG3MLKR8jHf5aTOafQQ/HRLz6xvlzN4a7gIVkUQ==
dependencies:
"@walletconnect/events" "^1.0.1"
"@walletconnect/heartbeat" "1.2.1"
"@walletconnect/jsonrpc-types" "1.0.3"
"@walletconnect/keyvaluestorage" "^1.0.2"
"@walletconnect/logger" "^2.0.1"
events "^3.3.0"

"@walletconnect/[email protected]":
version "2.10.0"
resolved "https://registry.yarnpkg.com/@walletconnect/universal-provider/-/universal-provider-2.10.0.tgz#565d6478dcb5cc66955e5f03d6a00f51c9bcac14"
Expand All @@ -2256,6 +2371,21 @@
"@walletconnect/utils" "2.10.0"
events "^3.3.0"

"@walletconnect/[email protected]":
version "2.10.1"
resolved "https://registry.yarnpkg.com/@walletconnect/universal-provider/-/universal-provider-2.10.1.tgz#c4a77bd2eed1a335edae5b2b298636092fff63ef"
integrity sha512-81QxTH/X4dRoYCz0U9iOrBYOcj7N897ONcB57wsGhEkV7Rc9htmWJq2CzeOuxvVZ+pNZkE+/aw9LrhizO1Ltxg==
dependencies:
"@walletconnect/jsonrpc-http-connection" "^1.0.7"
"@walletconnect/jsonrpc-provider" "1.0.13"
"@walletconnect/jsonrpc-types" "^1.0.2"
"@walletconnect/jsonrpc-utils" "^1.0.7"
"@walletconnect/logger" "^2.0.1"
"@walletconnect/sign-client" "2.10.1"
"@walletconnect/types" "2.10.1"
"@walletconnect/utils" "2.10.1"
events "^3.3.0"

"@walletconnect/[email protected]":
version "2.10.0"
resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.10.0.tgz#6918d12180d797b8bd4a19fb2ff128e394e181d6"
Expand All @@ -2276,6 +2406,26 @@
query-string "7.1.3"
uint8arrays "^3.1.0"

"@walletconnect/[email protected]":
version "2.10.1"
resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.10.1.tgz#65b37c9800eb0e80a08385b6987471fb46e1e22e"
integrity sha512-DM0dKgm9O58l7VqJEyV2OVv16XRePhDAReI23let6WdW1dSpw/Y/A89Lp99ZJOjLm2FxyblMRF3YRaZtHwBffw==
dependencies:
"@stablelib/chacha20poly1305" "1.0.1"
"@stablelib/hkdf" "1.0.1"
"@stablelib/random" "^1.0.2"
"@stablelib/sha256" "1.0.1"
"@stablelib/x25519" "^1.0.3"
"@walletconnect/relay-api" "^1.0.9"
"@walletconnect/safe-json" "^1.0.2"
"@walletconnect/time" "^1.0.2"
"@walletconnect/types" "2.10.1"
"@walletconnect/window-getters" "^1.0.1"
"@walletconnect/window-metadata" "^1.0.1"
detect-browser "5.3.0"
query-string "7.1.3"
uint8arrays "^3.1.0"

"@walletconnect/window-getters@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@walletconnect/window-getters/-/window-getters-1.0.1.tgz#f36d1c72558a7f6b87ecc4451fc8bd44f63cbbdc"
Expand All @@ -2291,36 +2441,6 @@
"@walletconnect/window-getters" "^1.0.1"
tslib "1.14.1"

"@web3modal/[email protected]":
version "2.7.1"
resolved "https://registry.yarnpkg.com/@web3modal/core/-/core-2.7.1.tgz#257534d45f7b5d6bddbc667f787c094eb91dd281"
integrity sha512-eFWR1tK1qN4FguhaZq2VW0AVr8DC/Fox2eJnK1eTfk32hxSgUtl8wr5fVM8EoLeoapQ7Zcc0SNg/QLuLQ9t2tA==
dependencies:
valtio "1.11.0"

"@web3modal/ethereum@^2.7.1":
version "2.7.1"
resolved "https://registry.yarnpkg.com/@web3modal/ethereum/-/ethereum-2.7.1.tgz#464dbc1d00d075c16961b77e9a353b1966538653"
integrity sha512-1x3qhYh9qgtvw1MDQD4VeDf2ZOsVANKRPtUty4lF+N4L8xnAIwvNKUAMA4j6T5xSsjqUfq5Tdy5mYsNxLmsWMA==

"@web3modal/react@^2.7.1":
version "2.7.1"
resolved "https://registry.yarnpkg.com/@web3modal/react/-/react-2.7.1.tgz#c768aae41bfe15abe379f8b6489d69d153fc7a46"
integrity sha512-+zvP5Q7Q3ozW2hyA1NvS8giVDeZWA6PWgVhKA6656dCnOutonPUpWYuFPJahsFBYCrhLO8ApPmomgb6Dx/mh5A==
dependencies:
"@web3modal/core" "2.7.1"
"@web3modal/ui" "2.7.1"

"@web3modal/[email protected]":
version "2.7.1"
resolved "https://registry.yarnpkg.com/@web3modal/ui/-/ui-2.7.1.tgz#9c2cb0f66623fcf41084f50e63acff33f26b0635"
integrity sha512-JpGJbLAl/Wmuyyn+JwuwtlPD8mUW2HV/gsSxKWZoElgjbfDY4vjHo9PH2G++2HhugISfzjawp43r8lP/hWgWOQ==
dependencies:
"@web3modal/core" "2.7.1"
lit "2.7.6"
motion "10.16.2"
qrcode "1.5.3"

JSONStream@^1.3.5:
version "1.3.5"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
Expand Down Expand Up @@ -5142,6 +5262,15 @@ [email protected]:
lit-element "^3.3.0"
lit-html "^2.7.0"

[email protected]:
version "2.8.0"
resolved "https://registry.yarnpkg.com/lit/-/lit-2.8.0.tgz#4d838ae03059bf9cafa06e5c61d8acc0081e974e"
integrity sha512-4Sc3OFX9QHOJaHbmTMk28SYgVxLN3ePDjg7hofEft2zWlehFL3LiAuapWc4U/kYwMYJSh2hTCPZ6/LIC7ii0MA==
dependencies:
"@lit/reactive-element" "^1.6.0"
lit-element "^3.3.0"
lit-html "^2.8.0"

load-tsconfig@^0.2.3:
version "0.2.5"
resolved "https://registry.yarnpkg.com/load-tsconfig/-/load-tsconfig-0.2.5.tgz#453b8cd8961bfb912dea77eb6c168fe8cca3d3a1"
Expand Down Expand Up @@ -7027,6 +7156,14 @@ [email protected]:
proxy-compare "2.5.1"
use-sync-external-store "1.2.0"

[email protected]:
version "1.11.2"
resolved "https://registry.yarnpkg.com/valtio/-/valtio-1.11.2.tgz#b8049c02dfe65620635d23ebae9121a741bb6530"
integrity sha512-1XfIxnUXzyswPAPXo1P3Pdx2mq/pIqZICkWN60Hby0d9Iqb+MEIpqgYVlbflvHdrp2YR/q3jyKWRPJJ100yxaw==
dependencies:
proxy-compare "2.5.1"
use-sync-external-store "1.2.0"

[email protected]:
version "1.10.14"
resolved "https://registry.yarnpkg.com/viem/-/viem-1.10.14.tgz#f32ab489f36700987accd93daa9b43135e39bc8b"
Expand Down

0 comments on commit 063edbd

Please sign in to comment.