From 527329fee3dbc2e68663bc734a555750d83aa320 Mon Sep 17 00:00:00 2001 From: Wenty Li <105278450+wenty22@users.noreply.github.com> Date: Thu, 15 Aug 2024 09:50:17 +0800 Subject: [PATCH] refactor: solana and evm are unified into one package (#181) * feat: Split into four packages: ui, wagmi, solana and walletkit * feat: Split packages & support solana * feat: Split package into solana & wagmi * feat: Split package into solana & wagmi * feat: Update soft link * feat: Update soft link (#179) * feat: Split into four packages: ui, wagmi, solana and walletkit * feat: Split packages & support solana * feat: Split package into solana & wagmi * feat: Split package into solana & wagmi * feat: Update soft link * chore: update versions (alpha) (#180) Co-authored-by: github-actions[bot] * refactor: Refactor walletkit * refactor: Refactor wallets * feat: Update pack config * feat: Add ConnectModal * refactor: Normalized names * refactor: solana and evm are unified into one package --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] --- .changeset/friendly-weeks-applaud.md | 5 + examples/nextjs/package.json | 6 +- examples/nextjs/pages/_app.tsx | 77 +- examples/nextjs/pages/_document.tsx | 2 +- examples/vite/package.json | 5 +- examples/vite/src/App.tsx | 126 +- package.json | 10 +- packages/walletkit/CHANGELOG.md | 40 - packages/walletkit/__dev__/App.tsx | 153 +- packages/walletkit/__dev__/chains.ts | 29 - packages/walletkit/__dev__/index.html | 1 - packages/walletkit/__dev__/style.css | 1722 ++ packages/walletkit/package.json | 45 +- .../walletkit/src/chains/icons/BscIcon.tsx | 20 - .../walletkit/src/chains/icons/ComboIcon.tsx | 25 - .../src/chains/icons/EthereumIcon.tsx | 14 - .../src/chains/icons/UnknownChainIcon.tsx | 45 - packages/walletkit/src/chains/index.tsx | 47 - packages/walletkit/src/chains/types.ts | 5 - .../src/components/DisconnectButton/index.tsx | 35 - .../components/DisconnectButton/styles.css.ts | 19 - .../ConnectButton/ConnectedInfo/index.tsx | 75 - .../ConnectButton/ConnectedInfo/styles.css.ts | 59 - .../WalletKitButton/ConnectButton/index.tsx | 47 - .../ConnectButton/styles.css.ts | 18 - .../ConnectButtonRenderer/index.tsx | 55 - .../src/components/WalletKitButton/index.tsx | 11 - .../components/WalletKitProvider/context.ts | 56 - .../components/WalletKitProvider/index.tsx | 107 - packages/walletkit/src/constants/common.ts | 4 - .../{ => core}/base/components/Box/index.tsx | 2 +- .../base/components/Box/styles.css.ts | 0 .../base/components/Button/index.tsx | 4 +- .../base/components/Button/styles.css.ts | 0 .../base/components/IconButton/index.tsx | 4 +- .../base/components/IconButton/styles.css.ts | 4 +- .../{ => core}/base/components/Link/index.tsx | 4 +- .../base/components/Link/styles.css.ts | 4 +- .../base/components/Modal/ModalBody/index.tsx | 2 +- .../components/Modal/ModalBody/styles.css.ts | 0 .../components/Modal/ModalContent/index.tsx | 4 +- .../Modal/ModalContent/style.css.ts | 4 +- .../components/Modal/ModalFooter/index.tsx | 4 +- .../Modal/ModalFooter/styles.css.ts | 0 .../components/Modal/ModalHeader/index.tsx | 2 +- .../Modal/ModalHeader/styles.css.ts | 2 +- .../base/components/Modal/index.tsx | 10 +- .../base/components/Modal/styles.css.ts | 4 +- .../base/components/Portal/index.tsx | 0 .../{ => core}/base/components/Text/index.tsx | 0 .../base/components/Transition/fade.css.ts | 0 .../base/components/Transition/index.tsx | 2 +- .../components/Transition/modalSlide.css.ts | 0 .../components/Transition/toastSlide.css.ts | 0 .../base/components/toast/ToastComponent.tsx | 6 +- .../base/components/toast/ToastManager.ts | 0 .../base/components/toast/ToastProvider.tsx | 4 +- .../base/components/toast/index.tsx | 0 .../base/components/toast/styles.css.ts | 2 +- .../src/{ => core}/base/constant/index.ts | 0 .../src/{ => core}/base/hooks/useClipboard.ts | 0 .../{ => core}/base/hooks/useDisclosure.ts | 0 .../src/{ => core}/base/hooks/useIsMounted.ts | 0 .../src/{ => core}/base/hooks/useKeyDown.ts | 0 .../{ => core}/base/hooks/useResponsive.ts | 0 .../{ => core}/base/hooks/useScrollLock.ts | 0 .../src/{ => core}/base/icons/AlertIcon.tsx | 2 - .../src/{ => core}/base/icons/BackIcon.tsx | 2 - .../base/icons/ChainSpinnerIcon.tsx | 3 +- .../base/icons/CircleLoadingIcon.tsx | 1 - .../src/{ => core}/base/icons/CloseIcon.tsx | 2 - .../src/{ => core}/base/icons/CopyIcon.tsx | 2 - .../{ => core}/base/icons/DownArrowIcon.tsx | 2 - .../src/{ => core}/base/icons/ErrorIcon.tsx | 1 - .../src/{ => core}/base/icons/ExitIcon.tsx | 2 - .../src/{ => core}/base/icons/ForwardIcon.tsx | 2 - .../src/{ => core}/base/icons/InfoIcon.tsx | 2 - .../src/{ => core}/base/icons/RefreshIcon.tsx | 2 - .../src/{ => core}/base/icons/SuccessIcon.tsx | 2 - .../src/{ => core}/base/icons/WalletIcon.tsx | 2 - .../src/{ => core}/base/utils/common.ts | 0 .../src/{ => core}/base/utils/css.ts | 0 .../src/{ => core}/base/utils/mobile.ts | 0 .../src/{ => core}/base/vanilla/index.css.ts | 0 .../{ => core}/components/Avatar/index.tsx | 7 +- .../components/Avatar/styles.css.ts | 0 .../components}/ConnectSpinner/index.tsx | 6 +- .../components}/ConnectSpinner/styles.css.ts | 2 +- .../components}/Content/Description/index.tsx | 4 +- .../Content/Description/styles.css.ts | 2 +- .../components}/Content/ErrorTitle/index.tsx | 6 +- .../Content/ErrorTitle/styles.css.ts | 2 +- .../components}/Content/InfoTitle/index.tsx | 4 +- .../Content/InfoTitle/styles.css.ts | 0 .../components}/Content/index.tsx | 4 +- .../components}/Content/styles.css.ts | 0 .../components/CustomQRCode/QRCode.tsx | 0 .../CustomQRCode/QRCodePlaceHolder/index.tsx | 2 +- .../QRCodePlaceHolder/styles.css.ts | 2 +- .../components/CustomQRCode/index.tsx | 9 +- .../components/CustomQRCode/styles.css.ts | 2 +- .../{ => core}/components/Navbar/index.tsx | 10 +- .../components/Navbar/styles.css.ts | 0 .../src/core/configs/getDefaultConfig.ts | 59 + .../wallets/binanceWeb3Wallet/icon.tsx | 2 - .../wallets/binanceWeb3Wallet/index.tsx | 15 + .../configs}/wallets/bitgetWallet/icon.tsx | 0 .../configs/wallets/bitgetWallet/index.tsx | 15 + .../configs}/wallets/coinbaseWallet/icon.tsx | 2 - .../configs/wallets/coinbaseWallet/index.tsx | 15 + .../configs}/wallets/mathWallet/icon.tsx | 2 - .../core/configs/wallets/mathWallet/index.tsx | 15 + .../configs}/wallets/metaMask/icon.tsx | 2 - .../core/configs/wallets/metaMask/index.tsx | 15 + .../configs}/wallets/okxWallet/icon.tsx | 2 - .../core/configs/wallets/okxWallet/index.tsx | 15 + .../configs/wallets/phantomWallet/icon.tsx | 24 + .../configs/wallets/phantomWallet/index.tsx | 15 + .../{ => core/configs}/wallets/safe/icon.tsx | 2 - .../src/core/configs/wallets/safe/index.tsx | 13 + .../configs}/wallets/tokenPocket/icon.tsx | 2 - .../configs/wallets/tokenPocket/index.tsx | 15 + .../configs}/wallets/trustWallet/icon.tsx | 2 - .../configs/wallets/trustWallet/index.tsx | 26 + .../src/core/configs/wallets/types.ts | 38 + .../configs}/wallets/walletConnect/icon.tsx | 2 - .../configs/wallets/walletConnect/index.tsx | 14 + .../walletkit/src/core/constants/index.ts | 8 + .../src/{ => core}/globalData/index.ts | 14 +- .../core/hooks/useAutoCloseConnectModal.ts | 19 + .../src/core/hooks/useCloseAllModals.ts | 17 + .../src/core/hooks/useWalletDownloadUrl.ts | 16 + .../src/{ => core}/hooks/useWalletLogos.ts | 8 +- .../src/core/hooks/useWalletRender.ts | 40 + packages/walletkit/src/core/index.ts | 14 + .../ConnectModal/ConnectWithQRCode/index.tsx | 50 + .../ConnectWithQRCode/styles.css.ts | 0 .../ConnectModal/ConnectingView/index.tsx | 140 + .../ConnectingView}/styles.css.ts | 4 +- .../GridLayout/WalletOption/index.tsx | 51 + .../GridLayout/WalletOption/styles.css.ts | 4 +- .../ConnectorsView/GridLayout/index.tsx | 38 + .../ConnectorsView}/GridLayout/styles.css.ts | 4 +- .../ListLayout/WalletOption/index.tsx | 48 + .../ListLayout/WalletOption/styles.css.ts | 4 +- .../ConnectorsView/ListLayout/index.tsx | 35 + .../ConnectorsView}/ListLayout/styles.css.ts | 0 .../SetWalletClickRef/index.tsx | 21 + .../ConnectModal/ConnectorsView/index.tsx | 31 + .../ConnectorsView}/styles.css.ts | 2 +- .../ConnectModal/RouteProvider/context.tsx | 2 +- .../ConnectModal/RouteProvider/index.tsx | 42 +- .../{ => core}/modals/ConnectModal/context.ts | 9 +- .../{ => core}/modals/ConnectModal/index.tsx | 18 +- .../src/core/modals/ConnectModal/provider.tsx | 47 + .../providers}/ThemeProvider/context.ts | 0 .../providers}/ThemeProvider/index.tsx | 27 +- .../providers/ThemeProvider}/themes/base.ts | 8 +- .../providers/WalletKitProvider/context.ts | 112 + .../providers/WalletKitProvider/index.tsx | 57 + .../walletkit/src/{ => core}/utils/account.ts | 17 +- packages/walletkit/src/core/utils/common.ts | 27 + .../walletkit/src/core/utils/eventEmitter.ts | 34 + .../src/defaultConfig/defaultWagmiConfig.ts | 93 - .../defaultConfig/getDefaultChainsConfig.tsx | 23 - .../getDefaultWalletKitOptions.ts | 39 - .../src/defaultConfig/getDefaultWallets.ts | 16 - .../components/EthereumScript/index.tsx | 0 .../EvmConnectWithQRCodeView/index.tsx | 24 + .../components/EvmConnectingView/index.tsx | 95 + .../components/EvmWalletProvider/index.tsx | 29 + .../components/SetEvmWalletClickRef/index.tsx | 101 + .../hooks/useEvmBalance.ts} | 10 +- .../hooks/useEvmConnect.ts} | 22 +- .../src/evm/hooks/useEvmSwitchChain.ts | 28 + .../src/{ => evm}/hooks/useIsConnected.ts | 0 .../src/{ => evm}/hooks/useQRCodeUri.ts | 13 +- .../evm/hooks/useWalletConnectConnector.ts | 7 + .../{ => evm}/hooks/useWalletConnectModal.ts | 17 +- .../src/evm/hooks/useWalletConnector.ts | 6 + packages/walletkit/src/evm/index.ts | 2 + .../src/evm/utils/evmCommonErrorHandler.ts | 38 + .../walletkit/src/evm/utils/getEvmConfig.ts | 57 + .../wallets/binanceWeb3Wallet/index.tsx | 46 +- .../src/evm/wallets/bitgetWallet/index.tsx | 48 + .../src/evm/wallets/coinbaseWallet/index.tsx | 44 + .../walletkit/src/{ => evm}/wallets/index.ts | 0 .../src/{ => evm}/wallets/injected.ts | 0 .../src/evm/wallets/mathWallet/index.tsx | 44 + .../src/evm/wallets/metaMask/index.tsx | 32 + .../src/evm/wallets/okxWallet/index.tsx | 47 + .../walletkit/src/evm/wallets/safe/index.tsx | 31 + .../src/evm/wallets/tokenPocket/index.tsx | 51 + .../src/evm/wallets/trustWallet/index.tsx | 53 + packages/walletkit/src/evm/wallets/types.ts | 13 + .../walletkit/src/{ => evm}/wallets/utils.ts | 6 +- .../{ => evm}/wallets/walletConnect/index.tsx | 45 +- .../walletkit/src/hooks/useChainConfig.ts | 15 - .../src/hooks/useChainIsSupported.ts | 8 - .../walletkit/src/hooks/useClickWallet.ts | 95 - .../walletkit/src/hooks/useCloseAllModals.ts | 17 - .../walletkit/src/hooks/useWalletConfig.ts | 14 - .../src/hooks/useWalletConnectConnector.ts | 7 - .../src/hooks/useWalletDownloadUrl.ts | 16 - .../src/hooks/useWalletKitSwitchChain.ts | 27 - .../walletkit/src/hooks/useWalletRender.ts | 33 - packages/walletkit/src/index.ts | 23 - .../ConnectModal/ConnectWithQRCode/index.tsx | 45 - .../Connecting/UnsupportedContent/index.tsx | 34 - .../modals/ConnectModal/Connecting/index.tsx | 194 - .../GridLayout/WalletOption/index.tsx | 43 - .../Connectors/GridLayout/index.tsx | 34 - .../ListLayout/WalletOption/index.tsx | 40 - .../Connectors/ListLayout/index.tsx | 32 - .../modals/ConnectModal/Connectors/index.tsx | 27 - .../src/modals/ConnectModal/provider.tsx | 54 - .../src/modals/EmbeddedConnectModal/index.tsx | 22 - .../modals/EmbeddedConnectModal/style.css.ts | 17 - .../ProfileModal/CopyToClipboard/index.tsx | 27 - .../CopyToClipboard/styles.css.ts | 17 - .../src/modals/ProfileModal/context.ts | 13 - .../src/modals/ProfileModal/index.tsx | 52 - .../src/modals/ProfileModal/provider.tsx | 34 - .../src/modals/ProfileModal/styles.css.ts | 30 - .../SwitchNetworkModal/ChainOption/index.tsx | 31 - .../ChainOption/styles.css.ts | 54 - .../SwitchNetworkModal/ChainSpinner/index.tsx | 19 - .../ChainSpinner/styles.css.ts | 28 - .../src/modals/SwitchNetworkModal/context.ts | 18 - .../src/modals/SwitchNetworkModal/index.tsx | 94 - .../modals/SwitchNetworkModal/provider.tsx | 75 - .../modals/SwitchNetworkModal/styles.css.ts | 50 - .../SetSolanaWalletClickRef/index.tsx | 67 + .../SolanaConnectWithQRCodeView/index.tsx | 3 + .../components/SolanaConnectingView/index.tsx | 82 + .../components/SolanaWalletProvider/index.tsx | 40 + packages/walletkit/src/solana/index.ts | 1 + .../src/solana/utils/getSolanaConfig.ts | 17 + .../solana/utils/solanaCommonErrorHandler.ts | 10 + .../walletkit/src/solana/wallets/index.ts | 7 + .../solana/wallets/phantomWallet/index.tsx | 28 + .../src/solana/wallets/trustWallet/index.tsx | 34 + .../walletkit/src/solana/wallets/types.ts | 13 + .../walletkit/src/solana/wallets/utils.ts | 9 + .../solana/wallets/walletConnect/index.tsx | 52 + packages/walletkit/src/types.ts | 7 - packages/walletkit/src/typings.d.ts | 8 + packages/walletkit/src/utils/common.ts | 66 - .../src/wallets/bitgetWallet/index.tsx | 61 - .../src/wallets/coinbaseWallet/index.tsx | 57 - .../src/wallets/mathWallet/index.tsx | 57 - .../walletkit/src/wallets/metaMask/index.tsx | 50 - .../walletkit/src/wallets/okxWallet/index.tsx | 60 - packages/walletkit/src/wallets/safe/index.tsx | 42 - .../src/wallets/tokenPocket/index.tsx | 60 - .../src/wallets/trustWallet/index.tsx | 80 - packages/walletkit/src/wallets/types.ts | 40 - packages/walletkit/styles.css/package.json | 3 - packages/walletkit/tsconfig.json | 4 +- packages/walletkit/vite.config.ts | 9 +- packages/walletkit/wallets/package.json | 3 - pnpm-lock.yaml | 21051 +++++++++++----- 262 files changed, 19444 insertions(+), 9296 deletions(-) create mode 100644 .changeset/friendly-weeks-applaud.md delete mode 100644 packages/walletkit/CHANGELOG.md delete mode 100644 packages/walletkit/__dev__/chains.ts create mode 100644 packages/walletkit/__dev__/style.css delete mode 100644 packages/walletkit/src/chains/icons/BscIcon.tsx delete mode 100644 packages/walletkit/src/chains/icons/ComboIcon.tsx delete mode 100644 packages/walletkit/src/chains/icons/EthereumIcon.tsx delete mode 100644 packages/walletkit/src/chains/icons/UnknownChainIcon.tsx delete mode 100644 packages/walletkit/src/chains/index.tsx delete mode 100644 packages/walletkit/src/chains/types.ts delete mode 100644 packages/walletkit/src/components/DisconnectButton/index.tsx delete mode 100644 packages/walletkit/src/components/DisconnectButton/styles.css.ts delete mode 100644 packages/walletkit/src/components/WalletKitButton/ConnectButton/ConnectedInfo/index.tsx delete mode 100644 packages/walletkit/src/components/WalletKitButton/ConnectButton/ConnectedInfo/styles.css.ts delete mode 100644 packages/walletkit/src/components/WalletKitButton/ConnectButton/index.tsx delete mode 100644 packages/walletkit/src/components/WalletKitButton/ConnectButton/styles.css.ts delete mode 100644 packages/walletkit/src/components/WalletKitButton/ConnectButtonRenderer/index.tsx delete mode 100644 packages/walletkit/src/components/WalletKitButton/index.tsx delete mode 100644 packages/walletkit/src/components/WalletKitProvider/context.ts delete mode 100644 packages/walletkit/src/components/WalletKitProvider/index.tsx delete mode 100644 packages/walletkit/src/constants/common.ts rename packages/walletkit/src/{ => core}/base/components/Box/index.tsx (92%) rename packages/walletkit/src/{ => core}/base/components/Box/styles.css.ts (100%) rename packages/walletkit/src/{ => core}/base/components/Button/index.tsx (91%) rename packages/walletkit/src/{ => core}/base/components/Button/styles.css.ts (100%) rename packages/walletkit/src/{ => core}/base/components/IconButton/index.tsx (92%) rename packages/walletkit/src/{ => core}/base/components/IconButton/styles.css.ts (77%) rename packages/walletkit/src/{ => core}/base/components/Link/index.tsx (91%) rename packages/walletkit/src/{ => core}/base/components/Link/styles.css.ts (69%) rename packages/walletkit/src/{ => core}/base/components/Modal/ModalBody/index.tsx (87%) rename packages/walletkit/src/{ => core}/base/components/Modal/ModalBody/styles.css.ts (100%) rename packages/walletkit/src/{ => core}/base/components/Modal/ModalContent/index.tsx (88%) rename packages/walletkit/src/{ => core}/base/components/Modal/ModalContent/style.css.ts (81%) rename packages/walletkit/src/{ => core}/base/components/Modal/ModalFooter/index.tsx (88%) rename packages/walletkit/src/{ => core}/base/components/Modal/ModalFooter/styles.css.ts (100%) rename packages/walletkit/src/{ => core}/base/components/Modal/ModalHeader/index.tsx (88%) rename packages/walletkit/src/{ => core}/base/components/Modal/ModalHeader/styles.css.ts (83%) rename packages/walletkit/src/{ => core}/base/components/Modal/index.tsx (86%) rename packages/walletkit/src/{ => core}/base/components/Modal/styles.css.ts (85%) rename packages/walletkit/src/{ => core}/base/components/Portal/index.tsx (100%) rename packages/walletkit/src/{ => core}/base/components/Text/index.tsx (100%) rename packages/walletkit/src/{ => core}/base/components/Transition/fade.css.ts (100%) rename packages/walletkit/src/{ => core}/base/components/Transition/index.tsx (96%) rename packages/walletkit/src/{ => core}/base/components/Transition/modalSlide.css.ts (100%) rename packages/walletkit/src/{ => core}/base/components/Transition/toastSlide.css.ts (100%) rename packages/walletkit/src/{ => core}/base/components/toast/ToastComponent.tsx (93%) rename packages/walletkit/src/{ => core}/base/components/toast/ToastManager.ts (100%) rename packages/walletkit/src/{ => core}/base/components/toast/ToastProvider.tsx (96%) rename packages/walletkit/src/{ => core}/base/components/toast/index.tsx (100%) rename packages/walletkit/src/{ => core}/base/components/toast/styles.css.ts (95%) rename packages/walletkit/src/{ => core}/base/constant/index.ts (100%) rename packages/walletkit/src/{ => core}/base/hooks/useClipboard.ts (100%) rename packages/walletkit/src/{ => core}/base/hooks/useDisclosure.ts (100%) rename packages/walletkit/src/{ => core}/base/hooks/useIsMounted.ts (100%) rename packages/walletkit/src/{ => core}/base/hooks/useKeyDown.ts (100%) rename packages/walletkit/src/{ => core}/base/hooks/useResponsive.ts (100%) rename packages/walletkit/src/{ => core}/base/hooks/useScrollLock.ts (100%) rename packages/walletkit/src/{ => core}/base/icons/AlertIcon.tsx (96%) rename packages/walletkit/src/{ => core}/base/icons/BackIcon.tsx (93%) rename packages/walletkit/src/{ => core}/base/icons/ChainSpinnerIcon.tsx (90%) rename packages/walletkit/src/{ => core}/base/icons/CircleLoadingIcon.tsx (96%) rename packages/walletkit/src/{ => core}/base/icons/CloseIcon.tsx (94%) rename packages/walletkit/src/{ => core}/base/icons/CopyIcon.tsx (95%) rename packages/walletkit/src/{ => core}/base/icons/DownArrowIcon.tsx (93%) rename packages/walletkit/src/{ => core}/base/icons/ErrorIcon.tsx (96%) rename packages/walletkit/src/{ => core}/base/icons/ExitIcon.tsx (96%) rename packages/walletkit/src/{ => core}/base/icons/ForwardIcon.tsx (94%) rename packages/walletkit/src/{ => core}/base/icons/InfoIcon.tsx (96%) rename packages/walletkit/src/{ => core}/base/icons/RefreshIcon.tsx (98%) rename packages/walletkit/src/{ => core}/base/icons/SuccessIcon.tsx (95%) rename packages/walletkit/src/{ => core}/base/icons/WalletIcon.tsx (96%) rename packages/walletkit/src/{ => core}/base/utils/common.ts (100%) rename packages/walletkit/src/{ => core}/base/utils/css.ts (100%) rename packages/walletkit/src/{ => core}/base/utils/mobile.ts (100%) rename packages/walletkit/src/{ => core}/base/vanilla/index.css.ts (100%) rename packages/walletkit/src/{ => core}/components/Avatar/index.tsx (86%) rename packages/walletkit/src/{ => core}/components/Avatar/styles.css.ts (100%) rename packages/walletkit/src/{modals/ConnectModal/Connecting => core/components}/ConnectSpinner/index.tsx (81%) rename packages/walletkit/src/{modals/ConnectModal/Connecting => core/components}/ConnectSpinner/styles.css.ts (95%) rename packages/walletkit/src/{modals/ConnectModal/Connecting => core/components}/Content/Description/index.tsx (69%) rename packages/walletkit/src/{modals/ConnectModal/Connecting => core/components}/Content/Description/styles.css.ts (83%) rename packages/walletkit/src/{modals/ConnectModal/Connecting => core/components}/Content/ErrorTitle/index.tsx (65%) rename packages/walletkit/src/{modals/ConnectModal/Connecting => core/components}/Content/ErrorTitle/styles.css.ts (84%) rename packages/walletkit/src/{modals/ConnectModal/Connecting => core/components}/Content/InfoTitle/index.tsx (72%) rename packages/walletkit/src/{modals/ConnectModal/Connecting => core/components}/Content/InfoTitle/styles.css.ts (100%) rename packages/walletkit/src/{modals/ConnectModal/Connecting => core/components}/Content/index.tsx (67%) rename packages/walletkit/src/{modals/ConnectModal/Connecting => core/components}/Content/styles.css.ts (100%) rename packages/walletkit/src/{ => core}/components/CustomQRCode/QRCode.tsx (100%) rename packages/walletkit/src/{ => core}/components/CustomQRCode/QRCodePlaceHolder/index.tsx (85%) rename packages/walletkit/src/{ => core}/components/CustomQRCode/QRCodePlaceHolder/styles.css.ts (97%) rename packages/walletkit/src/{ => core}/components/CustomQRCode/index.tsx (82%) rename packages/walletkit/src/{ => core}/components/CustomQRCode/styles.css.ts (93%) rename packages/walletkit/src/{ => core}/components/Navbar/index.tsx (69%) rename packages/walletkit/src/{ => core}/components/Navbar/styles.css.ts (100%) create mode 100644 packages/walletkit/src/core/configs/getDefaultConfig.ts rename packages/walletkit/src/{ => core/configs}/wallets/binanceWeb3Wallet/icon.tsx (96%) create mode 100644 packages/walletkit/src/core/configs/wallets/binanceWeb3Wallet/index.tsx rename packages/walletkit/src/{ => core/configs}/wallets/bitgetWallet/icon.tsx (100%) create mode 100644 packages/walletkit/src/core/configs/wallets/bitgetWallet/index.tsx rename packages/walletkit/src/{ => core/configs}/wallets/coinbaseWallet/icon.tsx (99%) create mode 100644 packages/walletkit/src/core/configs/wallets/coinbaseWallet/index.tsx rename packages/walletkit/src/{ => core/configs}/wallets/mathWallet/icon.tsx (99%) create mode 100644 packages/walletkit/src/core/configs/wallets/mathWallet/index.tsx rename packages/walletkit/src/{ => core/configs}/wallets/metaMask/icon.tsx (99%) create mode 100644 packages/walletkit/src/core/configs/wallets/metaMask/index.tsx rename packages/walletkit/src/{ => core/configs}/wallets/okxWallet/icon.tsx (95%) create mode 100644 packages/walletkit/src/core/configs/wallets/okxWallet/index.tsx create mode 100644 packages/walletkit/src/core/configs/wallets/phantomWallet/icon.tsx create mode 100644 packages/walletkit/src/core/configs/wallets/phantomWallet/index.tsx rename packages/walletkit/src/{ => core/configs}/wallets/safe/icon.tsx (97%) create mode 100644 packages/walletkit/src/core/configs/wallets/safe/index.tsx rename packages/walletkit/src/{ => core/configs}/wallets/tokenPocket/icon.tsx (99%) create mode 100644 packages/walletkit/src/core/configs/wallets/tokenPocket/index.tsx rename packages/walletkit/src/{ => core/configs}/wallets/trustWallet/icon.tsx (99%) create mode 100644 packages/walletkit/src/core/configs/wallets/trustWallet/index.tsx create mode 100644 packages/walletkit/src/core/configs/wallets/types.ts rename packages/walletkit/src/{ => core/configs}/wallets/walletConnect/icon.tsx (98%) create mode 100644 packages/walletkit/src/core/configs/wallets/walletConnect/index.tsx create mode 100644 packages/walletkit/src/core/constants/index.ts rename packages/walletkit/src/{ => core}/globalData/index.ts (56%) create mode 100644 packages/walletkit/src/core/hooks/useAutoCloseConnectModal.ts create mode 100644 packages/walletkit/src/core/hooks/useCloseAllModals.ts create mode 100644 packages/walletkit/src/core/hooks/useWalletDownloadUrl.ts rename packages/walletkit/src/{ => core}/hooks/useWalletLogos.ts (75%) create mode 100644 packages/walletkit/src/core/hooks/useWalletRender.ts create mode 100644 packages/walletkit/src/core/index.ts create mode 100644 packages/walletkit/src/core/modals/ConnectModal/ConnectWithQRCode/index.tsx rename packages/walletkit/src/{ => core}/modals/ConnectModal/ConnectWithQRCode/styles.css.ts (100%) create mode 100644 packages/walletkit/src/core/modals/ConnectModal/ConnectingView/index.tsx rename packages/walletkit/src/{modals/ConnectModal/Connecting => core/modals/ConnectModal/ConnectingView}/styles.css.ts (83%) create mode 100644 packages/walletkit/src/core/modals/ConnectModal/ConnectorsView/GridLayout/WalletOption/index.tsx rename packages/walletkit/src/{modals/ConnectModal/Connectors => core/modals/ConnectModal/ConnectorsView}/GridLayout/WalletOption/styles.css.ts (92%) create mode 100644 packages/walletkit/src/core/modals/ConnectModal/ConnectorsView/GridLayout/index.tsx rename packages/walletkit/src/{modals/ConnectModal/Connectors => core/modals/ConnectModal/ConnectorsView}/GridLayout/styles.css.ts (86%) create mode 100644 packages/walletkit/src/core/modals/ConnectModal/ConnectorsView/ListLayout/WalletOption/index.tsx rename packages/walletkit/src/{modals/ConnectModal/Connectors => core/modals/ConnectModal/ConnectorsView}/ListLayout/WalletOption/styles.css.ts (90%) create mode 100644 packages/walletkit/src/core/modals/ConnectModal/ConnectorsView/ListLayout/index.tsx rename packages/walletkit/src/{modals/ConnectModal/Connectors => core/modals/ConnectModal/ConnectorsView}/ListLayout/styles.css.ts (100%) create mode 100644 packages/walletkit/src/core/modals/ConnectModal/ConnectorsView/SetWalletClickRef/index.tsx create mode 100644 packages/walletkit/src/core/modals/ConnectModal/ConnectorsView/index.tsx rename packages/walletkit/src/{modals/ConnectModal/Connectors => core/modals/ConnectModal/ConnectorsView}/styles.css.ts (81%) rename packages/walletkit/src/{ => core}/modals/ConnectModal/RouteProvider/context.tsx (93%) rename packages/walletkit/src/{ => core}/modals/ConnectModal/RouteProvider/index.tsx (53%) rename packages/walletkit/src/{ => core}/modals/ConnectModal/context.ts (57%) rename packages/walletkit/src/{ => core}/modals/ConnectModal/index.tsx (52%) create mode 100644 packages/walletkit/src/core/modals/ConnectModal/provider.tsx rename packages/walletkit/src/{components => core/providers}/ThemeProvider/context.ts (100%) rename packages/walletkit/src/{components => core/providers}/ThemeProvider/index.tsx (83%) rename packages/walletkit/src/{ => core/providers/ThemeProvider}/themes/base.ts (96%) create mode 100644 packages/walletkit/src/core/providers/WalletKitProvider/context.ts create mode 100644 packages/walletkit/src/core/providers/WalletKitProvider/index.tsx rename packages/walletkit/src/{ => core}/utils/account.ts (78%) create mode 100644 packages/walletkit/src/core/utils/common.ts create mode 100644 packages/walletkit/src/core/utils/eventEmitter.ts delete mode 100644 packages/walletkit/src/defaultConfig/defaultWagmiConfig.ts delete mode 100644 packages/walletkit/src/defaultConfig/getDefaultChainsConfig.tsx delete mode 100644 packages/walletkit/src/defaultConfig/getDefaultWalletKitOptions.ts delete mode 100644 packages/walletkit/src/defaultConfig/getDefaultWallets.ts rename packages/walletkit/src/{ => evm}/components/EthereumScript/index.tsx (100%) create mode 100644 packages/walletkit/src/evm/components/EvmConnectWithQRCodeView/index.tsx create mode 100644 packages/walletkit/src/evm/components/EvmConnectingView/index.tsx create mode 100644 packages/walletkit/src/evm/components/EvmWalletProvider/index.tsx create mode 100644 packages/walletkit/src/evm/components/SetEvmWalletClickRef/index.tsx rename packages/walletkit/src/{hooks/useWalletKitBalance.ts => evm/hooks/useEvmBalance.ts} (71%) rename packages/walletkit/src/{hooks/useWalletKitConnect.ts => evm/hooks/useEvmConnect.ts} (54%) create mode 100644 packages/walletkit/src/evm/hooks/useEvmSwitchChain.ts rename packages/walletkit/src/{ => evm}/hooks/useIsConnected.ts (100%) rename packages/walletkit/src/{ => evm}/hooks/useQRCodeUri.ts (80%) create mode 100644 packages/walletkit/src/evm/hooks/useWalletConnectConnector.ts rename packages/walletkit/src/{ => evm}/hooks/useWalletConnectModal.ts (68%) create mode 100644 packages/walletkit/src/evm/hooks/useWalletConnector.ts create mode 100644 packages/walletkit/src/evm/index.ts create mode 100644 packages/walletkit/src/evm/utils/evmCommonErrorHandler.ts create mode 100644 packages/walletkit/src/evm/utils/getEvmConfig.ts rename packages/walletkit/src/{ => evm}/wallets/binanceWeb3Wallet/index.tsx (50%) create mode 100644 packages/walletkit/src/evm/wallets/bitgetWallet/index.tsx create mode 100644 packages/walletkit/src/evm/wallets/coinbaseWallet/index.tsx rename packages/walletkit/src/{ => evm}/wallets/index.ts (100%) rename packages/walletkit/src/{ => evm}/wallets/injected.ts (100%) create mode 100644 packages/walletkit/src/evm/wallets/mathWallet/index.tsx create mode 100644 packages/walletkit/src/evm/wallets/metaMask/index.tsx create mode 100644 packages/walletkit/src/evm/wallets/okxWallet/index.tsx create mode 100644 packages/walletkit/src/evm/wallets/safe/index.tsx create mode 100644 packages/walletkit/src/evm/wallets/tokenPocket/index.tsx create mode 100644 packages/walletkit/src/evm/wallets/trustWallet/index.tsx create mode 100644 packages/walletkit/src/evm/wallets/types.ts rename packages/walletkit/src/{ => evm}/wallets/utils.ts (62%) rename packages/walletkit/src/{ => evm}/wallets/walletConnect/index.tsx (50%) delete mode 100644 packages/walletkit/src/hooks/useChainConfig.ts delete mode 100644 packages/walletkit/src/hooks/useChainIsSupported.ts delete mode 100644 packages/walletkit/src/hooks/useClickWallet.ts delete mode 100644 packages/walletkit/src/hooks/useCloseAllModals.ts delete mode 100644 packages/walletkit/src/hooks/useWalletConfig.ts delete mode 100644 packages/walletkit/src/hooks/useWalletConnectConnector.ts delete mode 100644 packages/walletkit/src/hooks/useWalletDownloadUrl.ts delete mode 100644 packages/walletkit/src/hooks/useWalletKitSwitchChain.ts delete mode 100644 packages/walletkit/src/hooks/useWalletRender.ts delete mode 100644 packages/walletkit/src/index.ts delete mode 100644 packages/walletkit/src/modals/ConnectModal/ConnectWithQRCode/index.tsx delete mode 100644 packages/walletkit/src/modals/ConnectModal/Connecting/UnsupportedContent/index.tsx delete mode 100644 packages/walletkit/src/modals/ConnectModal/Connecting/index.tsx delete mode 100644 packages/walletkit/src/modals/ConnectModal/Connectors/GridLayout/WalletOption/index.tsx delete mode 100644 packages/walletkit/src/modals/ConnectModal/Connectors/GridLayout/index.tsx delete mode 100644 packages/walletkit/src/modals/ConnectModal/Connectors/ListLayout/WalletOption/index.tsx delete mode 100644 packages/walletkit/src/modals/ConnectModal/Connectors/ListLayout/index.tsx delete mode 100644 packages/walletkit/src/modals/ConnectModal/Connectors/index.tsx delete mode 100644 packages/walletkit/src/modals/ConnectModal/provider.tsx delete mode 100644 packages/walletkit/src/modals/EmbeddedConnectModal/index.tsx delete mode 100644 packages/walletkit/src/modals/EmbeddedConnectModal/style.css.ts delete mode 100644 packages/walletkit/src/modals/ProfileModal/CopyToClipboard/index.tsx delete mode 100644 packages/walletkit/src/modals/ProfileModal/CopyToClipboard/styles.css.ts delete mode 100644 packages/walletkit/src/modals/ProfileModal/context.ts delete mode 100644 packages/walletkit/src/modals/ProfileModal/index.tsx delete mode 100644 packages/walletkit/src/modals/ProfileModal/provider.tsx delete mode 100644 packages/walletkit/src/modals/ProfileModal/styles.css.ts delete mode 100644 packages/walletkit/src/modals/SwitchNetworkModal/ChainOption/index.tsx delete mode 100644 packages/walletkit/src/modals/SwitchNetworkModal/ChainOption/styles.css.ts delete mode 100644 packages/walletkit/src/modals/SwitchNetworkModal/ChainSpinner/index.tsx delete mode 100644 packages/walletkit/src/modals/SwitchNetworkModal/ChainSpinner/styles.css.ts delete mode 100644 packages/walletkit/src/modals/SwitchNetworkModal/context.ts delete mode 100644 packages/walletkit/src/modals/SwitchNetworkModal/index.tsx delete mode 100644 packages/walletkit/src/modals/SwitchNetworkModal/provider.tsx delete mode 100644 packages/walletkit/src/modals/SwitchNetworkModal/styles.css.ts create mode 100644 packages/walletkit/src/solana/components/SetSolanaWalletClickRef/index.tsx create mode 100644 packages/walletkit/src/solana/components/SolanaConnectWithQRCodeView/index.tsx create mode 100644 packages/walletkit/src/solana/components/SolanaConnectingView/index.tsx create mode 100644 packages/walletkit/src/solana/components/SolanaWalletProvider/index.tsx create mode 100644 packages/walletkit/src/solana/index.ts create mode 100644 packages/walletkit/src/solana/utils/getSolanaConfig.ts create mode 100644 packages/walletkit/src/solana/utils/solanaCommonErrorHandler.ts create mode 100644 packages/walletkit/src/solana/wallets/index.ts create mode 100644 packages/walletkit/src/solana/wallets/phantomWallet/index.tsx create mode 100644 packages/walletkit/src/solana/wallets/trustWallet/index.tsx create mode 100644 packages/walletkit/src/solana/wallets/types.ts create mode 100644 packages/walletkit/src/solana/wallets/utils.ts create mode 100644 packages/walletkit/src/solana/wallets/walletConnect/index.tsx delete mode 100644 packages/walletkit/src/types.ts delete mode 100644 packages/walletkit/src/utils/common.ts delete mode 100644 packages/walletkit/src/wallets/bitgetWallet/index.tsx delete mode 100644 packages/walletkit/src/wallets/coinbaseWallet/index.tsx delete mode 100644 packages/walletkit/src/wallets/mathWallet/index.tsx delete mode 100644 packages/walletkit/src/wallets/metaMask/index.tsx delete mode 100644 packages/walletkit/src/wallets/okxWallet/index.tsx delete mode 100644 packages/walletkit/src/wallets/safe/index.tsx delete mode 100644 packages/walletkit/src/wallets/tokenPocket/index.tsx delete mode 100644 packages/walletkit/src/wallets/trustWallet/index.tsx delete mode 100644 packages/walletkit/src/wallets/types.ts delete mode 100644 packages/walletkit/styles.css/package.json delete mode 100644 packages/walletkit/wallets/package.json diff --git a/.changeset/friendly-weeks-applaud.md b/.changeset/friendly-weeks-applaud.md new file mode 100644 index 00000000..ee780f79 --- /dev/null +++ b/.changeset/friendly-weeks-applaud.md @@ -0,0 +1,5 @@ +--- +'@node-real/walletkit': minor +--- + +refactor: solana and evm are unified into one package diff --git a/examples/nextjs/package.json b/examples/nextjs/package.json index 8390e60e..cdd60926 100644 --- a/examples/nextjs/package.json +++ b/examples/nextjs/package.json @@ -11,12 +11,14 @@ }, "dependencies": { "@node-real/walletkit": "workspace:*", + "@tanstack/react-query": "^5", + "encoding": "^0.1.13", "next": "^14", + "pino-pretty": "^11.2.2", "react": "^18", "react-dom": "^18", "viem": "^2", - "wagmi": "^2", - "@tanstack/react-query": "^5.51.1" + "wagmi": "^2" }, "devDependencies": { "@types/node": "^20", diff --git a/examples/nextjs/pages/_app.tsx b/examples/nextjs/pages/_app.tsx index 02dfb412..2b91e0a3 100644 --- a/examples/nextjs/pages/_app.tsx +++ b/examples/nextjs/pages/_app.tsx @@ -1,62 +1,75 @@ import '@node-real/walletkit/styles.css'; import '@/styles/globals.css'; -import { bsc, mainnet, opBNB } from 'wagmi/chains'; +import { mainnet } from 'wagmi/chains'; -import { trustWallet, metaMask, walletConnect } from '@node-real/walletkit/wallets'; +import { trustWallet, metaMask, walletConnect } from '@node-real/walletkit/evm'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { - defaultWagmiConfig, - SwitchNetworkModal, - WalletKitButton, - WalletKitOptions, WalletKitProvider, - ProfileModal, ConnectModal, + useConnectModal, + WalletKitConfig, } from '@node-real/walletkit'; -import { WagmiProvider } from 'wagmi'; import { AppProps } from 'next/app'; +import { + trustWallet as solanaTrustWallet, + phantomWallet as solanaPhantomWallet, +} from '@node-real/walletkit/solana'; const queryClient = new QueryClient(); -const config = defaultWagmiConfig({ - appName: 'WalletKit', - chains: [bsc, mainnet, opBNB], - connectors: [trustWallet(), metaMask(), walletConnect()], - - // WalletConnect 2.0 requires a projectId which you can create quickly - // and easily for free over at WalletConnect Cloud https://cloud.walletconnect.com/sign-in - walletConnectProjectId: 'e68a1816d39726c2afabf05661a32767', -}); - -const options: WalletKitOptions = { - initialChainId: 1, +const config: WalletKitConfig = { + walletSetting: { + autoConnect: true, + evm: { + initialChainId: 1, + wallets: [metaMask(), trustWallet(), walletConnect()], + chains: [mainnet] as any[], + }, + solana: { + rpcUrl: 'https://solana-rpc.debridge.finance', + wallets: [solanaTrustWallet(), solanaPhantomWallet()], + }, + }, + appearance: { + mode: 'light', + }, + events: { + closeModalOnEsc: false, + closeModalOnOverlayClick: false, + closeModalAfterConnected: true, + }, }; export default function App({ Component, pageProps }: AppProps) { return ( - + - - - - + - + {/* */} + + - {/* + {/* Profile modal shows some basic information about the current account, If you don't need this modal, you can remove it. */} - + {/* */} - {/* + {/* 👇 Here's the SwitchNetworkModal If the user switches to a network that is not supported by our dApp, this modal will be displayed to remind the user to switch to our supported networks. */} - - + {/* */} - + ); } + +function ConnectButton() { + const { onOpen } = useConnectModal(); + + return ; +} diff --git a/examples/nextjs/pages/_document.tsx b/examples/nextjs/pages/_document.tsx index ef37a5de..f6de4d29 100644 --- a/examples/nextjs/pages/_document.tsx +++ b/examples/nextjs/pages/_document.tsx @@ -1,5 +1,5 @@ import { Html, Head, Main, NextScript } from 'next/document'; -import { EthereumScript } from '@node-real/walletkit'; +import { EthereumScript } from '@node-real/walletkit/evm'; export default function Document() { return ( diff --git a/examples/vite/package.json b/examples/vite/package.json index a8fb2855..de7d4431 100644 --- a/examples/vite/package.json +++ b/examples/vite/package.json @@ -11,11 +11,12 @@ }, "dependencies": { "@node-real/walletkit": "workspace:*", + "@particle-network/connectkit": "^2.0.0", + "@tanstack/react-query": "^5", "react": "^18", "react-dom": "^18", "viem": "^2", - "wagmi": "^2", - "@tanstack/react-query": "^5.51.1" + "wagmi": "^2" }, "devDependencies": { "@types/react": "^18", diff --git a/examples/vite/src/App.tsx b/examples/vite/src/App.tsx index 6059af0d..d22b1712 100644 --- a/examples/vite/src/App.tsx +++ b/examples/vite/src/App.tsx @@ -1,47 +1,109 @@ -import '@node-real/walletkit/styles.css'; -import './global.css'; -import { bsc, mainnet, opBNB } from 'wagmi/chains'; - -import { trustWallet, metaMask, walletConnect } from '@node-real/walletkit/wallets'; -import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { + BaseWallet, ConnectModal, - defaultWagmiConfig, - ProfileModal, - SwitchNetworkModal, - WalletKitButton, - WalletKitOptions, + useConnectModal, + useWallets, + WalletKitConfig, WalletKitProvider, } from '@node-real/walletkit'; -import { WagmiProvider } from 'wagmi'; - -const queryClient = new QueryClient(); +import VConsole from 'vconsole'; +import { metaMask, trustWallet, walletConnect } from '@node-real/walletkit/evm'; +import { + trustWallet as solanaTrustWallet, + phantomWallet as solanaPhantomWallet, +} from '@node-real/walletkit/solana'; +import { mainnet } from 'viem/chains'; +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; -const config = defaultWagmiConfig({ - appName: 'WalletKit', - chains: [mainnet, bsc, opBNB], - connectors: [trustWallet(), metaMask(), walletConnect()], +new VConsole(); - // WalletConnect 2.0 requires a projectId which you can create quickly - // and easily for free over at WalletConnect Cloud https://cloud.walletconnect.com/sign-in - walletConnectProjectId: 'e68a1816d39726c2afabf05661a32767', -}); +const queryClient = new QueryClient(); -const options: WalletKitOptions = { - initialChainId: 1, +const config: WalletKitConfig = { + walletSetting: { + autoConnect: true, + evm: { + initialChainId: 1, + wallets: [metaMask(), trustWallet(), walletConnect()], + chains: [mainnet] as any[], + }, + solana: { + rpcUrl: 'https://solana-rpc.debridge.finance', + wallets: [solanaTrustWallet(), solanaPhantomWallet()], + }, + }, + appearance: {}, + events: { + closeModalOnEsc: false, + closeModalOnOverlayClick: false, + closeModalAfterConnected: true, + }, }; export default function App() { return ( - + - - - - - - + + - + + ); +} + +function selectWallets(wallets: BaseWallet[], include: string, exclude: string) { + const newWallets: BaseWallet[] = []; + wallets.forEach((item) => { + if (item.walletType === include) { + newWallets.push({ ...item }); + } else if (item.walletType === exclude) { + newWallets.push({ + ...item, + render: ({ wallet, onClick }) => { + return ; + }, + }); + } + }); + + newWallets.forEach((item) => { + if ( + newWallets.find( + (e) => e.walletType === include && item.walletType === exclude && e.id === item.id, + ) + ) { + item.isVisible = false; + } + }); + + newWallets.sort((a, b) => { + if (a.walletType === b.walletType) return 0; + if (a.walletType === include) return -1; + return 0; + }); + + return newWallets; +} + +function ConnectButton() { + const { onOpen } = useConnectModal(); + const { wallets, setWallets } = useWallets(); + + const onEvm = () => { + const newWallets = selectWallets(wallets, 'evm', 'solana'); + setWallets(newWallets); + }; + + const onSolana = () => { + const newWallets = selectWallets(wallets, 'solana', 'evm'); + setWallets(newWallets); + }; + + return ( + <> + + + + ); } diff --git a/package.json b/package.json index 19c4a0ca..95bfd91d 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,7 @@ "scripts": { "prepare": "husky install", "lint": "pnpm eslint .", - "dev": "pnpm --F @node-real/walletkit dev", - "build": "pnpm --F @node-real/walletkit build", - "dev:docs": "pnpm --F @node-real/walletkit build:watch & pnpm --F website dev", + "build": "pnpm --F @node-real/* build", "build:docs": "pnpm build && pnpm --F website build", "ci:enter": "pnpm changeset pre enter alpha || true", "ci:exit": "pnpm changeset pre exit || true", @@ -21,7 +19,7 @@ "ci:stable-version": "pnpm ci:exit && pnpm ci:version" }, "devDependencies": { - "@changesets/cli": "^2.27.5", + "@changesets/cli": "^2.27.7", "@commitlint/cli": "^18.6.1", "@commitlint/config-conventional": "^18.6.3", "@typescript-eslint/eslint-plugin": "^5.62.0", @@ -30,7 +28,7 @@ "eslint-plugin-react-hooks": "^4.6.2", "eslint-plugin-react-refresh": "^0.3.5", "husky": "^8.0.3", - "lint-staged": "^15.2.7", - "prettier": "^3.3.2" + "lint-staged": "^15.2.9", + "prettier": "^3.3.3" } } diff --git a/packages/walletkit/CHANGELOG.md b/packages/walletkit/CHANGELOG.md deleted file mode 100644 index f3ecfd30..00000000 --- a/packages/walletkit/CHANGELOG.md +++ /dev/null @@ -1,40 +0,0 @@ -# @node-real/walletkit - -## 2.0.3 - -### Patch Changes - -- 5b7f3f6: test: Add log -- 5b7f3f6: fix: ssr no need to wait for the provider to be ready - -## 2.0.3-alpha.0 - -### Patch Changes - -- d5437a7: test: Add log -- 90846a4: fix: ssr no need to wait for the provider to be ready - -## 2.0.2 - -### Patch Changes - -- 1fed209: feat: Upgrade wagmi & viem to 2.x -- 1fed209: fix: ssr no need to wait for the provider to be ready - -## 2.0.2-alpha.0 - -### Patch Changes - -- 90846a4: fix: ssr no need to wait for the provider to be ready - -## 2.0.1 - -### Patch Changes - -- 83c5001: feat: Upgrade wagmi & viem to 2.x - -## 2.0.1-alpha.0 - -### Patch Changes - -- 919b9ba: feat: Upgrade wagmi & viem to 2.x diff --git a/packages/walletkit/__dev__/App.tsx b/packages/walletkit/__dev__/App.tsx index 0f02686d..8e572c48 100644 --- a/packages/walletkit/__dev__/App.tsx +++ b/packages/walletkit/__dev__/App.tsx @@ -1,89 +1,110 @@ -import { useState } from 'react'; -import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; -import { WagmiProvider } from 'wagmi'; -import VConsole from 'vconsole'; import { + BaseWallet, ConnectModal, - ProfileModal, - SwitchNetworkModal, - ThemeMode, - WalletKitButton, - WalletKitOptions, - WalletKitProvider, - defaultWagmiConfig, useConnectModal, - useProfileModal, - useSwitchNetworkModal, -} from '@/index'; + useWallets, + WalletKitConfig, + WalletKitProvider, +} from '@/core/index'; +import './style.css'; +import VConsole from 'vconsole'; +import { metaMask, trustWallet, walletConnect } from '@/evm/index'; import { - binanceWeb3Wallet, - bitgetWallet, - coinbaseWallet, - metaMask, - okxWallet, - tokenPocket, - trustWallet, - walletConnect, -} from '@/wallets'; -import { chains } from './chains'; - -const queryClient = new QueryClient(); + trustWallet as solanaTrustWallet, + phantomWallet as solanaPhantomWallet, +} from '@/solana/index'; +import { mainnet } from 'viem/chains'; +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; new VConsole(); -const config = defaultWagmiConfig({ - appName: 'WalletKit', - chains, - connectors: [ - binanceWeb3Wallet(), - bitgetWallet(), - coinbaseWallet(), - metaMask(), - okxWallet(), - tokenPocket(), - trustWallet(), - walletConnect(), - ], -}); +const queryClient = new QueryClient(); -const options: WalletKitOptions = { - initialChainId: 204, +const config: WalletKitConfig = { + walletSetting: { + autoConnect: true, + evm: { + initialChainId: 1, + wallets: [metaMask(), trustWallet(), walletConnect()], + chains: [mainnet], + }, + solana: { + rpcUrl: 'https://solana-rpc.debridge.finance', + wallets: [solanaTrustWallet(), solanaPhantomWallet()], + }, + }, + appearance: {}, + events: { + closeModalOnEsc: false, + closeModalOnOverlayClick: false, + closeModalAfterConnected: true, + }, }; export default function App() { - const [mode, setMode] = useState('light'); - const nextMode = mode === 'light' ? 'dark' : 'light'; - return ( - + - -
mode: {mode}
- -
- - - - - - - - + + - + ); } -function Example() { - const connectModal = useConnectModal(); - const profileModal = useProfileModal(); - const switchNetworkModal = useSwitchNetworkModal(); +function selectWallets(wallets: BaseWallet[], include: string, exclude: string) { + const newWallets: BaseWallet[] = []; + wallets.forEach((item) => { + if (item.walletType === include) { + newWallets.push({ ...item }); + } else if (item.walletType === exclude) { + newWallets.push({ + ...item, + render: ({ wallet, onClick }) => { + return ; + }, + }); + } + }); + + newWallets.forEach((item) => { + if ( + newWallets.find( + (e) => e.walletType === include && item.walletType === exclude && e.id === item.id, + ) + ) { + item.isVisible = false; + } + }); + + newWallets.sort((a, b) => { + if (a.walletType === b.walletType) return 0; + if (a.walletType === include) return -1; + return 0; + }); + + return newWallets; +} + +function ConnectButton() { + const { onOpen } = useConnectModal(); + const { wallets, setWallets } = useWallets(); + + const onEvm = () => { + const newWallets = selectWallets(wallets, 'evm', 'solana'); + setWallets(newWallets); + }; + + const onSolana = () => { + const newWallets = selectWallets(wallets, 'solana', 'evm'); + setWallets(newWallets); + }; return ( <> - - - + + + ); } diff --git a/packages/walletkit/__dev__/chains.ts b/packages/walletkit/__dev__/chains.ts deleted file mode 100644 index b2067fd4..00000000 --- a/packages/walletkit/__dev__/chains.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { bsc, bscTestnet, mainnet, opBNB } from 'wagmi/chains'; - -export const chains = [ - { - id: 1017, - name: 'BNB Greenfield', - nativeCurrency: { - name: 'tBNB', - symbol: 'tBNB', - decimals: 18, - }, - rpcUrls: { - default: { - http: [`https://greenfield-chain-us.bnbchain.org`], - }, - public: { - http: [`https://greenfield-chain-us.bnbchain.org`], - }, - }, - blockExplorers: { - etherscan: { name: 'Greenfield Scan', url: `https://greenfieldscan.com` }, - default: { name: 'Greenfield Scan', url: `https://greenfieldscan.com` }, - }, - }, - opBNB, - bscTestnet, - bsc, - mainnet, -]; diff --git a/packages/walletkit/__dev__/index.html b/packages/walletkit/__dev__/index.html index 07e23793..d7134589 100644 --- a/packages/walletkit/__dev__/index.html +++ b/packages/walletkit/__dev__/index.html @@ -2,7 +2,6 @@ - WalletKit Test Demo