From e418a56e0954e342a8ae8b9beb80f1b88b9f797b Mon Sep 17 00:00:00 2001 From: Wenty Li <105278450+wenty22@users.noreply.github.com> Date: Fri, 1 Dec 2023 11:52:31 +0800 Subject: [PATCH] Dev (#47) * chore: prettier & eslint ignore changeset's md files * fix: No need refresh when open WalletConnect Modal in QRCode page * chore: Add vconsole for dev demo * fix: fixed trustwallet losing status after refreshing * chore: update release info * style: Update log output styles * style: Add switchNetwork log * refactor: update the `installed` field that detect whether wallet is installed to a function * fix: fixed conflict issue between trustwallet and metaMask * docs: update release docs --- .changeset/happy-hounds-complain.md | 5 ++++ .changeset/late-birds-compare.md | 5 ++++ .changeset/modern-comics-smell.md | 5 ++++ .changeset/pre.json | 4 +-- CONTRIBUTING.md | 4 +-- examples/nextjs/pages/_document.tsx | 2 ++ packages/walletkit/dev/index.html | 27 +++++++++++++++++ .../src/components/EthereumScript/index.tsx | 30 +++++++++++++++++++ .../walletkit/src/hooks/useClickWallet.ts | 7 +++-- packages/walletkit/src/hooks/useConnector.ts | 6 ---- .../src/hooks/useWalletConnectModal.ts | 2 +- .../src/hooks/useWalletKitConnect.ts | 8 +++-- .../src/hooks/useWalletKitSwitchNetwork.ts | 10 +++---- packages/walletkit/src/index.ts | 1 + .../walletkit/src/pages/Connecting/index.tsx | 10 ++++--- .../src/pages/SwitchNetwork/index.tsx | 4 ++- .../src/wallets/binanceWeb3Wallet/index.tsx | 6 +--- .../src/wallets/coinbaseWallet/index.tsx | 2 +- .../walletkit/src/wallets/injected/index.tsx | 2 +- .../src/wallets/mathWallet/index.tsx | 2 +- .../walletkit/src/wallets/metaMask/index.tsx | 2 +- .../walletkit/src/wallets/okxWallet/index.tsx | 4 +-- packages/walletkit/src/wallets/safe/index.tsx | 2 +- .../src/wallets/tokenPocket/icon.tsx | 2 +- .../src/wallets/tokenPocket/index.tsx | 4 +-- .../src/wallets/trustWallet/index.tsx | 8 ++--- packages/walletkit/src/wallets/types.ts | 2 +- .../src/wallets/walletConnect/index.tsx | 2 +- 28 files changed, 118 insertions(+), 50 deletions(-) create mode 100644 .changeset/happy-hounds-complain.md create mode 100644 .changeset/late-birds-compare.md create mode 100644 .changeset/modern-comics-smell.md create mode 100644 packages/walletkit/src/components/EthereumScript/index.tsx delete mode 100644 packages/walletkit/src/hooks/useConnector.ts diff --git a/.changeset/happy-hounds-complain.md b/.changeset/happy-hounds-complain.md new file mode 100644 index 00000000..17ddadad --- /dev/null +++ b/.changeset/happy-hounds-complain.md @@ -0,0 +1,5 @@ +--- +'@totejs/walletkit': patch +--- + +refactor: update the `installed` field that detect whether wallet is installed to a function diff --git a/.changeset/late-birds-compare.md b/.changeset/late-birds-compare.md new file mode 100644 index 00000000..2471f4e7 --- /dev/null +++ b/.changeset/late-birds-compare.md @@ -0,0 +1,5 @@ +--- +'@totejs/walletkit': patch +--- + +Fixed `WalletConnect` automatic connection issue in the follow scenario: connect the WalletConnect -> close browser -> reopen browser -> disconnect -> select WalletConnect, will automatically connect. diff --git a/.changeset/modern-comics-smell.md b/.changeset/modern-comics-smell.md new file mode 100644 index 00000000..55dfc42c --- /dev/null +++ b/.changeset/modern-comics-smell.md @@ -0,0 +1,5 @@ +--- +'@totejs/walletkit': patch +--- + +Fixed conflict issue between trustwallet and metaMask. diff --git a/.changeset/pre.json b/.changeset/pre.json index 4c0a1627..823a7d56 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -7,7 +7,5 @@ "@totejs/walletkit": "1.0.7-alpha.2", "website": "0.0.1" }, - "changesets": [ - "lovely-months-argue" - ] + "changesets": ["lovely-months-argue"] } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 632a16a3..7b2c647a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -117,7 +117,7 @@ export function trustWallet(props: TrustWalletProps = {}): WalletProps { default: 'https://trustwallet.com/', }, spinnerColor: '#1098FC', - installed: isTrustWallet(), + isInstalled: isTrustWallet, createConnector: (chains: Chain[]) => { return new TrustWalletConnector({ chains, @@ -163,7 +163,7 @@ export interface WalletProps { }; spinnerColor?: string; showQRCode?: boolean; - installed: boolean | undefined; + isInstalled: () => boolean | undefined; createConnector: (chains: Chain[]) => Connector; getDeepLink: () => string | undefined; getQRCodeUri?: (uri: string) => string; diff --git a/examples/nextjs/pages/_document.tsx b/examples/nextjs/pages/_document.tsx index 86b57f74..b4c55d0a 100644 --- a/examples/nextjs/pages/_document.tsx +++ b/examples/nextjs/pages/_document.tsx @@ -1,10 +1,12 @@ import { Html, Head, Main, NextScript } from 'next/document'; +import { EthereumScript } from '@totejs/walletkit'; export default function Document() { return ( WalletKit Next.js Example +
diff --git a/packages/walletkit/dev/index.html b/packages/walletkit/dev/index.html index f5e32244..07e23793 100644 --- a/packages/walletkit/dev/index.html +++ b/packages/walletkit/dev/index.html @@ -5,6 +5,33 @@ WalletKit Test Demo + diff --git a/packages/walletkit/src/components/EthereumScript/index.tsx b/packages/walletkit/src/components/EthereumScript/index.tsx new file mode 100644 index 00000000..1fb856d3 --- /dev/null +++ b/packages/walletkit/src/components/EthereumScript/index.tsx @@ -0,0 +1,30 @@ +export function EthereumScript() { + const scriptHtml = ` + (function() { + try { + const isMobile = + /android|iPhone|iPad|iPod/i.test(navigator.userAgent) || + (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1); + + if (!isMobile && window.ethereum && window.ethereum.isMetaMask && window.trustwallet) { + const originalEthereum = window.ethereum; + + Object.defineProperty(window, 'ethereum', { + enumerable: true, + configurable: true, + set(v) { + if (v.isTrust || v.isTrustWallet) return; + this.value = v; + }, + get() { + return this.value ?? originalEthereum; + }, + }); + } + } catch (err) { + console.error('[ethereum script]', err); + } + })() + `; + return