From 86426c062f7fa074dc23802f08a556bbe154783a Mon Sep 17 00:00:00 2001 From: wenty22 Date: Tue, 3 Dec 2024 00:22:40 +0800 Subject: [PATCH] feat: Support tg wallet --- .changeset/wise-days-juggle.md | 5 +++ packages/walletkit/__dev__/App.tsx | 20 +++++------ packages/walletkit/package.json | 2 +- .../HomeView/GridLayout/index.tsx | 28 +++++++++------ .../HomeView/ListLayout/index.tsx | 22 ++++++++---- .../ConnectModal/HomeView/Reload/index.tsx | 23 +++++++++++++ .../ConnectModal/HomeView/Reload/style.css.ts | 17 ++++++++++ .../components/SetEvmWalletClickRef/index.tsx | 4 +-- .../evm/wallets/binanceWeb3Wallet/index.tsx | 9 +++-- pnpm-lock.yaml | 34 +++++++++---------- 10 files changed, 115 insertions(+), 49 deletions(-) create mode 100644 .changeset/wise-days-juggle.md create mode 100644 packages/walletkit/src/core/modals/ConnectModal/HomeView/Reload/index.tsx create mode 100644 packages/walletkit/src/core/modals/ConnectModal/HomeView/Reload/style.css.ts diff --git a/.changeset/wise-days-juggle.md b/.changeset/wise-days-juggle.md new file mode 100644 index 00000000..aa494867 --- /dev/null +++ b/.changeset/wise-days-juggle.md @@ -0,0 +1,5 @@ +--- +'@node-real/walletkit': minor +--- + +Support tg diff --git a/packages/walletkit/__dev__/App.tsx b/packages/walletkit/__dev__/App.tsx index 59587ebd..83d88a03 100644 --- a/packages/walletkit/__dev__/App.tsx +++ b/packages/walletkit/__dev__/App.tsx @@ -61,16 +61,16 @@ const config: WalletKitConfig = { // mathWallet(), ], }), - solanaConfig: defaultSolanaConfig({ - autoConnect: true, - rpcUrl: 'https://solana-rpc.debridge.finance', - wallets: [solanaTrustWallet(), solanaPhantomWallet()], - }), - tronConfig: defaultTronConfig({ - autoConnect: true, - initialChainId: '0xcd8690dc', - wallets: [tronLink()], - }), + // solanaConfig: defaultSolanaConfig({ + // autoConnect: true, + // rpcUrl: 'https://solana-rpc.debridge.finance', + // wallets: [solanaTrustWallet(), solanaPhantomWallet()], + // }), + // tronConfig: defaultTronConfig({ + // autoConnect: true, + // initialChainId: '0xcd8690dc', + // wallets: [tronLink()], + // }), }; export default function App() { diff --git a/packages/walletkit/package.json b/packages/walletkit/package.json index 1f44d1d1..f4a59f85 100644 --- a/packages/walletkit/package.json +++ b/packages/walletkit/package.json @@ -53,7 +53,7 @@ "wagmi": "^2" }, "dependencies": { - "@binance/w3w-wagmi-connector-v2": "1.2.4-alpha.0", + "@binance/w3w-wagmi-connector-v2": "^1.2.3", "@metamask/jazzicon": "^2", "@solana/wallet-adapter-react": "^0", "@solana/wallet-adapter-wallets": "^0", diff --git a/packages/walletkit/src/core/modals/ConnectModal/HomeView/GridLayout/index.tsx b/packages/walletkit/src/core/modals/ConnectModal/HomeView/GridLayout/index.tsx index 76bcb30f..2ac04532 100644 --- a/packages/walletkit/src/core/modals/ConnectModal/HomeView/GridLayout/index.tsx +++ b/packages/walletkit/src/core/modals/ConnectModal/HomeView/GridLayout/index.tsx @@ -7,6 +7,8 @@ import { WalletOption } from './WalletOption'; import { BaseWallet } from '@/core/configs/types'; import { useWalletKit } from '@/core/providers/WalletKitProvider/context'; import { clsWallets, clsNoWalletButton } from './styles.css'; +import { isTMA } from '@/core/base/utils/mobile'; +import { Reload } from '../Reload'; export function GridLayout(props: { visibleWallets: BaseWallet[] }) { const { visibleWallets } = props; @@ -18,18 +20,24 @@ export function GridLayout(props: { visibleWallets: BaseWallet[] }) { {visibleWallets?.map((w, index) => )} - {!options.hideNoWalletCTA && ( + {isTMA() ? ( - + + ) : ( + !options.hideNoWalletCTA && ( + + + + ) )} ); diff --git a/packages/walletkit/src/core/modals/ConnectModal/HomeView/ListLayout/index.tsx b/packages/walletkit/src/core/modals/ConnectModal/HomeView/ListLayout/index.tsx index fb7432ab..7003f996 100644 --- a/packages/walletkit/src/core/modals/ConnectModal/HomeView/ListLayout/index.tsx +++ b/packages/walletkit/src/core/modals/ConnectModal/HomeView/ListLayout/index.tsx @@ -7,6 +7,8 @@ import { useWalletKit } from '@/core/providers/WalletKitProvider/context'; import { clsWallets, clsNoWalletLink } from './styles.css'; import { WalletOption } from './WalletOption'; import { BaseWallet } from '@/core/configs/types'; +import { isTMA } from '@/core/base/utils/mobile'; +import { Reload } from '../Reload'; export function ListLayout(props: { visibleWallets: BaseWallet[] }) { const { visibleWallets } = props; @@ -18,15 +20,21 @@ export function ListLayout(props: { visibleWallets: BaseWallet[] }) { {visibleWallets?.map((w, index) => )} - {!options.hideNoWalletCTA && ( + {isTMA() ? ( - - I don’t have a wallet - + + ) : ( + !options.hideNoWalletCTA && ( + + + I don’t have a wallet + + + ) )} ); diff --git a/packages/walletkit/src/core/modals/ConnectModal/HomeView/Reload/index.tsx b/packages/walletkit/src/core/modals/ConnectModal/HomeView/Reload/index.tsx new file mode 100644 index 00000000..512ea76e --- /dev/null +++ b/packages/walletkit/src/core/modals/ConnectModal/HomeView/Reload/index.tsx @@ -0,0 +1,23 @@ +import { Box } from '@/core/base/components/Box'; + +import { cx } from '@/core/base/utils/css'; +import { clsContent, clsReloadBtn } from './style.css'; +import { Link } from '@/core/base/components/Link'; + +export function Reload() { + return ( + + No response on wallet? + + { + window.location.reload(); + }} + > + Reload + + + + ); +} diff --git a/packages/walletkit/src/core/modals/ConnectModal/HomeView/Reload/style.css.ts b/packages/walletkit/src/core/modals/ConnectModal/HomeView/Reload/style.css.ts new file mode 100644 index 00000000..50e436bc --- /dev/null +++ b/packages/walletkit/src/core/modals/ConnectModal/HomeView/Reload/style.css.ts @@ -0,0 +1,17 @@ +import { style } from '@vanilla-extract/css'; + +export const clsContent = style({ + fontSize: '16px', + lineHeight: '24px', + display: 'flex', + alignItems: 'center', + width: '100%', + justifyContent: 'center', +}); + +export const clsReloadBtn = style({ + width: '100%', + marginLeft: '4px', + textDecoration: 'underline', + cursor: 'pointer', +}); diff --git a/packages/walletkit/src/evm/components/SetEvmWalletClickRef/index.tsx b/packages/walletkit/src/evm/components/SetEvmWalletClickRef/index.tsx index 1487c130..59d0821f 100644 --- a/packages/walletkit/src/evm/components/SetEvmWalletClickRef/index.tsx +++ b/packages/walletkit/src/evm/components/SetEvmWalletClickRef/index.tsx @@ -1,4 +1,4 @@ -import { isMobile, isTMA } from '@/core/base/utils/mobile'; +import { isMobile, isPC, isTMA } from '@/core/base/utils/mobile'; import { UseWalletRenderProps } from '@/core/hooks/useWalletRender'; import { useConnectModal } from '@/core/modals/ConnectModal/context'; import { ViewRoutes } from '@/core/modals/ConnectModal/RouteProvider'; @@ -84,7 +84,7 @@ export function SetEvmWalletClickRef(props: SetEvmWalletClickRefProps) { disconnect(); clearTimeout(timerRef.current); - const useSDK = [binanceWeb3Wallet().id].includes(walletId); + const useSDK = [binanceWeb3Wallet().id].includes(walletId) && isPC(); const delay = useSDK ? 0 : 300; const handleJumping = () => { diff --git a/packages/walletkit/src/evm/wallets/binanceWeb3Wallet/index.tsx b/packages/walletkit/src/evm/wallets/binanceWeb3Wallet/index.tsx index a79b0fdd..43c89653 100644 --- a/packages/walletkit/src/evm/wallets/binanceWeb3Wallet/index.tsx +++ b/packages/walletkit/src/evm/wallets/binanceWeb3Wallet/index.tsx @@ -1,6 +1,7 @@ import { binanceWeb3WalletConfig } from '@/core/configs/binanceWeb3Wallet'; import { EvmWallet } from '../types'; import { BinanceW3WParameters, getWagmiConnectorV2 } from '@binance/w3w-wagmi-connector-v2'; +import { isAndroid, isTMA } from '@/core/base/utils/mobile'; export interface BinanceWeb3WalletOptions extends Partial { connectorOptions?: BinanceW3WParameters; @@ -21,8 +22,12 @@ export function binanceWeb3Wallet(props: BinanceWeb3WalletOptions = {}): EvmWall getDeepLink() { return undefined; }, - getUri() { - return undefined; + getUri(uri) { + let encodedUri = encodeURIComponent(uri); + if (isTMA() && isAndroid()) { + encodedUri = encodeURIComponent(encodedUri); + } + return `https://app.binance.com/cedefi/wc?uri=${encodedUri}`; }, getCreateConnectorFn() { const connector = getWagmiConnectorV2(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 75d8aae0..d15fac93 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -134,8 +134,8 @@ importers: packages/walletkit: dependencies: '@binance/w3w-wagmi-connector-v2': - specifier: 1.2.4-alpha.0 - version: 1.2.4-alpha.0(bufferutil@4.0.8)(encoding@0.1.13)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10)(viem@2.21.53(bufferutil@4.0.8)(typescript@5.5.3)(utf-8-validate@5.0.10)(zod@3.22.4))(wagmi@2.13.3(@react-native-async-storage/async-storage@1.24.0(react-native@0.74.3(@babel/core@7.25.2)(@babel/preset-env@7.24.8(@babel/core@7.25.2))(@types/react@18.3.3)(bufferutil@4.0.8)(encoding@0.1.13)(react@18.3.1)(utf-8-validate@5.0.10)))(@tanstack/query-core@5.51.21)(@tanstack/react-query@5.51.21(react@18.3.1))(@types/react@18.3.3)(bufferutil@4.0.8)(encoding@0.1.13)(react@18.3.1)(typescript@5.5.3)(utf-8-validate@5.0.10)(viem@2.21.53(bufferutil@4.0.8)(typescript@5.5.3)(utf-8-validate@5.0.10)(zod@3.22.4))(zod@3.22.4)) + specifier: ^1.2.3 + version: 1.2.3(bufferutil@4.0.8)(encoding@0.1.13)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10)(viem@2.21.53(bufferutil@4.0.8)(typescript@5.5.3)(utf-8-validate@5.0.10)(zod@3.22.4))(wagmi@2.13.3(@react-native-async-storage/async-storage@1.24.0(react-native@0.74.3(@babel/core@7.25.2)(@babel/preset-env@7.24.8(@babel/core@7.25.2))(@types/react@18.3.3)(bufferutil@4.0.8)(encoding@0.1.13)(react@18.3.1)(utf-8-validate@5.0.10)))(@tanstack/query-core@5.51.21)(@tanstack/react-query@5.51.21(react@18.3.1))(@types/react@18.3.3)(bufferutil@4.0.8)(encoding@0.1.13)(react@18.3.1)(typescript@5.5.3)(utf-8-validate@5.0.10)(viem@2.21.53(bufferutil@4.0.8)(typescript@5.5.3)(utf-8-validate@5.0.10)(zod@3.22.4))(zod@3.22.4)) '@metamask/jazzicon': specifier: ^2 version: 2.0.0 @@ -1450,11 +1450,11 @@ packages: resolution: {integrity: sha512-Z/yiTPj+lDVnF7lWeKCIJzaIkI0vYO87dMpZ4bg4TDrFe4XXLFWL1TbXU27gBP3QccxV9mZICCrnjnYlJjXHOA==} engines: {node: '>=6.9.0'} - '@binance/w3w-core@1.1.8-alpha.0': - resolution: {integrity: sha512-fLTBqF4Yb7s4zFMhzHnmurQqszbiE9c8ZdmbELSkWgSwEHtEO7DAOAV61X9mCLLeCLpQkwz3sLULg/Agjr5iXA==} + '@binance/w3w-core@1.1.7': + resolution: {integrity: sha512-Aipavg2sc8JyBsgvmdbpna0RmS1EVmaIIgZO3lQr+OV0Q2EKabAIZ5nZNQOEmhxAzOxcrCZAUaNu/tW17JfcGg==} - '@binance/w3w-ethereum-provider@1.1.8-alpha.0': - resolution: {integrity: sha512-pmJWrv1npmqYYz1M3wtaXVY4rSJh2GYjNgRXoFb9SUJOklO8zHqKUjRoPWcHtWQTnEHmwzE4e/dIzE3tecRAjg==} + '@binance/w3w-ethereum-provider@1.1.7': + resolution: {integrity: sha512-fHHifGDidtYaXoboe1FzLZ5wKk0FzIvgq8SCuEtibXZK3d+iITF28gmCKZnp7BCuCjvuNvOCp3GNHcvY4ARPJg==} '@binance/w3w-http-client@1.1.4': resolution: {integrity: sha512-dovohLZThYNY2DNbM0XILjLsgo+ZMdMRRTkbdewrLcj1KkXwUn36K2tFsi/aDZXTBjWcNlziaGQYHmbuLEXTpw==} @@ -1462,8 +1462,8 @@ packages: '@binance/w3w-qrcode-modal@1.1.5': resolution: {integrity: sha512-SFwA9PeCAlPBjfgLf9chLoia3D5pWpDjDZOZ6wD3G3Xspd4XKrtQl4UvFpAm6hkrgw6fShtI2zis9PQYAxQjiA==} - '@binance/w3w-sign-client@1.1.8-alpha.0': - resolution: {integrity: sha512-p/p/aN6bwCko6X6SGvHGIEW/8ePx/2FWecnAwZaqWmglOdc3u632MWYgTj814Vn6tM36kntY5GoYbGVPMPtQ2w==} + '@binance/w3w-sign-client@1.1.7': + resolution: {integrity: sha512-KmuQCJ6g0L2LS0LEUQWbugqWiB6Nx+GMCEVuyRhl1AxzAiDybolpx8bIYAIinUeWoO2NcDJdzn971tX+QkhjoQ==} '@binance/w3w-socket-transport@1.1.4': resolution: {integrity: sha512-SFHknzRM74CMam95bcpcyGeYVHfET3vrANU6XROAVYTa+kCP2O6/tIZVO+WC5HyEJf2uNcJJAV1PVn3gq/3kKQ==} @@ -1474,8 +1474,8 @@ packages: '@binance/w3w-utils@1.1.4': resolution: {integrity: sha512-lWpxCj5IB8XNKmFotZ2MLsK4rP5ECyC5jHxbDuvjseMlZchEaWKRXViUcwIz3XdJPVM3DDArqqweLEyxCcsDtQ==} - '@binance/w3w-wagmi-connector-v2@1.2.4-alpha.0': - resolution: {integrity: sha512-L/ivthYZeFjJ4DAYaKg3o5gDqRtmdiIptC4JgFfvVN6gpdEcAKM28ZJfpd6Gtax2Or+nrTw5eXdaxUUtp4cXtw==} + '@binance/w3w-wagmi-connector-v2@1.2.3': + resolution: {integrity: sha512-tprDHbHuOctnqfCJ3Fygzw+zdNhkCtxs8JJZ+Yhk50Mi2hytjydoL2G0674GE+6dCiDP5SveDtT6X99MRMtQqQ==} peerDependencies: viem: 2.x wagmi: 2.x @@ -13366,7 +13366,7 @@ snapshots: '@babel/helper-string-parser': 7.25.9 '@babel/helper-validator-identifier': 7.25.9 - '@binance/w3w-core@1.1.8-alpha.0(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10)': + '@binance/w3w-core@1.1.7(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10)': dependencies: '@binance/w3w-qrcode-modal': 1.1.5(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3)) '@binance/w3w-socket-transport': 1.1.4(bufferutil@4.0.8)(utf-8-validate@5.0.10) @@ -13381,10 +13381,10 @@ snapshots: - ts-node - utf-8-validate - '@binance/w3w-ethereum-provider@1.1.8-alpha.0(bufferutil@4.0.8)(encoding@0.1.13)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10)': + '@binance/w3w-ethereum-provider@1.1.7(bufferutil@4.0.8)(encoding@0.1.13)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10)': dependencies: '@binance/w3w-http-client': 1.1.4(encoding@0.1.13) - '@binance/w3w-sign-client': 1.1.8-alpha.0(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10) + '@binance/w3w-sign-client': 1.1.7(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10) '@binance/w3w-types': 1.1.4 '@binance/w3w-utils': 1.1.4 eip1193-provider: 1.0.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) @@ -13417,9 +13417,9 @@ snapshots: transitivePeerDependencies: - ts-node - '@binance/w3w-sign-client@1.1.8-alpha.0(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10)': + '@binance/w3w-sign-client@1.1.7(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10)': dependencies: - '@binance/w3w-core': 1.1.8-alpha.0(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10) + '@binance/w3w-core': 1.1.7(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10) '@binance/w3w-types': 1.1.4 '@binance/w3w-utils': 1.1.4 transitivePeerDependencies: @@ -13448,9 +13448,9 @@ snapshots: hash.js: 1.1.7 js-base64: 3.7.7 - '@binance/w3w-wagmi-connector-v2@1.2.4-alpha.0(bufferutil@4.0.8)(encoding@0.1.13)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10)(viem@2.21.53(bufferutil@4.0.8)(typescript@5.5.3)(utf-8-validate@5.0.10)(zod@3.22.4))(wagmi@2.13.3(@react-native-async-storage/async-storage@1.24.0(react-native@0.74.3(@babel/core@7.25.2)(@babel/preset-env@7.24.8(@babel/core@7.25.2))(@types/react@18.3.3)(bufferutil@4.0.8)(encoding@0.1.13)(react@18.3.1)(utf-8-validate@5.0.10)))(@tanstack/query-core@5.51.21)(@tanstack/react-query@5.51.21(react@18.3.1))(@types/react@18.3.3)(bufferutil@4.0.8)(encoding@0.1.13)(react@18.3.1)(typescript@5.5.3)(utf-8-validate@5.0.10)(viem@2.21.53(bufferutil@4.0.8)(typescript@5.5.3)(utf-8-validate@5.0.10)(zod@3.22.4))(zod@3.22.4))': + '@binance/w3w-wagmi-connector-v2@1.2.3(bufferutil@4.0.8)(encoding@0.1.13)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10)(viem@2.21.53(bufferutil@4.0.8)(typescript@5.5.3)(utf-8-validate@5.0.10)(zod@3.22.4))(wagmi@2.13.3(@react-native-async-storage/async-storage@1.24.0(react-native@0.74.3(@babel/core@7.25.2)(@babel/preset-env@7.24.8(@babel/core@7.25.2))(@types/react@18.3.3)(bufferutil@4.0.8)(encoding@0.1.13)(react@18.3.1)(utf-8-validate@5.0.10)))(@tanstack/query-core@5.51.21)(@tanstack/react-query@5.51.21(react@18.3.1))(@types/react@18.3.3)(bufferutil@4.0.8)(encoding@0.1.13)(react@18.3.1)(typescript@5.5.3)(utf-8-validate@5.0.10)(viem@2.21.53(bufferutil@4.0.8)(typescript@5.5.3)(utf-8-validate@5.0.10)(zod@3.22.4))(zod@3.22.4))': dependencies: - '@binance/w3w-ethereum-provider': 1.1.8-alpha.0(bufferutil@4.0.8)(encoding@0.1.13)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10) + '@binance/w3w-ethereum-provider': 1.1.7(bufferutil@4.0.8)(encoding@0.1.13)(ts-node@10.9.2(@types/node@22.9.3)(typescript@5.5.3))(utf-8-validate@5.0.10) '@binance/w3w-utils': 1.1.4 viem: 2.21.53(bufferutil@4.0.8)(typescript@5.5.3)(utf-8-validate@5.0.10)(zod@3.22.4) wagmi: 2.13.3(@react-native-async-storage/async-storage@1.24.0(react-native@0.74.3(@babel/core@7.25.2)(@babel/preset-env@7.24.8(@babel/core@7.25.2))(@types/react@18.3.3)(bufferutil@4.0.8)(encoding@0.1.13)(react@18.3.1)(utf-8-validate@5.0.10)))(@tanstack/query-core@5.51.21)(@tanstack/react-query@5.51.21(react@18.3.1))(@types/react@18.3.3)(bufferutil@4.0.8)(encoding@0.1.13)(react@18.3.1)(typescript@5.5.3)(utf-8-validate@5.0.10)(viem@2.21.53(bufferutil@4.0.8)(typescript@5.5.3)(utf-8-validate@5.0.10)(zod@3.22.4))(zod@3.22.4)