@ant-design/web3-sui 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @ant-design/web3-sui
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 9bb1ea1: feat: Add Sui adapter
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [9bb1ea1]
12
+ - @ant-design/web3-common@1.13.0
13
+ - @ant-design/web3-assets@1.10.2
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Ant Design Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @ant-design/web3-solana
2
+
3
+ This package provides a [Sui](https://sui.io) adapter for [@ant-design/web3](https://www.npmjs.com/package/@ant-design/web3).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @ant-design/web3 @ant-design/web3-sui --save
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```tsx
14
+ import { ConnectButton, Connector } from '@ant-design/web3';
15
+ import { SuiWallet, SuiWeb3ConfigProvider } from '@ant-design/web3-sui';
16
+
17
+ const App: React.FC = () => {
18
+ return (
19
+ <SuiWeb3ConfigProvider>
20
+ <Connector>
21
+ <ConnectButton />
22
+ </Connector>
23
+ </SuiWeb3ConfigProvider>
24
+ );
25
+ };
26
+
27
+ export default App;
28
+ ```
29
+
30
+ For more examples, refer to [Sui - Ant Design Web3](https://web3.ant.design/components/sui).
31
+
32
+ ## Documentation
33
+
34
+ - For more information, visit [Ant Design Web3](https://web3.ant.design).
35
+ - For an introduction to Sui, visit [Sui](https://sui.io).
@@ -0,0 +1,10 @@
1
+ import type { Chain } from '@ant-design/web3-common';
2
+ import { SuiChainIds } from '@ant-design/web3-common';
3
+ export interface SuiChain extends Chain {
4
+ id: SuiChainIds;
5
+ network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
6
+ }
7
+ export declare const suiMainnet: SuiChain;
8
+ export declare const suiTestnet: SuiChain;
9
+ export declare const suiDevnet: SuiChain;
10
+ export declare const suiLocalnet: SuiChain;
@@ -0,0 +1,64 @@
1
+ import React from 'react';
2
+ import { createGetBrowserLink, SuiChainIds } from '@ant-design/web3-common';
3
+ import { SuiColorful } from '@ant-design/web3-icons';
4
+ import { SUI_DECIMALS } from '@mysten/sui/utils';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ export const suiMainnet = {
7
+ id: SuiChainIds.Mainnet,
8
+ name: 'Sui',
9
+ network: 'mainnet',
10
+ icon: /*#__PURE__*/_jsx(SuiColorful, {}),
11
+ browser: {
12
+ icon: /*#__PURE__*/_jsx(SuiColorful, {}),
13
+ getBrowserLink: createGetBrowserLink('https://suiscan.xyz/mainnet')
14
+ },
15
+ nativeCurrency: {
16
+ name: 'Sui',
17
+ symbol: 'SUI',
18
+ decimals: SUI_DECIMALS
19
+ }
20
+ };
21
+ export const suiTestnet = {
22
+ id: SuiChainIds.Testnet,
23
+ name: 'Sui Testnet',
24
+ network: 'testnet',
25
+ icon: /*#__PURE__*/_jsx(SuiColorful, {}),
26
+ browser: {
27
+ icon: /*#__PURE__*/_jsx(SuiColorful, {}),
28
+ getBrowserLink: createGetBrowserLink('https://suiscan.xyz/testnet')
29
+ },
30
+ nativeCurrency: {
31
+ name: 'Sui',
32
+ symbol: 'SUI',
33
+ decimals: SUI_DECIMALS
34
+ }
35
+ };
36
+ export const suiDevnet = {
37
+ id: SuiChainIds.Devnet,
38
+ name: 'Sui Devnet',
39
+ network: 'devnet',
40
+ icon: /*#__PURE__*/_jsx(SuiColorful, {}),
41
+ browser: {
42
+ icon: /*#__PURE__*/_jsx(SuiColorful, {}),
43
+ getBrowserLink: createGetBrowserLink('https://suiscan.xyz/devnet')
44
+ },
45
+ nativeCurrency: {
46
+ name: 'Sui',
47
+ symbol: 'SUI',
48
+ decimals: SUI_DECIMALS
49
+ }
50
+ };
51
+ export const suiLocalnet = {
52
+ id: SuiChainIds.Localnet,
53
+ name: 'Sui Localnet',
54
+ network: 'localnet',
55
+ icon: /*#__PURE__*/_jsx(SuiColorful, {}),
56
+ browser: {
57
+ icon: /*#__PURE__*/_jsx(SuiColorful, {})
58
+ },
59
+ nativeCurrency: {
60
+ name: 'Sui',
61
+ symbol: 'SUI',
62
+ decimals: SUI_DECIMALS
63
+ }
64
+ };
@@ -0,0 +1,4 @@
1
+ export * from './chain';
2
+ export * from './sui-provider';
3
+ export * from './wallets/built-in';
4
+ export * from './wallets/factory';
@@ -0,0 +1,4 @@
1
+ export * from "./chain";
2
+ export * from "./sui-provider";
3
+ export * from "./wallets/built-in";
4
+ export * from "./wallets/factory";
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import type { Locale } from '@ant-design/web3-common';
3
+ import type { SuiChain } from '../chain';
4
+ import type { WalletFactory } from '../wallets/types';
5
+ export interface AntDesignWeb3ConfigProviderProps {
6
+ balance?: boolean;
7
+ locale?: Locale;
8
+ availableChains?: SuiChain[];
9
+ availableWallets?: WalletFactory[];
10
+ currentChain?: SuiChain;
11
+ sns?: boolean;
12
+ onCurrentChainChange: (network: string) => void;
13
+ }
14
+ export declare const AntDesignWeb3ConfigProvider: React.FC<React.PropsWithChildren<AntDesignWeb3ConfigProviderProps>>;
@@ -0,0 +1,116 @@
1
+ import React, { useCallback, useMemo } from 'react';
2
+ import { SUI } from '@ant-design/web3-assets/tokens';
3
+ import { Web3ConfigProvider } from '@ant-design/web3-common';
4
+ import { SuiColorful } from '@ant-design/web3-icons';
5
+ import { useConnectWallet, useCurrentAccount, useDisconnectWallet, useResolveSuiNSName, useSuiClient, useSuiClientQuery, useWallets } from '@mysten/dapp-kit';
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ export const AntDesignWeb3ConfigProvider = ({
8
+ balance: showBalance,
9
+ locale,
10
+ availableChains,
11
+ availableWallets,
12
+ currentChain,
13
+ sns,
14
+ onCurrentChainChange,
15
+ children
16
+ }) => {
17
+ const account = useCurrentAccount();
18
+ const standardWallets = useWallets();
19
+ const {
20
+ mutateAsync: connectAsync
21
+ } = useConnectWallet();
22
+ const {
23
+ mutateAsync: disconnectAsync
24
+ } = useDisconnectWallet();
25
+ const {
26
+ data: snsData
27
+ } = useResolveSuiNSName(sns ? account?.address : undefined);
28
+ const client = useSuiClient();
29
+ const {
30
+ data: balanceData
31
+ } = useSuiClientQuery('getBalance', {
32
+ owner: account?.address ?? ''
33
+ }, {
34
+ select(data) {
35
+ return BigInt(data.totalBalance);
36
+ }
37
+ });
38
+ const accountData = account ? {
39
+ address: account.address,
40
+ name: sns && snsData ? snsData : undefined
41
+ } : undefined;
42
+ const allWallets = useMemo(() => {
43
+ const standardWalletNames = standardWallets.map(w => w.name);
44
+ const fixedWallets = availableWallets?.map(factory => factory.create())?.filter(w => !standardWalletNames.includes(w.name));
45
+ const injectedWalletAssets = standardWallets.map(w => {
46
+ return {
47
+ name: w.name,
48
+ icon: w.icon,
49
+ remark: w.name,
50
+ _standardWallet: w,
51
+ async hasExtensionInstalled() {
52
+ return true;
53
+ },
54
+ async hasWalletReady() {
55
+ return true;
56
+ }
57
+ };
58
+ });
59
+ return fixedWallets ? fixedWallets.concat(injectedWalletAssets) : injectedWalletAssets;
60
+ }, [availableWallets, standardWallets]);
61
+ const getNFTMetadataFunc = useCallback(async ({
62
+ address
63
+ }) => {
64
+ const {
65
+ data: nftData
66
+ } = await client.getObject({
67
+ id: address,
68
+ options: {
69
+ showContent: true,
70
+ showDisplay: true
71
+ }
72
+ });
73
+ const displayData = nftData?.display?.data;
74
+ const objectFields = nftData?.content?.dataType === 'moveObject' ? nftData.content.fields : undefined;
75
+ return {
76
+ image: displayData?.image_url,
77
+ date: objectFields?.birthdate,
78
+ attributes: objectFields?.attributes,
79
+ description: displayData?.description,
80
+ edition: nftData?.version
81
+ };
82
+ }, [client]);
83
+ return /*#__PURE__*/_jsx(Web3ConfigProvider, {
84
+ availableChains: availableChains,
85
+ availableWallets: allWallets,
86
+ locale: locale,
87
+ account: accountData,
88
+ chain: currentChain,
89
+ balance: showBalance ? {
90
+ symbol: SUI.symbol,
91
+ decimals: SUI.decimal,
92
+ value: balanceData,
93
+ icon: /*#__PURE__*/_jsx(SuiColorful, {})
94
+ } : undefined,
95
+ connect: async wallet => {
96
+ const foundWallet = wallet?._standardWallet;
97
+ if (!foundWallet) {
98
+ throw new Error(`Can not find wallet ${wallet?.name}`);
99
+ }
100
+ await connectAsync({
101
+ wallet: foundWallet
102
+ });
103
+ },
104
+ disconnect: async () => {
105
+ await disconnectAsync();
106
+ },
107
+ switchChain: async chain => {
108
+ const network = availableChains?.find(item => item.id === chain.id)?.network;
109
+ if (network) {
110
+ onCurrentChainChange(network);
111
+ }
112
+ },
113
+ getNFTMetadata: getNFTMetadataFunc,
114
+ children: children
115
+ });
116
+ };
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import type { Locale } from '@ant-design/web3-common';
3
+ import { createNetworkConfig } from '@mysten/dapp-kit';
4
+ import { QueryClient } from '@tanstack/react-query';
5
+ import type { WalletFactory } from '../wallets/types';
6
+ export interface SuiWeb3ConfigProviderProps {
7
+ balance?: boolean;
8
+ locale?: Locale;
9
+ autoConnect?: boolean;
10
+ networkConfig?: ReturnType<typeof createNetworkConfig>['networkConfig'];
11
+ sns?: boolean;
12
+ defaultNetwork?: string;
13
+ wallets?: WalletFactory[];
14
+ queryClient?: QueryClient;
15
+ }
16
+ export declare const SuiWeb3ConfigProvider: React.FC<React.PropsWithChildren<SuiWeb3ConfigProviderProps>>;
@@ -0,0 +1,59 @@
1
+ import React, { useContext } from 'react';
2
+ import { createNetworkConfig, SuiClientProvider, WalletProvider } from '@mysten/dapp-kit';
3
+ import { getFullnodeUrl } from '@mysten/sui/client';
4
+ import { QueryClient, QueryClientContext, QueryClientProvider } from '@tanstack/react-query';
5
+ import { suiDevnet, suiLocalnet, suiMainnet, suiTestnet } from "../chain";
6
+ import { AntDesignWeb3ConfigProvider } from "./config-provider";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ export const SuiWeb3ConfigProvider = ({
9
+ autoConnect,
10
+ balance,
11
+ locale,
12
+ networkConfig,
13
+ defaultNetwork = 'mainnet',
14
+ queryClient,
15
+ sns,
16
+ wallets,
17
+ children
18
+ }) => {
19
+ const [network, setNetwork] = React.useState(defaultNetwork);
20
+ const injectedQueryClient = useContext(QueryClientContext);
21
+ const mergedQueryClient = React.useMemo(() => {
22
+ return queryClient ?? injectedQueryClient ?? new QueryClient();
23
+ }, [injectedQueryClient, queryClient]);
24
+ const mergedNetworkConfig = React.useMemo(() => {
25
+ return networkConfig ?? createNetworkConfig({
26
+ mainnet: {
27
+ url: getFullnodeUrl('mainnet')
28
+ }
29
+ }).networkConfig;
30
+ }, [networkConfig]);
31
+ const networks = React.useMemo(() => {
32
+ const networkConfigKeys = Object.keys(mergedNetworkConfig);
33
+ const networkConfigs = [suiMainnet, suiTestnet, suiDevnet, suiLocalnet];
34
+ return networkConfigKeys.map(networkKey => networkConfigs.find(item => item.network === networkKey)).filter(item => !!item);
35
+ }, [mergedNetworkConfig]);
36
+ const currentNetwork = React.useMemo(() => {
37
+ return networks?.find(item => item.network === network);
38
+ }, [network, networks]);
39
+ return /*#__PURE__*/_jsx(QueryClientProvider, {
40
+ client: mergedQueryClient,
41
+ children: /*#__PURE__*/_jsx(SuiClientProvider, {
42
+ networks: mergedNetworkConfig,
43
+ network: network,
44
+ children: /*#__PURE__*/_jsx(WalletProvider, {
45
+ autoConnect: autoConnect,
46
+ children: /*#__PURE__*/_jsx(AntDesignWeb3ConfigProvider, {
47
+ locale: locale,
48
+ availableChains: networks,
49
+ availableWallets: wallets,
50
+ currentChain: currentNetwork,
51
+ balance: balance,
52
+ sns: sns,
53
+ onCurrentChainChange: setNetwork,
54
+ children: children
55
+ })
56
+ })
57
+ })
58
+ });
59
+ };
@@ -0,0 +1,2 @@
1
+ export declare const Suiet: () => import("./types").WalletFactory;
2
+ export declare const SuiWallet: () => import("./types").WalletFactory;
@@ -0,0 +1,5 @@
1
+ /* v8 ignore start */
2
+ import { metadata_Suiet, metadata_SuiWallet } from '@ant-design/web3-assets';
3
+ import { WalletFactory } from "./factory";
4
+ export const Suiet = () => WalletFactory(metadata_Suiet);
5
+ export const SuiWallet = () => WalletFactory(metadata_SuiWallet);
@@ -0,0 +1,2 @@
1
+ import type { WalletFactoryBuilder } from './types';
2
+ export declare const WalletFactory: WalletFactoryBuilder;
@@ -0,0 +1,15 @@
1
+ /* v8 ignore start */
2
+
3
+ export const WalletFactory = metadata => {
4
+ return {
5
+ create: () => {
6
+ return {
7
+ ...metadata,
8
+ // We simply assume that all wallets implement the `Standard Wallet`,
9
+ // so the wallets provided by `wallets` are not available.
10
+ hasWalletReady: () => Promise.resolve(false),
11
+ hasExtensionInstalled: () => Promise.resolve(false)
12
+ };
13
+ }
14
+ };
15
+ };
@@ -0,0 +1,5 @@
1
+ import type { Wallet, WalletMetadata } from '@ant-design/web3-common';
2
+ export interface WalletFactory {
3
+ create: () => Wallet;
4
+ }
5
+ export type WalletFactoryBuilder = (metadata: WalletMetadata) => WalletFactory;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { Chain } from '@ant-design/web3-common';
2
+ import { SuiChainIds } from '@ant-design/web3-common';
3
+ export interface SuiChain extends Chain {
4
+ id: SuiChainIds;
5
+ network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
6
+ }
7
+ export declare const suiMainnet: SuiChain;
8
+ export declare const suiTestnet: SuiChain;
9
+ export declare const suiDevnet: SuiChain;
10
+ export declare const suiLocalnet: SuiChain;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.suiTestnet = exports.suiMainnet = exports.suiLocalnet = exports.suiDevnet = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _web3Common = require("@ant-design/web3-common");
9
+ var _web3Icons = require("@ant-design/web3-icons");
10
+ var _utils = require("@mysten/sui/utils");
11
+ var _jsxRuntime = require("react/jsx-runtime");
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ const suiMainnet = exports.suiMainnet = {
14
+ id: _web3Common.SuiChainIds.Mainnet,
15
+ name: 'Sui',
16
+ network: 'mainnet',
17
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.SuiColorful, {}),
18
+ browser: {
19
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.SuiColorful, {}),
20
+ getBrowserLink: (0, _web3Common.createGetBrowserLink)('https://suiscan.xyz/mainnet')
21
+ },
22
+ nativeCurrency: {
23
+ name: 'Sui',
24
+ symbol: 'SUI',
25
+ decimals: _utils.SUI_DECIMALS
26
+ }
27
+ };
28
+ const suiTestnet = exports.suiTestnet = {
29
+ id: _web3Common.SuiChainIds.Testnet,
30
+ name: 'Sui Testnet',
31
+ network: 'testnet',
32
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.SuiColorful, {}),
33
+ browser: {
34
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.SuiColorful, {}),
35
+ getBrowserLink: (0, _web3Common.createGetBrowserLink)('https://suiscan.xyz/testnet')
36
+ },
37
+ nativeCurrency: {
38
+ name: 'Sui',
39
+ symbol: 'SUI',
40
+ decimals: _utils.SUI_DECIMALS
41
+ }
42
+ };
43
+ const suiDevnet = exports.suiDevnet = {
44
+ id: _web3Common.SuiChainIds.Devnet,
45
+ name: 'Sui Devnet',
46
+ network: 'devnet',
47
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.SuiColorful, {}),
48
+ browser: {
49
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.SuiColorful, {}),
50
+ getBrowserLink: (0, _web3Common.createGetBrowserLink)('https://suiscan.xyz/devnet')
51
+ },
52
+ nativeCurrency: {
53
+ name: 'Sui',
54
+ symbol: 'SUI',
55
+ decimals: _utils.SUI_DECIMALS
56
+ }
57
+ };
58
+ const suiLocalnet = exports.suiLocalnet = {
59
+ id: _web3Common.SuiChainIds.Localnet,
60
+ name: 'Sui Localnet',
61
+ network: 'localnet',
62
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.SuiColorful, {}),
63
+ browser: {
64
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.SuiColorful, {})
65
+ },
66
+ nativeCurrency: {
67
+ name: 'Sui',
68
+ symbol: 'SUI',
69
+ decimals: _utils.SUI_DECIMALS
70
+ }
71
+ };
@@ -0,0 +1,4 @@
1
+ export * from './chain';
2
+ export * from './sui-provider';
3
+ export * from './wallets/built-in';
4
+ export * from './wallets/factory';
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _chain = require("./chain");
7
+ Object.keys(_chain).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _chain[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _chain[key];
14
+ }
15
+ });
16
+ });
17
+ var _suiProvider = require("./sui-provider");
18
+ Object.keys(_suiProvider).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _suiProvider[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _suiProvider[key];
25
+ }
26
+ });
27
+ });
28
+ var _builtIn = require("./wallets/built-in");
29
+ Object.keys(_builtIn).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _builtIn[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _builtIn[key];
36
+ }
37
+ });
38
+ });
39
+ var _factory = require("./wallets/factory");
40
+ Object.keys(_factory).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _factory[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _factory[key];
47
+ }
48
+ });
49
+ });
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import type { Locale } from '@ant-design/web3-common';
3
+ import type { SuiChain } from '../chain';
4
+ import type { WalletFactory } from '../wallets/types';
5
+ export interface AntDesignWeb3ConfigProviderProps {
6
+ balance?: boolean;
7
+ locale?: Locale;
8
+ availableChains?: SuiChain[];
9
+ availableWallets?: WalletFactory[];
10
+ currentChain?: SuiChain;
11
+ sns?: boolean;
12
+ onCurrentChainChange: (network: string) => void;
13
+ }
14
+ export declare const AntDesignWeb3ConfigProvider: React.FC<React.PropsWithChildren<AntDesignWeb3ConfigProviderProps>>;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AntDesignWeb3ConfigProvider = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _tokens = require("@ant-design/web3-assets/tokens");
9
+ var _web3Common = require("@ant-design/web3-common");
10
+ var _web3Icons = require("@ant-design/web3-icons");
11
+ var _dappKit = require("@mysten/dapp-kit");
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
+ const AntDesignWeb3ConfigProvider = ({
16
+ balance: showBalance,
17
+ locale,
18
+ availableChains,
19
+ availableWallets,
20
+ currentChain,
21
+ sns,
22
+ onCurrentChainChange,
23
+ children
24
+ }) => {
25
+ const account = (0, _dappKit.useCurrentAccount)();
26
+ const standardWallets = (0, _dappKit.useWallets)();
27
+ const {
28
+ mutateAsync: connectAsync
29
+ } = (0, _dappKit.useConnectWallet)();
30
+ const {
31
+ mutateAsync: disconnectAsync
32
+ } = (0, _dappKit.useDisconnectWallet)();
33
+ const {
34
+ data: snsData
35
+ } = (0, _dappKit.useResolveSuiNSName)(sns ? account?.address : undefined);
36
+ const client = (0, _dappKit.useSuiClient)();
37
+ const {
38
+ data: balanceData
39
+ } = (0, _dappKit.useSuiClientQuery)('getBalance', {
40
+ owner: account?.address ?? ''
41
+ }, {
42
+ select(data) {
43
+ return BigInt(data.totalBalance);
44
+ }
45
+ });
46
+ const accountData = account ? {
47
+ address: account.address,
48
+ name: sns && snsData ? snsData : undefined
49
+ } : undefined;
50
+ const allWallets = (0, _react.useMemo)(() => {
51
+ const standardWalletNames = standardWallets.map(w => w.name);
52
+ const fixedWallets = availableWallets?.map(factory => factory.create())?.filter(w => !standardWalletNames.includes(w.name));
53
+ const injectedWalletAssets = standardWallets.map(w => {
54
+ return {
55
+ name: w.name,
56
+ icon: w.icon,
57
+ remark: w.name,
58
+ _standardWallet: w,
59
+ async hasExtensionInstalled() {
60
+ return true;
61
+ },
62
+ async hasWalletReady() {
63
+ return true;
64
+ }
65
+ };
66
+ });
67
+ return fixedWallets ? fixedWallets.concat(injectedWalletAssets) : injectedWalletAssets;
68
+ }, [availableWallets, standardWallets]);
69
+ const getNFTMetadataFunc = (0, _react.useCallback)(async ({
70
+ address
71
+ }) => {
72
+ const {
73
+ data: nftData
74
+ } = await client.getObject({
75
+ id: address,
76
+ options: {
77
+ showContent: true,
78
+ showDisplay: true
79
+ }
80
+ });
81
+ const displayData = nftData?.display?.data;
82
+ const objectFields = nftData?.content?.dataType === 'moveObject' ? nftData.content.fields : undefined;
83
+ return {
84
+ image: displayData?.image_url,
85
+ date: objectFields?.birthdate,
86
+ attributes: objectFields?.attributes,
87
+ description: displayData?.description,
88
+ edition: nftData?.version
89
+ };
90
+ }, [client]);
91
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Common.Web3ConfigProvider, {
92
+ availableChains: availableChains,
93
+ availableWallets: allWallets,
94
+ locale: locale,
95
+ account: accountData,
96
+ chain: currentChain,
97
+ balance: showBalance ? {
98
+ symbol: _tokens.SUI.symbol,
99
+ decimals: _tokens.SUI.decimal,
100
+ value: balanceData,
101
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.SuiColorful, {})
102
+ } : undefined,
103
+ connect: async wallet => {
104
+ const foundWallet = wallet?._standardWallet;
105
+ if (!foundWallet) {
106
+ throw new Error(`Can not find wallet ${wallet?.name}`);
107
+ }
108
+ await connectAsync({
109
+ wallet: foundWallet
110
+ });
111
+ },
112
+ disconnect: async () => {
113
+ await disconnectAsync();
114
+ },
115
+ switchChain: async chain => {
116
+ const network = availableChains?.find(item => item.id === chain.id)?.network;
117
+ if (network) {
118
+ onCurrentChainChange(network);
119
+ }
120
+ },
121
+ getNFTMetadata: getNFTMetadataFunc,
122
+ children: children
123
+ });
124
+ };
125
+ exports.AntDesignWeb3ConfigProvider = AntDesignWeb3ConfigProvider;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import type { Locale } from '@ant-design/web3-common';
3
+ import { createNetworkConfig } from '@mysten/dapp-kit';
4
+ import { QueryClient } from '@tanstack/react-query';
5
+ import type { WalletFactory } from '../wallets/types';
6
+ export interface SuiWeb3ConfigProviderProps {
7
+ balance?: boolean;
8
+ locale?: Locale;
9
+ autoConnect?: boolean;
10
+ networkConfig?: ReturnType<typeof createNetworkConfig>['networkConfig'];
11
+ sns?: boolean;
12
+ defaultNetwork?: string;
13
+ wallets?: WalletFactory[];
14
+ queryClient?: QueryClient;
15
+ }
16
+ export declare const SuiWeb3ConfigProvider: React.FC<React.PropsWithChildren<SuiWeb3ConfigProviderProps>>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SuiWeb3ConfigProvider = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _dappKit = require("@mysten/dapp-kit");
9
+ var _client = require("@mysten/sui/client");
10
+ var _reactQuery = require("@tanstack/react-query");
11
+ var _chain = require("../chain");
12
+ var _configProvider = require("./config-provider");
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
+ const SuiWeb3ConfigProvider = ({
17
+ autoConnect,
18
+ balance,
19
+ locale,
20
+ networkConfig,
21
+ defaultNetwork = 'mainnet',
22
+ queryClient,
23
+ sns,
24
+ wallets,
25
+ children
26
+ }) => {
27
+ const [network, setNetwork] = _react.default.useState(defaultNetwork);
28
+ const injectedQueryClient = (0, _react.useContext)(_reactQuery.QueryClientContext);
29
+ const mergedQueryClient = _react.default.useMemo(() => {
30
+ return queryClient ?? injectedQueryClient ?? new _reactQuery.QueryClient();
31
+ }, [injectedQueryClient, queryClient]);
32
+ const mergedNetworkConfig = _react.default.useMemo(() => {
33
+ return networkConfig ?? (0, _dappKit.createNetworkConfig)({
34
+ mainnet: {
35
+ url: (0, _client.getFullnodeUrl)('mainnet')
36
+ }
37
+ }).networkConfig;
38
+ }, [networkConfig]);
39
+ const networks = _react.default.useMemo(() => {
40
+ const networkConfigKeys = Object.keys(mergedNetworkConfig);
41
+ const networkConfigs = [_chain.suiMainnet, _chain.suiTestnet, _chain.suiDevnet, _chain.suiLocalnet];
42
+ return networkConfigKeys.map(networkKey => networkConfigs.find(item => item.network === networkKey)).filter(item => !!item);
43
+ }, [mergedNetworkConfig]);
44
+ const currentNetwork = _react.default.useMemo(() => {
45
+ return networks?.find(item => item.network === network);
46
+ }, [network, networks]);
47
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactQuery.QueryClientProvider, {
48
+ client: mergedQueryClient,
49
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_dappKit.SuiClientProvider, {
50
+ networks: mergedNetworkConfig,
51
+ network: network,
52
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_dappKit.WalletProvider, {
53
+ autoConnect: autoConnect,
54
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_configProvider.AntDesignWeb3ConfigProvider, {
55
+ locale: locale,
56
+ availableChains: networks,
57
+ availableWallets: wallets,
58
+ currentChain: currentNetwork,
59
+ balance: balance,
60
+ sns: sns,
61
+ onCurrentChainChange: setNetwork,
62
+ children: children
63
+ })
64
+ })
65
+ })
66
+ });
67
+ };
68
+ exports.SuiWeb3ConfigProvider = SuiWeb3ConfigProvider;
@@ -0,0 +1,2 @@
1
+ export declare const Suiet: () => import("./types").WalletFactory;
2
+ export declare const SuiWallet: () => import("./types").WalletFactory;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Suiet = exports.SuiWallet = void 0;
7
+ var _web3Assets = require("@ant-design/web3-assets");
8
+ var _factory = require("./factory");
9
+ /* v8 ignore start */
10
+
11
+ const Suiet = () => (0, _factory.WalletFactory)(_web3Assets.metadata_Suiet);
12
+ exports.Suiet = Suiet;
13
+ const SuiWallet = () => (0, _factory.WalletFactory)(_web3Assets.metadata_SuiWallet);
14
+ exports.SuiWallet = SuiWallet;
@@ -0,0 +1,2 @@
1
+ import type { WalletFactoryBuilder } from './types';
2
+ export declare const WalletFactory: WalletFactoryBuilder;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WalletFactory = void 0;
7
+ /* v8 ignore start */
8
+
9
+ const WalletFactory = metadata => {
10
+ return {
11
+ create: () => {
12
+ return {
13
+ ...metadata,
14
+ // We simply assume that all wallets implement the `Standard Wallet`,
15
+ // so the wallets provided by `wallets` are not available.
16
+ hasWalletReady: () => Promise.resolve(false),
17
+ hasExtensionInstalled: () => Promise.resolve(false)
18
+ };
19
+ }
20
+ };
21
+ };
22
+ exports.WalletFactory = WalletFactory;
@@ -0,0 +1,5 @@
1
+ import type { Wallet, WalletMetadata } from '@ant-design/web3-common';
2
+ export interface WalletFactory {
3
+ create: () => Wallet;
4
+ }
5
+ export type WalletFactoryBuilder = (metadata: WalletMetadata) => WalletFactory;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@ant-design/web3-sui",
3
+ "version": "1.0.0",
4
+ "main": "dist/lib/index.js",
5
+ "module": "dist/esm/index.js",
6
+ "typings": "dist/esm/index.d.ts",
7
+ "exports": {
8
+ "import": "./dist/esm/index.js",
9
+ "require": "./dist/lib/index.js",
10
+ "types": "./dist/esm/index.d.ts"
11
+ },
12
+ "sideEffects": false,
13
+ "files": [
14
+ "dist",
15
+ "CHANGELOG.md",
16
+ "README.md"
17
+ ],
18
+ "keywords": [
19
+ "ant",
20
+ "component",
21
+ "components",
22
+ "design",
23
+ "framework",
24
+ "frontend",
25
+ "react",
26
+ "react-component",
27
+ "ui",
28
+ "web3",
29
+ "sui"
30
+ ],
31
+ "homepage": "https://web3.ant.design",
32
+ "bugs": {
33
+ "url": "https://github.com/ant-design/ant-design-web3/issues"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/ant-design/ant-design-web3"
38
+ },
39
+ "dependencies": {
40
+ "debug": "^4.3.4",
41
+ "@ant-design/web3-common": "1.13.0",
42
+ "@ant-design/web3-assets": "1.10.2"
43
+ },
44
+ "devDependencies": {
45
+ "@mysten/dapp-kit": "^0.14.11",
46
+ "@mysten/sui": "^1.4.0",
47
+ "@tanstack/react-query": "^5.40.1",
48
+ "@types/debug": "^4.1.12",
49
+ "father": "^4.4.4",
50
+ "typescript": "^5.5.2"
51
+ },
52
+ "peerDependencies": {
53
+ "@mysten/dapp-kit": "^0.14.11",
54
+ "@mysten/sui": "^1.4.0",
55
+ "@tanstack/react-query": "^5.40.1"
56
+ },
57
+ "publishConfig": {
58
+ "registry": "https://registry.npmjs.org",
59
+ "access": "public"
60
+ },
61
+ "browserslist": [
62
+ "last 2 versions",
63
+ "Firefox ESR",
64
+ "> 1%",
65
+ "ie >= 11"
66
+ ],
67
+ "scripts": {
68
+ "dev": "father dev",
69
+ "build": "father build"
70
+ }
71
+ }