@ant-design/web3-tron 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.
Files changed (44) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/LICENSE +21 -0
  3. package/README.md +39 -0
  4. package/dist/esm/index.d.ts +4 -0
  5. package/dist/esm/index.js +4 -0
  6. package/dist/esm/provider/config-provider.d.ts +10 -0
  7. package/dist/esm/provider/config-provider.js +121 -0
  8. package/dist/esm/provider/index.d.ts +10 -0
  9. package/dist/esm/provider/index.js +38 -0
  10. package/dist/esm/utils.d.ts +2 -0
  11. package/dist/esm/utils.js +3 -0
  12. package/dist/esm/wallets/bitgetWallet.d.ts +2 -0
  13. package/dist/esm/wallets/bitgetWallet.js +21 -0
  14. package/dist/esm/wallets/bybitWallet.d.ts +2 -0
  15. package/dist/esm/wallets/bybitWallet.js +21 -0
  16. package/dist/esm/wallets/index.d.ts +3 -0
  17. package/dist/esm/wallets/index.js +6 -0
  18. package/dist/esm/wallets/okxTronWallet.d.ts +2 -0
  19. package/dist/esm/wallets/okxTronWallet.js +7 -0
  20. package/dist/esm/wallets/tronlinkWallet.d.ts +2 -0
  21. package/dist/esm/wallets/tronlinkWallet.js +21 -0
  22. package/dist/esm/wallets/types.d.ts +13 -0
  23. package/dist/esm/wallets/types.js +1 -0
  24. package/dist/lib/index.d.ts +4 -0
  25. package/dist/lib/index.js +51 -0
  26. package/dist/lib/provider/config-provider.d.ts +10 -0
  27. package/dist/lib/provider/config-provider.js +130 -0
  28. package/dist/lib/provider/index.d.ts +10 -0
  29. package/dist/lib/provider/index.js +47 -0
  30. package/dist/lib/utils.d.ts +2 -0
  31. package/dist/lib/utils.js +11 -0
  32. package/dist/lib/wallets/bitgetWallet.d.ts +2 -0
  33. package/dist/lib/wallets/bitgetWallet.js +27 -0
  34. package/dist/lib/wallets/bybitWallet.d.ts +2 -0
  35. package/dist/lib/wallets/bybitWallet.js +27 -0
  36. package/dist/lib/wallets/index.d.ts +3 -0
  37. package/dist/lib/wallets/index.js +38 -0
  38. package/dist/lib/wallets/okxTronWallet.d.ts +2 -0
  39. package/dist/lib/wallets/okxTronWallet.js +14 -0
  40. package/dist/lib/wallets/tronlinkWallet.d.ts +2 -0
  41. package/dist/lib/wallets/tronlinkWallet.js +27 -0
  42. package/dist/lib/wallets/types.d.ts +13 -0
  43. package/dist/lib/wallets/types.js +5 -0
  44. package/package.json +69 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @ant-design/web3-tron
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 1f08bd4: feat: Add support for Tron
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [0f83657]
12
+ - @ant-design/web3-common@1.19.0
13
+ - @ant-design/web3-assets@1.12.1
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,39 @@
1
+ # @ant-design/web3-tron
2
+
3
+ This package provides a [TRON](https://tron.network) adapter for [@ant-design/web3](https://www.npmjs.com/package/@ant-design/web3).
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ npm install @ant-design/web3 @ant-design/web3-tron --save
9
+ ```
10
+
11
+ ```tsx
12
+ import { ConnectButton, Connector } from '@ant-design/web3';
13
+ import {
14
+ BitgetWallet,
15
+ BybitWallet,
16
+ OkxTronWallet,
17
+ TronlinkWallet,
18
+ TronWeb3ConfigProvider,
19
+ } from '@ant-design/web3-tron';
20
+
21
+ const Basic = () => {
22
+ return (
23
+ <TronWeb3ConfigProvider wallets={[TronlinkWallet, OkxTronWallet, BitgetWallet, BybitWallet]}>
24
+ <Connector>
25
+ <ConnectButton />
26
+ </Connector>
27
+ </TronWeb3ConfigProvider>
28
+ );
29
+ };
30
+
31
+ export default Basic;
32
+ ```
33
+
34
+ For more examples, refer to [TRON - Ant Design Web3](https://web3.ant.design/components/tron).
35
+
36
+ ## Documentation
37
+
38
+ - For more information, visit [Ant Design Web3](https://web3.ant.design).
39
+ - For an introduction to TRON, visit [TRON](https://tron.network).
@@ -0,0 +1,4 @@
1
+ export * from './provider';
2
+ export * from './wallets/types';
3
+ export * from './wallets';
4
+ export { useWallet } from '@tronweb3/tronwallet-adapter-react-hooks';
@@ -0,0 +1,4 @@
1
+ export * from "./provider";
2
+ export * from "./wallets/types";
3
+ export * from "./wallets";
4
+ export { useWallet } from '@tronweb3/tronwallet-adapter-react-hooks';
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import type { Locale, Wallet } from '@ant-design/web3-common';
3
+ import { type WalletError } from '@tronweb3/tronwallet-abstract-adapter';
4
+ interface AntDesignWeb3ConfigProviderProps {
5
+ availableWallets?: Wallet[];
6
+ locale?: Locale;
7
+ connectionError?: WalletError;
8
+ }
9
+ export declare const AntDesignWeb3ConfigProvider: React.FC<React.PropsWithChildren<AntDesignWeb3ConfigProviderProps>>;
10
+ export {};
@@ -0,0 +1,121 @@
1
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
2
+ import { Web3ConfigProvider } from '@ant-design/web3-common';
3
+ import { WalletReadyState } from '@tronweb3/tronwallet-abstract-adapter';
4
+ import { useWallet } from '@tronweb3/tronwallet-adapter-react-hooks';
5
+ import { hasWalletReady } from "../utils";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ export const AntDesignWeb3ConfigProvider = ({
8
+ availableWallets,
9
+ locale,
10
+ connectionError,
11
+ children
12
+ }) => {
13
+ const {
14
+ address,
15
+ wallet,
16
+ wallets,
17
+ connected,
18
+ connect,
19
+ disconnect,
20
+ select
21
+ } = useWallet();
22
+ const connectAsyncRef = useRef();
23
+ const [account, setAccount] = useState();
24
+ useEffect(() => {
25
+ if (address) {
26
+ setAccount({
27
+ address
28
+ });
29
+ }
30
+ }, [address]);
31
+ const allWallets = useMemo(() => {
32
+ const providedWallets = availableWallets?.map(w => {
33
+ const adapter = wallets?.find(item => item.adapter.name === w.name)?.adapter;
34
+ return {
35
+ ...w,
36
+ adapter,
37
+ hasExtensionInstalled: async () => {
38
+ return adapter?.readyState === WalletReadyState.Found;
39
+ },
40
+ hasWalletReady: async () => {
41
+ return adapter?.readyState === WalletReadyState.Found || adapter?.readyState === WalletReadyState.Loading;
42
+ }
43
+ };
44
+ });
45
+ return providedWallets || [];
46
+ }, [availableWallets, wallets]);
47
+ useEffect(() => {
48
+ if (connectionError) {
49
+ connectAsyncRef.current?.reject(connectionError);
50
+ connectAsyncRef.current = undefined;
51
+ }
52
+ }, [connectionError]);
53
+
54
+ // get account address
55
+ useEffect(() => {
56
+ if (!(address && connected)) {
57
+ setAccount(undefined);
58
+ return;
59
+ }
60
+ setAccount({
61
+ address: address
62
+ });
63
+ }, [address, connected, wallet?.adapter?.name]);
64
+ useEffect(() => {
65
+ if (!connectAsyncRef.current) {
66
+ return;
67
+ }
68
+ if (connected) {
69
+ connectAsyncRef.current.resolve({
70
+ address: address
71
+ });
72
+ connectAsyncRef.current = undefined;
73
+ }
74
+ }, [connected]);
75
+
76
+ // connect/disconnect wallet
77
+ useEffect(() => {
78
+ if (wallet?.adapter?.name) {
79
+ // if wallet is not ready, need clear selected wallet
80
+ if (!hasWalletReady(wallet.adapter.readyState)) {
81
+ select(null);
82
+ return;
83
+ }
84
+ connect();
85
+ } else {
86
+ if (connected) {
87
+ disconnect();
88
+ }
89
+ }
90
+ }, [wallet?.adapter?.name, connected]);
91
+ return /*#__PURE__*/_jsx(Web3ConfigProvider, {
92
+ account: account,
93
+ addressPrefix: "",
94
+ availableWallets: allWallets,
95
+ locale: locale,
96
+ connect: async _wallet => {
97
+ let resolve;
98
+ let reject;
99
+ const promise = new Promise((res, rej) => {
100
+ resolve = res;
101
+ reject = rej;
102
+ });
103
+ connectAsyncRef.current = {
104
+ promise,
105
+ resolve,
106
+ reject
107
+ };
108
+ const walletName = _wallet?.name ?? null;
109
+ select(walletName);
110
+ return promise;
111
+ },
112
+ disconnect: async () => {
113
+ try {
114
+ await disconnect();
115
+ } catch (error) {
116
+ console.error(error);
117
+ }
118
+ },
119
+ children: children
120
+ });
121
+ };
@@ -0,0 +1,10 @@
1
+ import React, { type PropsWithChildren } from 'react';
2
+ import type { Locale, Wallet } from '@ant-design/web3-common';
3
+ export interface TronWeb3ConfigProviderProps {
4
+ wallets?: Wallet[];
5
+ onError?: (error: Error) => void;
6
+ autoConnect?: boolean;
7
+ locale?: Locale;
8
+ walletProviderProps?: Omit<React.PropsWithChildren<TronWeb3ConfigProviderProps>, 'children'>;
9
+ }
10
+ export declare const TronWeb3ConfigProvider: React.FC<PropsWithChildren<TronWeb3ConfigProviderProps>>;
@@ -0,0 +1,38 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import { BybitWalletAdapter } from '@tronweb3/tronwallet-adapter-bybit';
3
+ import { OkxWalletAdapter } from '@tronweb3/tronwallet-adapter-okxwallet';
4
+ import { WalletProvider } from '@tronweb3/tronwallet-adapter-react-hooks';
5
+ import { TronLinkAdapter } from '@tronweb3/tronwallet-adapter-tronlink';
6
+ import { AntDesignWeb3ConfigProvider } from "./config-provider";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ export const TronWeb3ConfigProvider = ({
9
+ wallets,
10
+ onError,
11
+ locale,
12
+ autoConnect,
13
+ children,
14
+ walletProviderProps
15
+ }) => {
16
+ const [connectionError, setConnectionError] = useState();
17
+ const adapters = useMemo(() => {
18
+ const tronLinkAdapter = new TronLinkAdapter();
19
+ const okxWalletAdapter = new OkxWalletAdapter();
20
+ const bybitWalletAdapter = new BybitWalletAdapter();
21
+ return [okxWalletAdapter, tronLinkAdapter, bybitWalletAdapter];
22
+ }, []);
23
+ return /*#__PURE__*/_jsx(WalletProvider, {
24
+ onError: error => {
25
+ setConnectionError(error);
26
+ onError?.(error);
27
+ },
28
+ adapters: adapters,
29
+ autoConnect: autoConnect,
30
+ ...walletProviderProps,
31
+ children: /*#__PURE__*/_jsx(AntDesignWeb3ConfigProvider, {
32
+ locale: locale,
33
+ connectionError: connectionError,
34
+ availableWallets: wallets,
35
+ children: children
36
+ })
37
+ });
38
+ };
@@ -0,0 +1,2 @@
1
+ import { WalletReadyState } from '@tronweb3/tronwallet-abstract-adapter';
2
+ export declare const hasWalletReady: (readyState?: WalletReadyState) => boolean;
@@ -0,0 +1,3 @@
1
+ /* v8 ignore start */
2
+ import { WalletReadyState } from '@tronweb3/tronwallet-abstract-adapter';
3
+ export const hasWalletReady = readyState => readyState === WalletReadyState.Found || readyState === WalletReadyState.Loading;
@@ -0,0 +1,2 @@
1
+ import type { WalletMetadata } from '@ant-design/web3-common';
2
+ export declare const BitgetWallet: WalletMetadata;
@@ -0,0 +1,21 @@
1
+ /* v8 ignore start */
2
+
3
+ import { BitgetWalletColorful, ChromeCircleColorful } from '@ant-design/web3-icons';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ export const BitgetWallet = {
6
+ icon: /*#__PURE__*/_jsx(BitgetWalletColorful, {}),
7
+ name: 'Bitget',
8
+ remark: 'Bitget',
9
+ app: {
10
+ link: 'https://web3.bitget.com/wallet-download'
11
+ },
12
+ extensions: [{
13
+ key: 'Chrome',
14
+ browserIcon: /*#__PURE__*/_jsx(ChromeCircleColorful, {}),
15
+ browserName: 'Chrome',
16
+ link: 'https://chromewebstore.google.com/detail/bitget-wallet-crypto-web3/jiidiaalihmmhddjgbnbgdfflelocpak',
17
+ description: "Bitget Wallet, formerly known as BitKeep, is one of the world's largest non-custodial multi-chain crypto wallets."
18
+ }],
19
+ key: 'BitgetWallet',
20
+ group: 'Popular'
21
+ };
@@ -0,0 +1,2 @@
1
+ import type { WalletMetadata } from '@ant-design/web3-common';
2
+ export declare const BybitWallet: WalletMetadata;
@@ -0,0 +1,21 @@
1
+ /* v8 ignore start */
2
+
3
+ import { BybitWalletCircleColorful, ChromeCircleColorful } from '@ant-design/web3-icons';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ export const BybitWallet = {
6
+ icon: /*#__PURE__*/_jsx(BybitWalletCircleColorful, {}),
7
+ name: 'Bybit',
8
+ remark: 'Bybit',
9
+ app: {
10
+ link: 'https://www.bybit.com/download/'
11
+ },
12
+ extensions: [{
13
+ key: 'Chrome',
14
+ browserIcon: /*#__PURE__*/_jsx(ChromeCircleColorful, {}),
15
+ browserName: 'Chrome',
16
+ link: 'https://chromewebstore.google.com/detail/bybit-wallet/pdliaogehgdbhbnmkklieghmmjkpigpa',
17
+ description: 'Bybit Wallet connects you to the world of Web3 with best-in-class reliability and security.'
18
+ }],
19
+ key: 'BybitWallet',
20
+ group: 'Popular'
21
+ };
@@ -0,0 +1,3 @@
1
+ export * from './okxTronWallet';
2
+ export * from './bybitWallet';
3
+ export * from './tronlinkWallet';
@@ -0,0 +1,6 @@
1
+ // TODO: Enable after fixing build issues
2
+ // export * from './bitgetWallet';
3
+
4
+ export * from "./okxTronWallet";
5
+ export * from "./bybitWallet";
6
+ export * from "./tronlinkWallet";
@@ -0,0 +1,2 @@
1
+ import type { WalletMetadata } from '@ant-design/web3-common';
2
+ export declare const OkxTronWallet: WalletMetadata;
@@ -0,0 +1,7 @@
1
+ /* v8 ignore start */
2
+ import { metadata_OkxWallet } from '@ant-design/web3-assets';
3
+ export const OkxTronWallet = {
4
+ ...metadata_OkxWallet,
5
+ key: 'okxTronWallet',
6
+ group: 'Popular'
7
+ };
@@ -0,0 +1,2 @@
1
+ import type { WalletMetadata } from '@ant-design/web3-common';
2
+ export declare const TronlinkWallet: WalletMetadata;
@@ -0,0 +1,21 @@
1
+ /* v8 ignore start */
2
+
3
+ import { ChromeCircleColorful, TronlinkColorful } from '@ant-design/web3-icons';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ export const TronlinkWallet = {
6
+ icon: /*#__PURE__*/_jsx(TronlinkColorful, {}),
7
+ name: 'TronLink',
8
+ remark: 'TronLink',
9
+ app: {
10
+ link: 'https://www.tronlink.org/dlDetails/'
11
+ },
12
+ extensions: [{
13
+ key: 'Chrome',
14
+ browserIcon: /*#__PURE__*/_jsx(ChromeCircleColorful, {}),
15
+ browserName: 'Chrome',
16
+ link: 'https://chromewebstore.google.com/detail/tronlink/ibnejdfjmmkpcnlpebklmnkoeoihofec',
17
+ description: 'The first and most popular TRON wallet. Recommended by TRON Foundation.'
18
+ }],
19
+ key: 'tronWallet',
20
+ group: 'Popular'
21
+ };
@@ -0,0 +1,13 @@
1
+ import type { Wallet, WalletMetadata } from '@ant-design/web3-common';
2
+ import type { Adapter } from '@tronweb3/tronwallet-abstract-adapter';
3
+ export interface StandardWallet extends Wallet {
4
+ isStandardWallet: boolean;
5
+ }
6
+ export interface StandardWalletFactory {
7
+ create: () => StandardWallet;
8
+ }
9
+ export interface AdapterWalletFactory {
10
+ adapter: Adapter;
11
+ }
12
+ export type WalletFactoryBuilder = (adapter: Adapter, walletMetadata: WalletMetadata) => AdapterWalletFactory;
13
+ export type StandardWalletFactoryBuilder = (walletMetadata: WalletMetadata) => StandardWalletFactory;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export * from './provider';
2
+ export * from './wallets/types';
3
+ export * from './wallets';
4
+ export { useWallet } from '@tronweb3/tronwallet-adapter-react-hooks';
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ useWallet: true
8
+ };
9
+ Object.defineProperty(exports, "useWallet", {
10
+ enumerable: true,
11
+ get: function () {
12
+ return _tronwalletAdapterReactHooks.useWallet;
13
+ }
14
+ });
15
+ var _provider = require("./provider");
16
+ Object.keys(_provider).forEach(function (key) {
17
+ if (key === "default" || key === "__esModule") return;
18
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
19
+ if (key in exports && exports[key] === _provider[key]) return;
20
+ Object.defineProperty(exports, key, {
21
+ enumerable: true,
22
+ get: function () {
23
+ return _provider[key];
24
+ }
25
+ });
26
+ });
27
+ var _types = require("./wallets/types");
28
+ Object.keys(_types).forEach(function (key) {
29
+ if (key === "default" || key === "__esModule") return;
30
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
31
+ if (key in exports && exports[key] === _types[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _types[key];
36
+ }
37
+ });
38
+ });
39
+ var _wallets = require("./wallets");
40
+ Object.keys(_wallets).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
43
+ if (key in exports && exports[key] === _wallets[key]) return;
44
+ Object.defineProperty(exports, key, {
45
+ enumerable: true,
46
+ get: function () {
47
+ return _wallets[key];
48
+ }
49
+ });
50
+ });
51
+ var _tronwalletAdapterReactHooks = require("@tronweb3/tronwallet-adapter-react-hooks");
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import type { Locale, Wallet } from '@ant-design/web3-common';
3
+ import { type WalletError } from '@tronweb3/tronwallet-abstract-adapter';
4
+ interface AntDesignWeb3ConfigProviderProps {
5
+ availableWallets?: Wallet[];
6
+ locale?: Locale;
7
+ connectionError?: WalletError;
8
+ }
9
+ export declare const AntDesignWeb3ConfigProvider: React.FC<React.PropsWithChildren<AntDesignWeb3ConfigProviderProps>>;
10
+ export {};
@@ -0,0 +1,130 @@
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 _web3Common = require("@ant-design/web3-common");
9
+ var _tronwalletAbstractAdapter = require("@tronweb3/tronwallet-abstract-adapter");
10
+ var _tronwalletAdapterReactHooks = require("@tronweb3/tronwallet-adapter-react-hooks");
11
+ var _utils = require("../utils");
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
+ availableWallets,
17
+ locale,
18
+ connectionError,
19
+ children
20
+ }) => {
21
+ const {
22
+ address,
23
+ wallet,
24
+ wallets,
25
+ connected,
26
+ connect,
27
+ disconnect,
28
+ select
29
+ } = (0, _tronwalletAdapterReactHooks.useWallet)();
30
+ const connectAsyncRef = (0, _react.useRef)();
31
+ const [account, setAccount] = (0, _react.useState)();
32
+ (0, _react.useEffect)(() => {
33
+ if (address) {
34
+ setAccount({
35
+ address
36
+ });
37
+ }
38
+ }, [address]);
39
+ const allWallets = (0, _react.useMemo)(() => {
40
+ const providedWallets = availableWallets?.map(w => {
41
+ const adapter = wallets?.find(item => item.adapter.name === w.name)?.adapter;
42
+ return {
43
+ ...w,
44
+ adapter,
45
+ hasExtensionInstalled: async () => {
46
+ return adapter?.readyState === _tronwalletAbstractAdapter.WalletReadyState.Found;
47
+ },
48
+ hasWalletReady: async () => {
49
+ return adapter?.readyState === _tronwalletAbstractAdapter.WalletReadyState.Found || adapter?.readyState === _tronwalletAbstractAdapter.WalletReadyState.Loading;
50
+ }
51
+ };
52
+ });
53
+ return providedWallets || [];
54
+ }, [availableWallets, wallets]);
55
+ (0, _react.useEffect)(() => {
56
+ if (connectionError) {
57
+ connectAsyncRef.current?.reject(connectionError);
58
+ connectAsyncRef.current = undefined;
59
+ }
60
+ }, [connectionError]);
61
+
62
+ // get account address
63
+ (0, _react.useEffect)(() => {
64
+ if (!(address && connected)) {
65
+ setAccount(undefined);
66
+ return;
67
+ }
68
+ setAccount({
69
+ address: address
70
+ });
71
+ }, [address, connected, wallet?.adapter?.name]);
72
+ (0, _react.useEffect)(() => {
73
+ if (!connectAsyncRef.current) {
74
+ return;
75
+ }
76
+ if (connected) {
77
+ connectAsyncRef.current.resolve({
78
+ address: address
79
+ });
80
+ connectAsyncRef.current = undefined;
81
+ }
82
+ }, [connected]);
83
+
84
+ // connect/disconnect wallet
85
+ (0, _react.useEffect)(() => {
86
+ if (wallet?.adapter?.name) {
87
+ // if wallet is not ready, need clear selected wallet
88
+ if (!(0, _utils.hasWalletReady)(wallet.adapter.readyState)) {
89
+ select(null);
90
+ return;
91
+ }
92
+ connect();
93
+ } else {
94
+ if (connected) {
95
+ disconnect();
96
+ }
97
+ }
98
+ }, [wallet?.adapter?.name, connected]);
99
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Common.Web3ConfigProvider, {
100
+ account: account,
101
+ addressPrefix: "",
102
+ availableWallets: allWallets,
103
+ locale: locale,
104
+ connect: async _wallet => {
105
+ let resolve;
106
+ let reject;
107
+ const promise = new Promise((res, rej) => {
108
+ resolve = res;
109
+ reject = rej;
110
+ });
111
+ connectAsyncRef.current = {
112
+ promise,
113
+ resolve,
114
+ reject
115
+ };
116
+ const walletName = _wallet?.name ?? null;
117
+ select(walletName);
118
+ return promise;
119
+ },
120
+ disconnect: async () => {
121
+ try {
122
+ await disconnect();
123
+ } catch (error) {
124
+ console.error(error);
125
+ }
126
+ },
127
+ children: children
128
+ });
129
+ };
130
+ exports.AntDesignWeb3ConfigProvider = AntDesignWeb3ConfigProvider;
@@ -0,0 +1,10 @@
1
+ import React, { type PropsWithChildren } from 'react';
2
+ import type { Locale, Wallet } from '@ant-design/web3-common';
3
+ export interface TronWeb3ConfigProviderProps {
4
+ wallets?: Wallet[];
5
+ onError?: (error: Error) => void;
6
+ autoConnect?: boolean;
7
+ locale?: Locale;
8
+ walletProviderProps?: Omit<React.PropsWithChildren<TronWeb3ConfigProviderProps>, 'children'>;
9
+ }
10
+ export declare const TronWeb3ConfigProvider: React.FC<PropsWithChildren<TronWeb3ConfigProviderProps>>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TronWeb3ConfigProvider = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _tronwalletAdapterBybit = require("@tronweb3/tronwallet-adapter-bybit");
9
+ var _tronwalletAdapterOkxwallet = require("@tronweb3/tronwallet-adapter-okxwallet");
10
+ var _tronwalletAdapterReactHooks = require("@tronweb3/tronwallet-adapter-react-hooks");
11
+ var _tronwalletAdapterTronlink = require("@tronweb3/tronwallet-adapter-tronlink");
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 TronWeb3ConfigProvider = ({
17
+ wallets,
18
+ onError,
19
+ locale,
20
+ autoConnect,
21
+ children,
22
+ walletProviderProps
23
+ }) => {
24
+ const [connectionError, setConnectionError] = (0, _react.useState)();
25
+ const adapters = (0, _react.useMemo)(() => {
26
+ const tronLinkAdapter = new _tronwalletAdapterTronlink.TronLinkAdapter();
27
+ const okxWalletAdapter = new _tronwalletAdapterOkxwallet.OkxWalletAdapter();
28
+ const bybitWalletAdapter = new _tronwalletAdapterBybit.BybitWalletAdapter();
29
+ return [okxWalletAdapter, tronLinkAdapter, bybitWalletAdapter];
30
+ }, []);
31
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_tronwalletAdapterReactHooks.WalletProvider, {
32
+ onError: error => {
33
+ setConnectionError(error);
34
+ onError?.(error);
35
+ },
36
+ adapters: adapters,
37
+ autoConnect: autoConnect,
38
+ ...walletProviderProps,
39
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_configProvider.AntDesignWeb3ConfigProvider, {
40
+ locale: locale,
41
+ connectionError: connectionError,
42
+ availableWallets: wallets,
43
+ children: children
44
+ })
45
+ });
46
+ };
47
+ exports.TronWeb3ConfigProvider = TronWeb3ConfigProvider;
@@ -0,0 +1,2 @@
1
+ import { WalletReadyState } from '@tronweb3/tronwallet-abstract-adapter';
2
+ export declare const hasWalletReady: (readyState?: WalletReadyState) => boolean;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hasWalletReady = void 0;
7
+ var _tronwalletAbstractAdapter = require("@tronweb3/tronwallet-abstract-adapter");
8
+ /* v8 ignore start */
9
+
10
+ const hasWalletReady = readyState => readyState === _tronwalletAbstractAdapter.WalletReadyState.Found || readyState === _tronwalletAbstractAdapter.WalletReadyState.Loading;
11
+ exports.hasWalletReady = hasWalletReady;
@@ -0,0 +1,2 @@
1
+ import type { WalletMetadata } from '@ant-design/web3-common';
2
+ export declare const BitgetWallet: WalletMetadata;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BitgetWallet = void 0;
7
+ var _web3Icons = require("@ant-design/web3-icons");
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ /* v8 ignore start */
10
+
11
+ const BitgetWallet = exports.BitgetWallet = {
12
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.BitgetWalletColorful, {}),
13
+ name: 'Bitget',
14
+ remark: 'Bitget',
15
+ app: {
16
+ link: 'https://web3.bitget.com/wallet-download'
17
+ },
18
+ extensions: [{
19
+ key: 'Chrome',
20
+ browserIcon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.ChromeCircleColorful, {}),
21
+ browserName: 'Chrome',
22
+ link: 'https://chromewebstore.google.com/detail/bitget-wallet-crypto-web3/jiidiaalihmmhddjgbnbgdfflelocpak',
23
+ description: "Bitget Wallet, formerly known as BitKeep, is one of the world's largest non-custodial multi-chain crypto wallets."
24
+ }],
25
+ key: 'BitgetWallet',
26
+ group: 'Popular'
27
+ };
@@ -0,0 +1,2 @@
1
+ import type { WalletMetadata } from '@ant-design/web3-common';
2
+ export declare const BybitWallet: WalletMetadata;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BybitWallet = void 0;
7
+ var _web3Icons = require("@ant-design/web3-icons");
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ /* v8 ignore start */
10
+
11
+ const BybitWallet = exports.BybitWallet = {
12
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.BybitWalletCircleColorful, {}),
13
+ name: 'Bybit',
14
+ remark: 'Bybit',
15
+ app: {
16
+ link: 'https://www.bybit.com/download/'
17
+ },
18
+ extensions: [{
19
+ key: 'Chrome',
20
+ browserIcon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.ChromeCircleColorful, {}),
21
+ browserName: 'Chrome',
22
+ link: 'https://chromewebstore.google.com/detail/bybit-wallet/pdliaogehgdbhbnmkklieghmmjkpigpa',
23
+ description: 'Bybit Wallet connects you to the world of Web3 with best-in-class reliability and security.'
24
+ }],
25
+ key: 'BybitWallet',
26
+ group: 'Popular'
27
+ };
@@ -0,0 +1,3 @@
1
+ export * from './okxTronWallet';
2
+ export * from './bybitWallet';
3
+ export * from './tronlinkWallet';
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _okxTronWallet = require("./okxTronWallet");
7
+ Object.keys(_okxTronWallet).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _okxTronWallet[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _okxTronWallet[key];
14
+ }
15
+ });
16
+ });
17
+ var _bybitWallet = require("./bybitWallet");
18
+ Object.keys(_bybitWallet).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _bybitWallet[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _bybitWallet[key];
25
+ }
26
+ });
27
+ });
28
+ var _tronlinkWallet = require("./tronlinkWallet");
29
+ Object.keys(_tronlinkWallet).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _tronlinkWallet[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _tronlinkWallet[key];
36
+ }
37
+ });
38
+ });
@@ -0,0 +1,2 @@
1
+ import type { WalletMetadata } from '@ant-design/web3-common';
2
+ export declare const OkxTronWallet: WalletMetadata;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.OkxTronWallet = void 0;
7
+ var _web3Assets = require("@ant-design/web3-assets");
8
+ /* v8 ignore start */
9
+
10
+ const OkxTronWallet = exports.OkxTronWallet = {
11
+ ..._web3Assets.metadata_OkxWallet,
12
+ key: 'okxTronWallet',
13
+ group: 'Popular'
14
+ };
@@ -0,0 +1,2 @@
1
+ import type { WalletMetadata } from '@ant-design/web3-common';
2
+ export declare const TronlinkWallet: WalletMetadata;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TronlinkWallet = void 0;
7
+ var _web3Icons = require("@ant-design/web3-icons");
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ /* v8 ignore start */
10
+
11
+ const TronlinkWallet = exports.TronlinkWallet = {
12
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.TronlinkColorful, {}),
13
+ name: 'TronLink',
14
+ remark: 'TronLink',
15
+ app: {
16
+ link: 'https://www.tronlink.org/dlDetails/'
17
+ },
18
+ extensions: [{
19
+ key: 'Chrome',
20
+ browserIcon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Icons.ChromeCircleColorful, {}),
21
+ browserName: 'Chrome',
22
+ link: 'https://chromewebstore.google.com/detail/tronlink/ibnejdfjmmkpcnlpebklmnkoeoihofec',
23
+ description: 'The first and most popular TRON wallet. Recommended by TRON Foundation.'
24
+ }],
25
+ key: 'tronWallet',
26
+ group: 'Popular'
27
+ };
@@ -0,0 +1,13 @@
1
+ import type { Wallet, WalletMetadata } from '@ant-design/web3-common';
2
+ import type { Adapter } from '@tronweb3/tronwallet-abstract-adapter';
3
+ export interface StandardWallet extends Wallet {
4
+ isStandardWallet: boolean;
5
+ }
6
+ export interface StandardWalletFactory {
7
+ create: () => StandardWallet;
8
+ }
9
+ export interface AdapterWalletFactory {
10
+ adapter: Adapter;
11
+ }
12
+ export type WalletFactoryBuilder = (adapter: Adapter, walletMetadata: WalletMetadata) => AdapterWalletFactory;
13
+ export type StandardWalletFactoryBuilder = (walletMetadata: WalletMetadata) => StandardWalletFactory;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@ant-design/web3-tron",
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
+ "tron"
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
+ "@tronweb3/tronwallet-abstract-adapter": "^1.1.9",
41
+ "@tronweb3/tronwallet-adapter-react-hooks": "^1.1.10",
42
+ "@tronweb3/tronwallet-adapter-walletconnect": "^2.0.3",
43
+ "@tronweb3/tronwallet-adapter-tronlink": "^1.1.12",
44
+ "@tronweb3/tronwallet-adapter-okxwallet": "^1.0.6",
45
+ "@tronweb3/tronwallet-adapter-bybit": "^1.0.1",
46
+ "tronweb": "^6.0.1",
47
+ "@ant-design/web3-assets": "1.12.1",
48
+ "@ant-design/web3-common": "1.19.0"
49
+ },
50
+ "devDependencies": {
51
+ "@types/debug": "^4.1.12",
52
+ "father": "^4.4.4",
53
+ "typescript": "^5.6.2"
54
+ },
55
+ "publishConfig": {
56
+ "registry": "https://registry.npmjs.org",
57
+ "access": "public"
58
+ },
59
+ "browserslist": [
60
+ "last 2 versions",
61
+ "Firefox ESR",
62
+ "> 1%",
63
+ "ie >= 11"
64
+ ],
65
+ "scripts": {
66
+ "dev": "father dev",
67
+ "build": "father build"
68
+ }
69
+ }