@ton/appkit-react 0.0.3 → 0.0.5-alpha.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/README.md +11 -2
- package/dist/esm/features/network/hooks/use-default-network.js +28 -0
- package/dist/esm/features/network/hooks/use-default-network.js.map +1 -0
- package/dist/esm/features/network/hooks/use-networks.js +10 -3
- package/dist/esm/features/network/hooks/use-networks.js.map +1 -1
- package/dist/esm/features/network/index.js +1 -0
- package/dist/esm/features/network/index.js.map +1 -1
- package/dist/esm/features/nft/hooks/use-nfts-by-address.js +1 -1
- package/dist/esm/features/nft/hooks/use-nfts.js +2 -2
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/features/network/hooks/use-default-network.d.ts +17 -0
- package/dist/types/features/network/hooks/use-default-network.d.ts.map +1 -0
- package/dist/types/features/network/hooks/use-networks.d.ts.map +1 -1
- package/dist/types/features/network/index.d.ts +1 -0
- package/dist/types/features/network/index.d.ts.map +1 -1
- package/dist/types/features/nft/hooks/use-nfts-by-address.d.ts +1 -1
- package/package.json +2 -2
- package/src/features/network/hooks/use-default-network.ts +47 -0
- package/src/features/network/hooks/use-networks.ts +14 -3
- package/src/features/network/index.ts +1 -0
- package/src/features/nft/hooks/use-nfts-by-address.ts +1 -1
- package/src/features/nft/hooks/use-nfts.ts +2 -2
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
This file is auto-generated. Do not edit manually.
|
|
3
|
+
Changes will be overwritten when running the docs update script.
|
|
4
|
+
Source template: template/packages/appkit-react/README.md
|
|
5
|
+
-->
|
|
6
|
+
|
|
1
7
|
# @ton/appkit-react
|
|
2
8
|
|
|
3
9
|
React components and hooks for AppKit.
|
|
@@ -164,7 +170,7 @@ npm install @ston-fi/omniston-sdk
|
|
|
164
170
|
Initialize `AppKit` with `OmnistonSwapProvider`:
|
|
165
171
|
|
|
166
172
|
```ts
|
|
167
|
-
// Initialize AppKit with swap
|
|
173
|
+
// Initialize AppKit with swap providers
|
|
168
174
|
const appKit = new AppKit({
|
|
169
175
|
networks: {
|
|
170
176
|
[Network.mainnet().chainId]: {
|
|
@@ -176,10 +182,13 @@ const appKit = new AppKit({
|
|
|
176
182
|
},
|
|
177
183
|
providers: [
|
|
178
184
|
new OmnistonSwapProvider({
|
|
179
|
-
// Optional configuration
|
|
180
185
|
apiUrl: 'https://api.ston.fi',
|
|
181
186
|
defaultSlippageBps: 100, // 1%
|
|
182
187
|
}),
|
|
188
|
+
new DeDustSwapProvider({
|
|
189
|
+
defaultSlippageBps: 100,
|
|
190
|
+
referralAddress: 'EQ...', // Optional
|
|
191
|
+
}),
|
|
183
192
|
],
|
|
184
193
|
});
|
|
185
194
|
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { useSyncExternalStore, useCallback } from 'react';
|
|
9
|
+
import { getDefaultNetwork, setDefaultNetwork, watchDefaultNetwork } from '@ton/appkit';
|
|
10
|
+
import { useAppKit } from '../../../hooks/use-app-kit';
|
|
11
|
+
/**
|
|
12
|
+
* Hook to get and set the default network for wallet connections.
|
|
13
|
+
*/
|
|
14
|
+
export const useDefaultNetwork = () => {
|
|
15
|
+
const appKit = useAppKit();
|
|
16
|
+
const subscribe = useCallback((onChange) => {
|
|
17
|
+
return watchDefaultNetwork(appKit, { onChange });
|
|
18
|
+
}, [appKit]);
|
|
19
|
+
const getSnapshot = useCallback(() => {
|
|
20
|
+
return getDefaultNetwork(appKit);
|
|
21
|
+
}, [appKit]);
|
|
22
|
+
const network = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
23
|
+
const setNetwork = useCallback((newNetwork) => {
|
|
24
|
+
setDefaultNetwork(appKit, { network: newNetwork });
|
|
25
|
+
}, [appKit]);
|
|
26
|
+
return [network, setNetwork];
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=use-default-network.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-default-network.js","sourceRoot":"","sources":["../../../../../src/features/network/hooks/use-default-network.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGxF,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAOvD;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAgC,EAAE;IAC/D,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAE3B,MAAM,SAAS,GAAG,WAAW,CACzB,CAAC,QAAoB,EAAE,EAAE;QACrB,OAAO,mBAAmB,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IACrD,CAAC,EACD,CAAC,MAAM,CAAC,CACX,CAAC;IAEF,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE;QACjC,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,MAAM,OAAO,GAAG,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;IAE1E,MAAM,UAAU,GAAG,WAAW,CAC1B,CAAC,UAA+B,EAAE,EAAE;QAChC,iBAAiB,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;IACvD,CAAC,EACD,CAAC,MAAM,CAAC,CACX,CAAC;IAEF,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACjC,CAAC,CAAC"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import { useSyncExternalStore, useCallback } from 'react';
|
|
8
|
+
import { useSyncExternalStore, useCallback, useRef } from 'react';
|
|
9
9
|
import { getNetworks, watchNetworks } from '@ton/appkit';
|
|
10
10
|
import { useAppKit } from '../../../hooks/use-app-kit';
|
|
11
11
|
/**
|
|
@@ -13,12 +13,19 @@ import { useAppKit } from '../../../hooks/use-app-kit';
|
|
|
13
13
|
*/
|
|
14
14
|
export const useNetworks = () => {
|
|
15
15
|
const appKit = useAppKit();
|
|
16
|
+
const cachedRef = useRef([]);
|
|
16
17
|
const subscribe = useCallback((onChange) => {
|
|
17
18
|
return watchNetworks(appKit, { onChange });
|
|
18
19
|
}, [appKit]);
|
|
19
20
|
const getSnapshot = useCallback(() => {
|
|
20
|
-
|
|
21
|
+
const networks = getNetworks(appKit);
|
|
22
|
+
if (networks.length === cachedRef.current.length &&
|
|
23
|
+
networks.every((n, i) => n.chainId === cachedRef.current[i]?.chainId)) {
|
|
24
|
+
return cachedRef.current;
|
|
25
|
+
}
|
|
26
|
+
cachedRef.current = networks;
|
|
27
|
+
return networks;
|
|
21
28
|
}, [appKit]);
|
|
22
|
-
return useSyncExternalStore(subscribe, getSnapshot,
|
|
29
|
+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
23
30
|
};
|
|
24
31
|
//# sourceMappingURL=use-networks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-networks.js","sourceRoot":"","sources":["../../../../../src/features/network/hooks/use-networks.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"use-networks.js","sourceRoot":"","sources":["../../../../../src/features/network/hooks/use-networks.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,oBAAoB,E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WAAW,EAA8B,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,UAAU,EAA6B,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/features/network/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,QAAQ;AACR,OAAO,EAAE,WAAW,EAA8B,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,UAAU,EAA6B,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAoC,MAAM,6BAA6B,CAAC"}
|
|
@@ -11,7 +11,7 @@ import { useQuery } from '../../../libs/query';
|
|
|
11
11
|
/**
|
|
12
12
|
* Hook to get NFTs
|
|
13
13
|
*/
|
|
14
|
-
export const
|
|
14
|
+
export const useNftsByAddress = (parameters = {}) => {
|
|
15
15
|
const appKit = useAppKit();
|
|
16
16
|
return useQuery(getNFTsQueryOptions(appKit, parameters));
|
|
17
17
|
};
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
import { useAddress } from '../../wallets/hooks/use-address';
|
|
9
|
-
import {
|
|
9
|
+
import { useNftsByAddress } from './use-nfts-by-address';
|
|
10
10
|
/**
|
|
11
11
|
* Hook to get NFTs of the selected wallet
|
|
12
12
|
*/
|
|
13
13
|
export const useNfts = (parameters = {}) => {
|
|
14
14
|
const address = useAddress();
|
|
15
|
-
return
|
|
15
|
+
return useNftsByAddress({ ...parameters, address });
|
|
16
16
|
};
|
|
17
17
|
//# sourceMappingURL=use-nfts.js.map
|