@ant-design/web3-ton 0.0.0-alpha-20260209094036
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 +174 -0
- package/LICENSE +21 -0
- package/README.md +33 -0
- package/dist/esm/chains/index.d.ts +1 -0
- package/dist/esm/chains/index.js +1 -0
- package/dist/esm/hooks/index.d.ts +1 -0
- package/dist/esm/hooks/index.js +1 -0
- package/dist/esm/hooks/useTonConnector.d.ts +7 -0
- package/dist/esm/hooks/useTonConnector.js +12 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/ton-provider/TonConnectSdk.d.ts +15 -0
- package/dist/esm/ton-provider/TonConnectSdk.js +48 -0
- package/dist/esm/ton-provider/TonWeb3ConfigProvider.d.ts +27 -0
- package/dist/esm/ton-provider/TonWeb3ConfigProvider.js +66 -0
- package/dist/esm/ton-provider/config-provider.d.ts +14 -0
- package/dist/esm/ton-provider/config-provider.js +63 -0
- package/dist/esm/ton-provider/index.d.ts +1 -0
- package/dist/esm/ton-provider/index.js +1 -0
- package/dist/esm/wallets/dewallet.d.ts +2 -0
- package/dist/esm/wallets/dewallet.js +6 -0
- package/dist/esm/wallets/factory.d.ts +2 -0
- package/dist/esm/wallets/factory.js +17 -0
- package/dist/esm/wallets/index.d.ts +7 -0
- package/dist/esm/wallets/index.js +7 -0
- package/dist/esm/wallets/myTonWallet.d.ts +2 -0
- package/dist/esm/wallets/myTonWallet.js +13 -0
- package/dist/esm/wallets/okxTonWallet.d.ts +2 -0
- package/dist/esm/wallets/okxTonWallet.js +15 -0
- package/dist/esm/wallets/openmask.d.ts +2 -0
- package/dist/esm/wallets/openmask.js +13 -0
- package/dist/esm/wallets/telegramWallet.d.ts +2 -0
- package/dist/esm/wallets/telegramWallet.js +6 -0
- package/dist/esm/wallets/tonhub.d.ts +2 -0
- package/dist/esm/wallets/tonhub.js +6 -0
- package/dist/esm/wallets/tonkeeper.d.ts +2 -0
- package/dist/esm/wallets/tonkeeper.js +14 -0
- package/dist/esm/wallets/type.d.ts +10 -0
- package/dist/esm/wallets/type.js +1 -0
- package/dist/lib/chains/index.d.ts +1 -0
- package/dist/lib/chains/index.js +12 -0
- package/dist/lib/hooks/index.d.ts +1 -0
- package/dist/lib/hooks/index.js +16 -0
- package/dist/lib/hooks/useTonConnector.d.ts +7 -0
- package/dist/lib/hooks/useTonConnector.js +20 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.js +49 -0
- package/dist/lib/ton-provider/TonConnectSdk.d.ts +15 -0
- package/dist/lib/ton-provider/TonConnectSdk.js +56 -0
- package/dist/lib/ton-provider/TonWeb3ConfigProvider.d.ts +27 -0
- package/dist/lib/ton-provider/TonWeb3ConfigProvider.js +76 -0
- package/dist/lib/ton-provider/config-provider.d.ts +14 -0
- package/dist/lib/ton-provider/config-provider.js +71 -0
- package/dist/lib/ton-provider/index.d.ts +1 -0
- package/dist/lib/ton-provider/index.js +16 -0
- package/dist/lib/wallets/dewallet.d.ts +2 -0
- package/dist/lib/wallets/dewallet.js +12 -0
- package/dist/lib/wallets/factory.d.ts +2 -0
- package/dist/lib/wallets/factory.js +24 -0
- package/dist/lib/wallets/index.d.ts +7 -0
- package/dist/lib/wallets/index.js +82 -0
- package/dist/lib/wallets/myTonWallet.d.ts +2 -0
- package/dist/lib/wallets/myTonWallet.js +19 -0
- package/dist/lib/wallets/okxTonWallet.d.ts +2 -0
- package/dist/lib/wallets/okxTonWallet.js +21 -0
- package/dist/lib/wallets/openmask.d.ts +2 -0
- package/dist/lib/wallets/openmask.js +19 -0
- package/dist/lib/wallets/telegramWallet.d.ts +2 -0
- package/dist/lib/wallets/telegramWallet.js +12 -0
- package/dist/lib/wallets/tonhub.d.ts +2 -0
- package/dist/lib/wallets/tonhub.js +12 -0
- package/dist/lib/wallets/tonkeeper.d.ts +2 -0
- package/dist/lib/wallets/tonkeeper.js +20 -0
- package/dist/lib/wallets/type.d.ts +10 -0
- package/dist/lib/wallets/type.js +5 -0
- package/package.json +65 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# @ant-design/web3-ton
|
|
2
|
+
|
|
3
|
+
## 0.0.0-alpha-20260209094036
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [01dc595]
|
|
8
|
+
- @ant-design/web3-common@0.0.0-alpha-20260209094036
|
|
9
|
+
- @ant-design/web3-assets@0.0.0-alpha-20260209094036
|
|
10
|
+
|
|
11
|
+
## 1.2.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 2ae483c: feat: support ignoreConfig for support multiple chain better
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [dfa67c5]
|
|
20
|
+
- Updated dependencies [2ae483c]
|
|
21
|
+
- @ant-design/web3-common@1.22.0
|
|
22
|
+
- @ant-design/web3-assets@1.14.3
|
|
23
|
+
|
|
24
|
+
## 1.1.4
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- @ant-design/web3-assets@1.14.2
|
|
29
|
+
|
|
30
|
+
## 1.1.3
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- @ant-design/web3-assets@1.14.1
|
|
35
|
+
|
|
36
|
+
## 1.1.2
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- Updated dependencies [640bce9]
|
|
41
|
+
- Updated dependencies [3d6d7c6]
|
|
42
|
+
- @ant-design/web3-assets@1.14.0
|
|
43
|
+
- @ant-design/web3-common@1.21.0
|
|
44
|
+
|
|
45
|
+
## 1.1.1
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [98dc8ef]
|
|
50
|
+
- Updated dependencies [b309635]
|
|
51
|
+
- Updated dependencies [d9629ed]
|
|
52
|
+
- @ant-design/web3-assets@1.13.0
|
|
53
|
+
- @ant-design/web3-common@1.20.0
|
|
54
|
+
|
|
55
|
+
## 1.1.0
|
|
56
|
+
|
|
57
|
+
### Minor Changes
|
|
58
|
+
|
|
59
|
+
- 09565b3: feat: update wallet extension info
|
|
60
|
+
|
|
61
|
+
### Patch Changes
|
|
62
|
+
|
|
63
|
+
- Updated dependencies [0f83657]
|
|
64
|
+
- @ant-design/web3-common@1.19.0
|
|
65
|
+
- @ant-design/web3-assets@1.12.1
|
|
66
|
+
|
|
67
|
+
## 1.0.12
|
|
68
|
+
|
|
69
|
+
### Patch Changes
|
|
70
|
+
|
|
71
|
+
- Updated dependencies [b6f1f1d]
|
|
72
|
+
- @ant-design/web3-assets@1.12.0
|
|
73
|
+
- @ant-design/web3-common@1.18.0
|
|
74
|
+
|
|
75
|
+
## 1.0.11
|
|
76
|
+
|
|
77
|
+
### Patch Changes
|
|
78
|
+
|
|
79
|
+
- Updated dependencies [f896044]
|
|
80
|
+
- @ant-design/web3-common@1.17.0
|
|
81
|
+
- @ant-design/web3-assets@1.11.8
|
|
82
|
+
|
|
83
|
+
## 1.0.10
|
|
84
|
+
|
|
85
|
+
### Patch Changes
|
|
86
|
+
|
|
87
|
+
- 8b857d3: chore: update wagmi version
|
|
88
|
+
- Updated dependencies [ad278cd]
|
|
89
|
+
- Updated dependencies [8b857d3]
|
|
90
|
+
- @ant-design/web3-common@1.16.0
|
|
91
|
+
- @ant-design/web3-assets@1.11.7
|
|
92
|
+
|
|
93
|
+
## 1.0.9
|
|
94
|
+
|
|
95
|
+
### Patch Changes
|
|
96
|
+
|
|
97
|
+
- @ant-design/web3-assets@1.11.6
|
|
98
|
+
|
|
99
|
+
## 1.0.8
|
|
100
|
+
|
|
101
|
+
### Patch Changes
|
|
102
|
+
|
|
103
|
+
- e0db15a: chore: upgrade pnpm version from 8.9.0 to 9.14.4
|
|
104
|
+
- Updated dependencies [14fae53]
|
|
105
|
+
- Updated dependencies [e0db15a]
|
|
106
|
+
- @ant-design/web3-assets@1.11.5
|
|
107
|
+
- @ant-design/web3-common@1.15.1
|
|
108
|
+
|
|
109
|
+
## 1.0.7
|
|
110
|
+
|
|
111
|
+
### Patch Changes
|
|
112
|
+
|
|
113
|
+
- Updated dependencies [0b2a19d]
|
|
114
|
+
- @ant-design/web3-common@1.15.0
|
|
115
|
+
- @ant-design/web3-assets@1.11.4
|
|
116
|
+
|
|
117
|
+
## 1.0.6
|
|
118
|
+
|
|
119
|
+
### Patch Changes
|
|
120
|
+
|
|
121
|
+
- @ant-design/web3-assets@1.11.3
|
|
122
|
+
|
|
123
|
+
## 1.0.5
|
|
124
|
+
|
|
125
|
+
### Patch Changes
|
|
126
|
+
|
|
127
|
+
- @ant-design/web3-assets@1.11.2
|
|
128
|
+
|
|
129
|
+
## 1.0.4
|
|
130
|
+
|
|
131
|
+
### Patch Changes
|
|
132
|
+
|
|
133
|
+
- 91801ad: chore: add readme
|
|
134
|
+
- Updated dependencies [c32f8e2]
|
|
135
|
+
- Updated dependencies [613b265]
|
|
136
|
+
- @ant-design/web3-common@1.14.0
|
|
137
|
+
- @ant-design/web3-assets@1.11.1
|
|
138
|
+
|
|
139
|
+
## 1.0.3
|
|
140
|
+
|
|
141
|
+
### Patch Changes
|
|
142
|
+
|
|
143
|
+
- Updated dependencies [c22eb4d]
|
|
144
|
+
- @ant-design/web3-assets@1.11.0
|
|
145
|
+
|
|
146
|
+
## 1.0.2
|
|
147
|
+
|
|
148
|
+
### Patch Changes
|
|
149
|
+
|
|
150
|
+
- Updated dependencies [9bb1ea1]
|
|
151
|
+
- @ant-design/web3-common@1.13.0
|
|
152
|
+
- @ant-design/web3-assets@1.10.2
|
|
153
|
+
|
|
154
|
+
## 1.0.1
|
|
155
|
+
|
|
156
|
+
### Patch Changes
|
|
157
|
+
|
|
158
|
+
- 2e5940c: fix: update okx wallet info in ton provider
|
|
159
|
+
- 3f7d7a6: build: set targets chrome 100
|
|
160
|
+
- Updated dependencies [3f7d7a6]
|
|
161
|
+
- @ant-design/web3-assets@1.10.1
|
|
162
|
+
- @ant-design/web3-common@1.12.1
|
|
163
|
+
|
|
164
|
+
## 1.0.0
|
|
165
|
+
|
|
166
|
+
### Major Changes
|
|
167
|
+
|
|
168
|
+
- d49a4b8: feat: add ton chain
|
|
169
|
+
|
|
170
|
+
### Patch Changes
|
|
171
|
+
|
|
172
|
+
- Updated dependencies [8f3430b]
|
|
173
|
+
- Updated dependencies [d663c3b]
|
|
174
|
+
- @ant-design/web3-assets@1.10.0
|
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,33 @@
|
|
|
1
|
+
# @ant-design/web3-ton
|
|
2
|
+
|
|
3
|
+
This package provides a [TON](https://ton.org) 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-ton --save
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { ConnectButton, Connector } from '@ant-design/web3';
|
|
13
|
+
import { okxTonWallet, tonkeeper, TonWeb3ConfigProvider } from '@ant-design/web3-ton';
|
|
14
|
+
|
|
15
|
+
const Basic = () => {
|
|
16
|
+
return (
|
|
17
|
+
<TonWeb3ConfigProvider wallets={[tonkeeper, okxTonWallet, { key: 'safepalwallet' }]}>
|
|
18
|
+
<Connector>
|
|
19
|
+
<ConnectButton />
|
|
20
|
+
</Connector>
|
|
21
|
+
</TonWeb3ConfigProvider>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default Basic;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
For more examples, refer to [TON - Ant Design Web3](https://web3.ant.design/components/ton).
|
|
29
|
+
|
|
30
|
+
## Documentation
|
|
31
|
+
|
|
32
|
+
- For more information, visit [Ant Design Web3](https://web3.ant.design).
|
|
33
|
+
- For an introduction to TON, visit [TON](https://ton.org).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CHAIN } from '@tonconnect/sdk';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CHAIN } from '@tonconnect/sdk';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useTonConnector';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useTonConnector";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const useTonConnector: () => {
|
|
2
|
+
connector: import("packages/ton/src/ton-provider/TonConnectSdk").default | null | undefined;
|
|
3
|
+
account: import("@tonconnect/sdk").Account | null | undefined;
|
|
4
|
+
tonSelectWallet: import("@tonconnect/sdk").Wallet | null | undefined;
|
|
5
|
+
setTonSelectWallet: ((sdk: import("@tonconnect/sdk").Wallet | null) => void) | undefined;
|
|
6
|
+
connectConfig: import("packages/ton/src/ton-provider/TonConnectSdk").TonConnectSdkConfigType | undefined;
|
|
7
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TonConnectorContext } from "../ton-provider/TonWeb3ConfigProvider";
|
|
3
|
+
export const useTonConnector = () => {
|
|
4
|
+
const provider = React.useContext(TonConnectorContext);
|
|
5
|
+
return {
|
|
6
|
+
connector: provider?.tonConnectSdk,
|
|
7
|
+
account: provider?.tonConnectSdk?.account,
|
|
8
|
+
tonSelectWallet: provider?.tonSelectWallet,
|
|
9
|
+
setTonSelectWallet: provider?.setTonSelectWallet,
|
|
10
|
+
connectConfig: provider?.connectConfig
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import TonConnect, { CHAIN, type TonConnectOptions } from '@tonconnect/sdk';
|
|
2
|
+
export interface TonConnectSdkConfigType extends TonConnectOptions {
|
|
3
|
+
chain?: CHAIN;
|
|
4
|
+
}
|
|
5
|
+
declare class TonConnectSdk extends TonConnect {
|
|
6
|
+
private _api;
|
|
7
|
+
private _network;
|
|
8
|
+
constructor(options: TonConnectSdkConfigType);
|
|
9
|
+
get network(): CHAIN;
|
|
10
|
+
set network(network: CHAIN);
|
|
11
|
+
get api(): string;
|
|
12
|
+
private _switchNetwork;
|
|
13
|
+
getBalance(url?: string): Promise<bigint>;
|
|
14
|
+
}
|
|
15
|
+
export default TonConnectSdk;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import TonConnect, { CHAIN } from '@tonconnect/sdk';
|
|
2
|
+
class TonConnectSdk extends TonConnect {
|
|
3
|
+
_api;
|
|
4
|
+
_network;
|
|
5
|
+
constructor(options) {
|
|
6
|
+
super({
|
|
7
|
+
manifestUrl: options?.manifestUrl
|
|
8
|
+
});
|
|
9
|
+
this._api = '';
|
|
10
|
+
this._network = CHAIN.MAINNET;
|
|
11
|
+
this._switchNetwork(options.chain || this._network);
|
|
12
|
+
}
|
|
13
|
+
get network() {
|
|
14
|
+
return this._network;
|
|
15
|
+
}
|
|
16
|
+
set network(network) {
|
|
17
|
+
this._switchNetwork(network);
|
|
18
|
+
}
|
|
19
|
+
get api() {
|
|
20
|
+
return this._api;
|
|
21
|
+
}
|
|
22
|
+
_switchNetwork(network) {
|
|
23
|
+
if (network === CHAIN.MAINNET) {
|
|
24
|
+
this._api = 'https://toncenter.com/api/v3';
|
|
25
|
+
} else {
|
|
26
|
+
this._api = 'https://testnet.toncenter.com/api/v3';
|
|
27
|
+
}
|
|
28
|
+
this._network = network;
|
|
29
|
+
}
|
|
30
|
+
async getBalance(url) {
|
|
31
|
+
if (!this.account?.address && !url) return Promise.resolve(0n);
|
|
32
|
+
const queryUrl = url || `${this._api}/account?address=${this.account?.address}`;
|
|
33
|
+
return fetch(queryUrl, {
|
|
34
|
+
method: 'GET',
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'application/json'
|
|
37
|
+
}
|
|
38
|
+
}).then(res => {
|
|
39
|
+
if (!res.ok) {
|
|
40
|
+
throw new Error('Failed to fetch balance');
|
|
41
|
+
}
|
|
42
|
+
return res.json();
|
|
43
|
+
}).then(res => {
|
|
44
|
+
return res.balance;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export default TonConnectSdk;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { type PropsWithChildren } from 'react';
|
|
2
|
+
import type { Locale } from '@ant-design/web3-common';
|
|
3
|
+
import type { CHAIN, TonConnectOptions, Wallet } from '@tonconnect/sdk';
|
|
4
|
+
import type { TonWalletMetadata } from '../wallets/type';
|
|
5
|
+
import TonConnectSdk, { type TonConnectSdkConfigType } from './TonConnectSdk';
|
|
6
|
+
interface TonConnectorContextProps {
|
|
7
|
+
tonConnectSdk: TonConnectSdk | null;
|
|
8
|
+
tonSelectWallet: Wallet | null;
|
|
9
|
+
setTonSelectWallet: (sdk: Wallet | null) => void;
|
|
10
|
+
connectConfig: TonConnectSdkConfigType;
|
|
11
|
+
}
|
|
12
|
+
export declare const TonConnectorContext: React.Context<TonConnectorContextProps | null>;
|
|
13
|
+
export interface TonWeb3ConfigProviderProps extends TonConnectOptions {
|
|
14
|
+
locale?: Locale;
|
|
15
|
+
balance?: boolean;
|
|
16
|
+
wallets: TonWalletMetadata[];
|
|
17
|
+
chain?: CHAIN;
|
|
18
|
+
reconnect?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* If true, this provider's configuration will be ignored when merging with parent context.
|
|
21
|
+
* This is useful when you have multiple chain providers and want to switch between them
|
|
22
|
+
* without causing page flickering. Only the active provider should not have this flag set.
|
|
23
|
+
*/
|
|
24
|
+
ignoreConfig?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare const TonWeb3ConfigProvider: React.FC<PropsWithChildren<TonWeb3ConfigProviderProps>>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { TonWalletFactory } from "../wallets/factory";
|
|
3
|
+
import TonConfigProvider from "./config-provider";
|
|
4
|
+
import TonConnectSdk from "./TonConnectSdk";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export const TonConnectorContext = /*#__PURE__*/React.createContext(null);
|
|
7
|
+
export const TonWeb3ConfigProvider = ({
|
|
8
|
+
children,
|
|
9
|
+
...restProps
|
|
10
|
+
}) => {
|
|
11
|
+
const {
|
|
12
|
+
balance,
|
|
13
|
+
locale,
|
|
14
|
+
wallets,
|
|
15
|
+
chain,
|
|
16
|
+
reconnect = true,
|
|
17
|
+
ignoreConfig
|
|
18
|
+
} = restProps;
|
|
19
|
+
const [tonConnectSdk, setTonConnectSdk] = React.useState(null);
|
|
20
|
+
const [tonSelectWallet, setTonSelectWallet] = React.useState(null);
|
|
21
|
+
const [tonWallets, setTonWallets] = React.useState([]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!tonConnectSdk) {
|
|
24
|
+
const tonSdk = new TonConnectSdk({
|
|
25
|
+
...restProps,
|
|
26
|
+
chain
|
|
27
|
+
});
|
|
28
|
+
if (reconnect) {
|
|
29
|
+
tonSdk.restoreConnection();
|
|
30
|
+
}
|
|
31
|
+
tonSdk.onStatusChange(s => {
|
|
32
|
+
setTonSelectWallet(s);
|
|
33
|
+
});
|
|
34
|
+
setTonConnectSdk(tonSdk);
|
|
35
|
+
}
|
|
36
|
+
}, [tonConnectSdk, restProps, reconnect, chain]);
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
if (tonConnectSdk && wallets?.length) {
|
|
39
|
+
tonConnectSdk.getWallets().then(res => {
|
|
40
|
+
const availableWallets = wallets.filter(w => res.findIndex(t => t.appName === w.key) >= 0);
|
|
41
|
+
setTonWallets(availableWallets.map(w => {
|
|
42
|
+
const tonBasicWallet = res.find(t => t.appName === w.key);
|
|
43
|
+
return {
|
|
44
|
+
...w,
|
|
45
|
+
...tonBasicWallet
|
|
46
|
+
};
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}, [wallets, tonConnectSdk]);
|
|
51
|
+
return /*#__PURE__*/_jsx(TonConnectorContext.Provider, {
|
|
52
|
+
value: {
|
|
53
|
+
tonConnectSdk,
|
|
54
|
+
tonSelectWallet,
|
|
55
|
+
setTonSelectWallet,
|
|
56
|
+
connectConfig: restProps
|
|
57
|
+
},
|
|
58
|
+
children: /*#__PURE__*/_jsx(TonConfigProvider, {
|
|
59
|
+
wallets: tonWallets.map(w => TonWalletFactory(w).create()),
|
|
60
|
+
balance: balance,
|
|
61
|
+
locale: locale,
|
|
62
|
+
ignoreConfig: ignoreConfig,
|
|
63
|
+
children: children
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React, { type PropsWithChildren } from 'react';
|
|
2
|
+
import type { TonWallet } from '../wallets/type';
|
|
3
|
+
import type { TonWeb3ConfigProviderProps } from './TonWeb3ConfigProvider';
|
|
4
|
+
interface TonConfigProviderProps extends Omit<TonWeb3ConfigProviderProps, 'wallets' | 'connectConfig'> {
|
|
5
|
+
wallets?: TonWallet[];
|
|
6
|
+
/**
|
|
7
|
+
* If true, this provider's configuration will be ignored when merging with parent context.
|
|
8
|
+
* This is useful when you have multiple chain providers and want to switch between them
|
|
9
|
+
* without causing page flickering. Only the active provider should not have this flag set.
|
|
10
|
+
*/
|
|
11
|
+
ignoreConfig?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare const TonConfigProvider: React.FC<PropsWithChildren<TonConfigProviderProps>>;
|
|
14
|
+
export default TonConfigProvider;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { Web3ConfigProvider } from '@ant-design/web3-common';
|
|
3
|
+
import { TonCircleColorful } from '@ant-design/web3-icons';
|
|
4
|
+
import { toUserFriendlyAddress } from '@tonconnect/sdk';
|
|
5
|
+
import { useTonConnector } from "../hooks";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const TonConfigProvider = ({
|
|
8
|
+
children,
|
|
9
|
+
locale,
|
|
10
|
+
balance: showBalance,
|
|
11
|
+
wallets,
|
|
12
|
+
ignoreConfig
|
|
13
|
+
}) => {
|
|
14
|
+
const {
|
|
15
|
+
connector,
|
|
16
|
+
tonSelectWallet,
|
|
17
|
+
setTonSelectWallet
|
|
18
|
+
} = useTonConnector();
|
|
19
|
+
const [balance, setBalance] = React.useState();
|
|
20
|
+
const [account, setAccount] = React.useState();
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!showBalance || !connector) return;
|
|
23
|
+
connector?.getBalance().then(res => {
|
|
24
|
+
setBalance({
|
|
25
|
+
value: BigInt(res)
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}, [connector, showBalance, tonSelectWallet]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (tonSelectWallet) {
|
|
31
|
+
setAccount({
|
|
32
|
+
address: toUserFriendlyAddress(tonSelectWallet.account.address)
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
setAccount(undefined);
|
|
36
|
+
}
|
|
37
|
+
}, [tonSelectWallet]);
|
|
38
|
+
return /*#__PURE__*/_jsx(Web3ConfigProvider, {
|
|
39
|
+
addressPrefix: false,
|
|
40
|
+
locale: locale,
|
|
41
|
+
availableWallets: wallets,
|
|
42
|
+
balance: balance ? {
|
|
43
|
+
...balance,
|
|
44
|
+
decimals: 9,
|
|
45
|
+
icon: /*#__PURE__*/_jsx(TonCircleColorful, {}),
|
|
46
|
+
symbol: 'TON'
|
|
47
|
+
} : undefined,
|
|
48
|
+
account: account,
|
|
49
|
+
connect: async wallet => {
|
|
50
|
+
const walletInfo = wallets?.find(w => w.appName === wallet?.key);
|
|
51
|
+
connector?.connect(walletInfo);
|
|
52
|
+
},
|
|
53
|
+
disconnect: async () => {
|
|
54
|
+
await connector?.disconnect();
|
|
55
|
+
if (!connector?.connected) {
|
|
56
|
+
setTonSelectWallet?.(null);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
ignoreConfig: ignoreConfig,
|
|
60
|
+
children: children
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
export default TonConfigProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TonWeb3ConfigProvider';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./TonWeb3ConfigProvider";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isWalletInfoCurrentlyInjected } from '@tonconnect/sdk';
|
|
2
|
+
export const TonWalletFactory = metadata => {
|
|
3
|
+
const isReady = isWalletInfoCurrentlyInjected(metadata);
|
|
4
|
+
return {
|
|
5
|
+
create: () => {
|
|
6
|
+
return {
|
|
7
|
+
...metadata,
|
|
8
|
+
name: metadata.name,
|
|
9
|
+
remark: metadata.appName,
|
|
10
|
+
key: metadata.appName,
|
|
11
|
+
icon: metadata.icon ?? metadata.imageUrl,
|
|
12
|
+
hasWalletReady: () => Promise.resolve(isReady),
|
|
13
|
+
hasExtensionInstalled: () => Promise.resolve(isReady)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ChromeCircleColorful, MytonWalletCircleColorful } from '@ant-design/web3-icons';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export const myTonWallet = {
|
|
4
|
+
key: 'mytonwallet',
|
|
5
|
+
icon: /*#__PURE__*/_jsx(MytonWalletCircleColorful, {}),
|
|
6
|
+
extensions: [{
|
|
7
|
+
key: 'Chrome',
|
|
8
|
+
browserIcon: /*#__PURE__*/_jsx(ChromeCircleColorful, {}),
|
|
9
|
+
browserName: 'Chrome',
|
|
10
|
+
link: 'https://chromewebstore.google.com/detail/fldfpgipfncgndfolcbkdeeknbbbnhcc',
|
|
11
|
+
description: 'The most feature-rich TON extension – with support of multi-accounts, tokens, NFT, TON DNS, TON Sites, TON Proxy, and TON Magic.'
|
|
12
|
+
}]
|
|
13
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { metadata_OkxWallet } from '@ant-design/web3-assets';
|
|
2
|
+
import { ChromeCircleColorful } from '@ant-design/web3-icons';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
export const okxTonWallet = {
|
|
5
|
+
...metadata_OkxWallet,
|
|
6
|
+
key: 'okxTonWallet',
|
|
7
|
+
group: 'Popular',
|
|
8
|
+
extensions: [{
|
|
9
|
+
key: 'Chrome',
|
|
10
|
+
browserIcon: /*#__PURE__*/_jsx(ChromeCircleColorful, {}),
|
|
11
|
+
browserName: 'Chrome',
|
|
12
|
+
link: 'https://chromewebstore.google.com/detail/mcohilncbfahbmgdjkbpemcciiolgcge',
|
|
13
|
+
description: 'Access your wallet right from your favorite web browser.'
|
|
14
|
+
}]
|
|
15
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ChromeCircleColorful, OpenmaskCircleColorful } from '@ant-design/web3-icons';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export const openmask = {
|
|
4
|
+
key: 'openmask',
|
|
5
|
+
icon: /*#__PURE__*/_jsx(OpenmaskCircleColorful, {}),
|
|
6
|
+
extensions: [{
|
|
7
|
+
key: 'Chrome',
|
|
8
|
+
browserIcon: /*#__PURE__*/_jsx(ChromeCircleColorful, {}),
|
|
9
|
+
browserName: 'Chrome',
|
|
10
|
+
link: 'https://chromewebstore.google.com/detail/penjlddjkjgpnkllboccdgccekpkcbin',
|
|
11
|
+
description: 'OpenMask is an extension for accessing TON enabled decentralized applications, or "dApps" in your browser! MetaMask analog for The Open Network.'
|
|
12
|
+
}]
|
|
13
|
+
};
|