@ton/appkit-react 0.0.6-alpha.1 → 0.0.6-alpha.3
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 +65 -2
- package/dist/esm/features/balances/components/send-jetton-button/send-jetton-button.js +2 -2
- package/dist/esm/features/balances/components/send-jetton-button/send-jetton-button.js.map +1 -1
- package/dist/esm/features/balances/components/send-ton-button/send-ton-button.js +2 -2
- package/dist/esm/features/balances/components/send-ton-button/send-ton-button.js.map +1 -1
- package/dist/esm/features/balances/hooks/use-watch-balance-by-address.js +43 -0
- package/dist/esm/features/balances/hooks/use-watch-balance-by-address.js.map +1 -0
- package/dist/esm/features/balances/hooks/use-watch-balance.js +20 -0
- package/dist/esm/features/balances/hooks/use-watch-balance.js.map +1 -0
- package/dist/esm/features/balances/index.js +2 -0
- package/dist/esm/features/balances/index.js.map +1 -1
- package/dist/esm/features/jettons/hooks/use-watch-jettons-by-address.js +49 -0
- package/dist/esm/features/jettons/hooks/use-watch-jettons-by-address.js.map +1 -0
- package/dist/esm/features/jettons/hooks/use-watch-jettons.js +20 -0
- package/dist/esm/features/jettons/hooks/use-watch-jettons.js.map +1 -0
- package/dist/esm/features/jettons/index.js +2 -0
- package/dist/esm/features/jettons/index.js.map +1 -1
- package/dist/esm/features/staking/hooks/use-build-stake-transaction.js +18 -0
- package/dist/esm/features/staking/hooks/use-build-stake-transaction.js.map +1 -0
- package/dist/esm/features/staking/hooks/use-staked-balance.js +18 -0
- package/dist/esm/features/staking/hooks/use-staked-balance.js.map +1 -0
- package/dist/esm/features/staking/hooks/use-staking-provider-info.js +18 -0
- package/dist/esm/features/staking/hooks/use-staking-provider-info.js.map +1 -0
- package/dist/esm/features/staking/hooks/use-staking-providers.js +18 -0
- package/dist/esm/features/staking/hooks/use-staking-providers.js.map +1 -0
- package/dist/esm/features/staking/hooks/use-staking-quote.js +18 -0
- package/dist/esm/features/staking/hooks/use-staking-quote.js.map +1 -0
- package/dist/esm/features/staking/index.js +14 -0
- package/dist/esm/features/staking/index.js.map +1 -0
- package/dist/esm/features/transaction/components/transaction/index.js +1 -1
- package/dist/esm/features/transaction/components/transaction/index.js.map +1 -1
- package/dist/esm/features/transaction/components/transaction/{transaction.js → send.js} +6 -6
- package/dist/esm/features/transaction/components/transaction/send.js.map +1 -0
- package/dist/esm/features/transaction/components/transaction-provider/index.js +1 -1
- package/dist/esm/features/transaction/components/transaction-provider/index.js.map +1 -1
- package/dist/esm/features/transaction/components/transaction-provider/{transaction-provider.js → send-provider.js} +6 -6
- package/dist/esm/features/transaction/components/transaction-provider/send-provider.js.map +1 -0
- package/dist/esm/features/transaction/hooks/use-watch-transactions-by-address.js +43 -0
- package/dist/esm/features/transaction/hooks/use-watch-transactions-by-address.js.map +1 -0
- package/dist/esm/features/transaction/hooks/use-watch-transactions.js +19 -0
- package/dist/esm/features/transaction/hooks/use-watch-transactions.js.map +1 -0
- package/dist/esm/features/transaction/index.js +2 -0
- package/dist/esm/features/transaction/index.js.map +1 -1
- package/dist/esm/features/wallets/hooks/use-connected-wallets.js +1 -1
- package/dist/esm/features/wallets/hooks/use-connected-wallets.js.map +1 -1
- package/dist/esm/features/wallets/hooks/use-connector-by-id.js +1 -1
- package/dist/esm/features/wallets/hooks/use-connector-by-id.js.map +1 -1
- package/dist/esm/features/wallets/hooks/use-connectors.js +1 -1
- package/dist/esm/features/wallets/hooks/use-connectors.js.map +1 -1
- package/dist/esm/features/wallets/hooks/use-selected-wallet.js +1 -1
- package/dist/esm/features/wallets/hooks/use-selected-wallet.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/tonconnect/tonconnect-bridge.js +3 -3
- package/dist/esm/tonconnect/tonconnect-bridge.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/features/balances/components/send-jetton-button/send-jetton-button.d.ts +2 -2
- package/dist/types/features/balances/components/send-jetton-button/send-jetton-button.d.ts.map +1 -1
- package/dist/types/features/balances/components/send-ton-button/send-ton-button.d.ts +2 -2
- package/dist/types/features/balances/components/send-ton-button/send-ton-button.d.ts.map +1 -1
- package/dist/types/features/balances/hooks/use-watch-balance-by-address.d.ts +15 -0
- package/dist/types/features/balances/hooks/use-watch-balance-by-address.d.ts.map +1 -0
- package/dist/types/features/balances/hooks/use-watch-balance.d.ts +15 -0
- package/dist/types/features/balances/hooks/use-watch-balance.d.ts.map +1 -0
- package/dist/types/features/balances/index.d.ts +2 -0
- package/dist/types/features/balances/index.d.ts.map +1 -1
- package/dist/types/features/jettons/hooks/use-watch-jettons-by-address.d.ts +15 -0
- package/dist/types/features/jettons/hooks/use-watch-jettons-by-address.d.ts.map +1 -0
- package/dist/types/features/jettons/hooks/use-watch-jettons.d.ts +15 -0
- package/dist/types/features/jettons/hooks/use-watch-jettons.d.ts.map +1 -0
- package/dist/types/features/jettons/index.d.ts +2 -0
- package/dist/types/features/jettons/index.d.ts.map +1 -1
- package/dist/types/features/staking/hooks/use-build-stake-transaction.d.ts +15 -0
- package/dist/types/features/staking/hooks/use-build-stake-transaction.d.ts.map +1 -0
- package/dist/types/features/staking/hooks/use-staked-balance.d.ts +16 -0
- package/dist/types/features/staking/hooks/use-staked-balance.d.ts.map +1 -0
- package/dist/types/features/staking/hooks/use-staking-provider-info.d.ts +16 -0
- package/dist/types/features/staking/hooks/use-staking-provider-info.d.ts.map +1 -0
- package/dist/types/features/staking/hooks/use-staking-providers.d.ts +16 -0
- package/dist/types/features/staking/hooks/use-staking-providers.d.ts.map +1 -0
- package/dist/types/features/staking/hooks/use-staking-quote.d.ts +16 -0
- package/dist/types/features/staking/hooks/use-staking-quote.d.ts.map +1 -0
- package/dist/types/features/staking/index.d.ts +14 -0
- package/dist/types/features/staking/index.d.ts.map +1 -0
- package/dist/types/features/transaction/components/transaction/index.d.ts +2 -2
- package/dist/types/features/transaction/components/transaction/index.d.ts.map +1 -1
- package/dist/types/features/transaction/components/transaction/{transaction.d.ts → send.d.ts} +7 -7
- package/dist/types/features/transaction/components/transaction/send.d.ts.map +1 -0
- package/dist/types/features/transaction/components/transaction-provider/index.d.ts +2 -2
- package/dist/types/features/transaction/components/transaction-provider/index.d.ts.map +1 -1
- package/dist/types/features/transaction/components/transaction-provider/{transaction-provider.d.ts → send-provider.d.ts} +8 -8
- package/dist/types/features/transaction/components/transaction-provider/send-provider.d.ts.map +1 -0
- package/dist/types/features/transaction/hooks/use-watch-transactions-by-address.d.ts +14 -0
- package/dist/types/features/transaction/hooks/use-watch-transactions-by-address.d.ts.map +1 -0
- package/dist/types/features/transaction/hooks/use-watch-transactions.d.ts +16 -0
- package/dist/types/features/transaction/hooks/use-watch-transactions.d.ts.map +1 -0
- package/dist/types/features/transaction/index.d.ts +2 -0
- package/dist/types/features/transaction/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/tonconnect/tonconnect-bridge.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/features/balances/components/send-jetton-button/send-jetton-button.tsx +4 -4
- package/src/features/balances/components/send-ton-button/send-ton-button.tsx +4 -4
- package/src/features/balances/hooks/use-watch-balance-by-address.ts +54 -0
- package/src/features/balances/hooks/use-watch-balance.ts +25 -0
- package/src/features/balances/index.ts +2 -0
- package/src/features/jettons/hooks/use-watch-jettons-by-address.ts +66 -0
- package/src/features/jettons/hooks/use-watch-jettons.ts +26 -0
- package/src/features/jettons/index.ts +2 -0
- package/src/features/staking/hooks/use-build-stake-transaction.ts +33 -0
- package/src/features/staking/hooks/use-staked-balance.ts +30 -0
- package/src/features/staking/hooks/use-staking-provider-info.ts +35 -0
- package/src/features/staking/hooks/use-staking-providers.ts +35 -0
- package/src/features/staking/hooks/use-staking-quote.ts +30 -0
- package/src/features/staking/index.ts +31 -0
- package/src/features/transaction/components/transaction/index.ts +2 -2
- package/src/features/transaction/components/transaction/{transaction.tsx → send.tsx} +15 -15
- package/src/features/transaction/components/transaction-provider/index.ts +2 -2
- package/src/features/transaction/components/transaction-provider/{transaction-provider.tsx → send-provider.tsx} +9 -15
- package/src/features/transaction/hooks/use-watch-transactions-by-address.ts +55 -0
- package/src/features/transaction/hooks/use-watch-transactions.ts +27 -0
- package/src/features/transaction/index.ts +2 -0
- package/src/features/wallets/hooks/use-connected-wallets.ts +1 -1
- package/src/features/wallets/hooks/use-connector-by-id.ts +1 -1
- package/src/features/wallets/hooks/use-connectors.ts +1 -1
- package/src/features/wallets/hooks/use-selected-wallet.ts +1 -1
- package/src/index.ts +1 -0
- package/src/tonconnect/tonconnect-bridge.tsx +6 -3
- package/dist/esm/features/transaction/components/transaction/transaction.js.map +0 -1
- package/dist/esm/features/transaction/components/transaction-provider/transaction-provider.js.map +0 -1
- package/dist/types/features/transaction/components/transaction/transaction.d.ts.map +0 -1
- package/dist/types/features/transaction/components/transaction-provider/transaction-provider.d.ts.map +0 -1
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
|
|
9
|
+
import { useEffect } from 'react';
|
|
10
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
11
|
+
import { watchBalanceByAddress, hasStreamingProvider, resolveNetwork } from '@ton/appkit';
|
|
12
|
+
import type { WatchBalanceByAddressOptions } from '@ton/appkit';
|
|
13
|
+
import { handleBalanceUpdate } from '@ton/appkit/queries';
|
|
14
|
+
|
|
15
|
+
import { useAppKit } from '../../../hooks/use-app-kit';
|
|
16
|
+
|
|
17
|
+
export type UseWatchBalanceByAddressParameters = Partial<WatchBalanceByAddressOptions>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Hook to watch balance of a specific address in real-time.
|
|
21
|
+
* Automatically updates the TanStack Query cache for `useBalanceByAddress`.
|
|
22
|
+
*/
|
|
23
|
+
export const useWatchBalanceByAddress = (parameters: UseWatchBalanceByAddressParameters): void => {
|
|
24
|
+
const { address, network, onChange } = parameters;
|
|
25
|
+
const appKit = useAppKit();
|
|
26
|
+
const queryClient = useQueryClient();
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!address) return;
|
|
30
|
+
|
|
31
|
+
const resolvedNetwork = resolveNetwork(appKit, network);
|
|
32
|
+
if (!resolvedNetwork || !hasStreamingProvider(appKit, resolvedNetwork)) {
|
|
33
|
+
// eslint-disable-next-line no-console
|
|
34
|
+
console.warn(
|
|
35
|
+
resolvedNetwork
|
|
36
|
+
? `No streaming provider available for network: ${resolvedNetwork?.chainId}`
|
|
37
|
+
: 'No network provided',
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const addressString = address.toString();
|
|
44
|
+
|
|
45
|
+
return watchBalanceByAddress(appKit, {
|
|
46
|
+
address,
|
|
47
|
+
network: resolvedNetwork,
|
|
48
|
+
onChange: (balance) => {
|
|
49
|
+
onChange?.(balance);
|
|
50
|
+
handleBalanceUpdate(queryClient, { address: addressString, network: resolvedNetwork }, balance);
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}, [address, network, appKit, queryClient, onChange]);
|
|
54
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
|
|
9
|
+
import { useAddress } from '../../wallets/hooks/use-address';
|
|
10
|
+
import { useNetwork } from '../../network/hooks/use-network';
|
|
11
|
+
import { useWatchBalanceByAddress } from './use-watch-balance-by-address';
|
|
12
|
+
import type { UseWatchBalanceByAddressParameters } from './use-watch-balance-by-address';
|
|
13
|
+
|
|
14
|
+
export type UseWatchBalanceParameters = Omit<UseWatchBalanceByAddressParameters, 'address'>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Hook to watch balance of the currently selected wallet in real-time.
|
|
18
|
+
* Automatically updates the TanStack Query cache for `useBalance`.
|
|
19
|
+
*/
|
|
20
|
+
export const useWatchBalance = (parameters: UseWatchBalanceParameters = {}): void => {
|
|
21
|
+
const address = useAddress();
|
|
22
|
+
const network = useNetwork();
|
|
23
|
+
|
|
24
|
+
useWatchBalanceByAddress({ ...parameters, address, network });
|
|
25
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
|
|
9
|
+
import { useEffect } from 'react';
|
|
10
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
11
|
+
import { watchJettonsByAddress, hasStreamingProvider, resolveNetwork } from '@ton/appkit';
|
|
12
|
+
import type { WatchJettonsByAddressOptions, JettonUpdate } from '@ton/appkit';
|
|
13
|
+
import { handleJettonBalanceUpdate, handleJettonsUpdate } from '@ton/appkit/queries';
|
|
14
|
+
|
|
15
|
+
import { useAppKit } from '../../../hooks/use-app-kit';
|
|
16
|
+
|
|
17
|
+
export type UseWatchJettonsByAddressParameters = Partial<WatchJettonsByAddressOptions>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Hook to watch jetton updates for a specific address in real-time.
|
|
21
|
+
* Automatically updates TanStack Query caches for jetton balances.
|
|
22
|
+
*/
|
|
23
|
+
export const useWatchJettonsByAddress = (parameters: UseWatchJettonsByAddressParameters): void => {
|
|
24
|
+
const { address, network } = parameters;
|
|
25
|
+
const appKit = useAppKit();
|
|
26
|
+
const queryClient = useQueryClient();
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!address) return;
|
|
30
|
+
|
|
31
|
+
const resolvedNetwork = resolveNetwork(appKit, network);
|
|
32
|
+
if (!resolvedNetwork || !hasStreamingProvider(appKit, resolvedNetwork)) {
|
|
33
|
+
// eslint-disable-next-line no-console
|
|
34
|
+
console.warn(
|
|
35
|
+
resolvedNetwork
|
|
36
|
+
? `No streaming provider available for network: ${resolvedNetwork?.chainId}`
|
|
37
|
+
: 'No network provided',
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const addressString = address.toString();
|
|
44
|
+
|
|
45
|
+
return watchJettonsByAddress(appKit, {
|
|
46
|
+
...parameters,
|
|
47
|
+
address,
|
|
48
|
+
network: resolvedNetwork,
|
|
49
|
+
onChange: (update: JettonUpdate) => {
|
|
50
|
+
parameters.onChange?.(update);
|
|
51
|
+
|
|
52
|
+
handleJettonsUpdate(queryClient, { address: addressString, network: resolvedNetwork }, update);
|
|
53
|
+
|
|
54
|
+
handleJettonBalanceUpdate(
|
|
55
|
+
queryClient,
|
|
56
|
+
{
|
|
57
|
+
ownerAddress: addressString,
|
|
58
|
+
jettonAddress: update.masterAddress,
|
|
59
|
+
network: resolvedNetwork,
|
|
60
|
+
},
|
|
61
|
+
update,
|
|
62
|
+
);
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}, [address, network, appKit, queryClient, parameters]);
|
|
66
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
|
|
9
|
+
import type { WatchJettonsOptions } from '@ton/appkit';
|
|
10
|
+
|
|
11
|
+
import { useAddress } from '../../wallets/hooks/use-address';
|
|
12
|
+
import { useNetwork } from '../../network/hooks/use-network';
|
|
13
|
+
import { useWatchJettonsByAddress } from './use-watch-jettons-by-address';
|
|
14
|
+
|
|
15
|
+
export type UseWatchJettonsParameters = Partial<WatchJettonsOptions>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Hook to watch jetton updates of the currently selected wallet in real-time.
|
|
19
|
+
* Automatically updates TanStack Query caches for jetton balances.
|
|
20
|
+
*/
|
|
21
|
+
export const useWatchJettons = (parameters: UseWatchJettonsParameters = {}): void => {
|
|
22
|
+
const address = useAddress();
|
|
23
|
+
const network = useNetwork();
|
|
24
|
+
|
|
25
|
+
useWatchJettonsByAddress({ ...parameters, address, network });
|
|
26
|
+
};
|
|
@@ -11,4 +11,6 @@ export * from './hooks/use-jetton-wallet-address';
|
|
|
11
11
|
export * from './hooks/use-jetton-balance-by-address';
|
|
12
12
|
export * from './hooks/use-jettons';
|
|
13
13
|
export * from './hooks/use-jettons-by-address';
|
|
14
|
+
export * from './hooks/use-watch-jettons-by-address';
|
|
14
15
|
export * from './hooks/use-transfer-jetton';
|
|
16
|
+
export * from './hooks/use-watch-jettons';
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
|
|
9
|
+
import type { UseMutationResult } from '@tanstack/react-query';
|
|
10
|
+
import { buildStakeTransactionMutationOptions } from '@ton/appkit/queries';
|
|
11
|
+
import type {
|
|
12
|
+
BuildStakeTransactionData,
|
|
13
|
+
BuildStakeTransactionErrorType,
|
|
14
|
+
BuildStakeTransactionVariables,
|
|
15
|
+
} from '@ton/appkit/queries';
|
|
16
|
+
|
|
17
|
+
import { useAppKit } from '../../../hooks/use-app-kit';
|
|
18
|
+
import { useMutation } from '../../../libs/query';
|
|
19
|
+
|
|
20
|
+
export type UseBuildStakeTransactionReturnType<context = unknown> = UseMutationResult<
|
|
21
|
+
BuildStakeTransactionData,
|
|
22
|
+
BuildStakeTransactionErrorType,
|
|
23
|
+
BuildStakeTransactionVariables,
|
|
24
|
+
context
|
|
25
|
+
>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Hook to build stake transaction
|
|
29
|
+
*/
|
|
30
|
+
export const useBuildStakeTransaction = <context = unknown>(): UseBuildStakeTransactionReturnType<context> => {
|
|
31
|
+
const appKit = useAppKit();
|
|
32
|
+
return useMutation(buildStakeTransactionMutationOptions<context>(appKit));
|
|
33
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
|
|
9
|
+
import { getStakedBalanceQueryOptions } from '@ton/appkit/queries';
|
|
10
|
+
import type { GetStakedBalanceData, GetStakedBalanceErrorType, GetStakedBalanceQueryConfig } from '@ton/appkit/queries';
|
|
11
|
+
|
|
12
|
+
import { useAppKit } from '../../../hooks/use-app-kit';
|
|
13
|
+
import { useQuery } from '../../../libs/query';
|
|
14
|
+
import type { UseQueryReturnType } from '../../../libs/query';
|
|
15
|
+
|
|
16
|
+
export type UseStakedBalanceParameters<selectData = GetStakedBalanceData> = GetStakedBalanceQueryConfig<selectData>;
|
|
17
|
+
export type UseStakedBalanceReturnType<selectData = GetStakedBalanceData> = UseQueryReturnType<
|
|
18
|
+
selectData,
|
|
19
|
+
GetStakedBalanceErrorType
|
|
20
|
+
>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Hook to get user's staked balance
|
|
24
|
+
*/
|
|
25
|
+
export const useStakedBalance = <selectData = GetStakedBalanceData>(
|
|
26
|
+
parameters: UseStakedBalanceParameters<selectData> = {},
|
|
27
|
+
): UseStakedBalanceReturnType<selectData> => {
|
|
28
|
+
const appKit = useAppKit();
|
|
29
|
+
return useQuery(getStakedBalanceQueryOptions(appKit, parameters));
|
|
30
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
|
|
9
|
+
import { getStakingProviderInfoQueryOptions } from '@ton/appkit/queries';
|
|
10
|
+
import type {
|
|
11
|
+
GetStakingProviderInfoData,
|
|
12
|
+
GetStakingProviderInfoErrorType,
|
|
13
|
+
GetStakingProviderInfoQueryConfig,
|
|
14
|
+
} from '@ton/appkit/queries';
|
|
15
|
+
|
|
16
|
+
import { useAppKit } from '../../../hooks/use-app-kit';
|
|
17
|
+
import { useQuery } from '../../../libs/query';
|
|
18
|
+
import type { UseQueryReturnType } from '../../../libs/query';
|
|
19
|
+
|
|
20
|
+
export type UseStakingProviderInfoParameters<selectData = GetStakingProviderInfoData> =
|
|
21
|
+
GetStakingProviderInfoQueryConfig<selectData>;
|
|
22
|
+
export type UseStakingProviderInfoReturnType<selectData = GetStakingProviderInfoData> = UseQueryReturnType<
|
|
23
|
+
selectData,
|
|
24
|
+
GetStakingProviderInfoErrorType
|
|
25
|
+
>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Hook to get staking provider information
|
|
29
|
+
*/
|
|
30
|
+
export const useStakingProviderInfo = <selectData = GetStakingProviderInfoData>(
|
|
31
|
+
parameters: UseStakingProviderInfoParameters<selectData> = {},
|
|
32
|
+
): UseStakingProviderInfoReturnType<selectData> => {
|
|
33
|
+
const appKit = useAppKit();
|
|
34
|
+
return useQuery(getStakingProviderInfoQueryOptions(appKit, parameters));
|
|
35
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
|
|
9
|
+
import { getStakingProvidersQueryOptions } from '@ton/appkit/queries';
|
|
10
|
+
import type {
|
|
11
|
+
GetStakingProvidersData,
|
|
12
|
+
GetStakingProvidersErrorType,
|
|
13
|
+
GetStakingProvidersQueryConfig,
|
|
14
|
+
} from '@ton/appkit/queries';
|
|
15
|
+
|
|
16
|
+
import { useAppKit } from '../../../hooks/use-app-kit';
|
|
17
|
+
import { useQuery } from '../../../libs/query';
|
|
18
|
+
import type { UseQueryReturnType } from '../../../libs/query';
|
|
19
|
+
|
|
20
|
+
export type UseStakingProvidersParameters<selectData = GetStakingProvidersData> =
|
|
21
|
+
GetStakingProvidersQueryConfig<selectData>;
|
|
22
|
+
export type UseStakingProvidersReturnType<selectData = GetStakingProvidersData> = UseQueryReturnType<
|
|
23
|
+
selectData,
|
|
24
|
+
GetStakingProvidersErrorType
|
|
25
|
+
>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Hook to get available staking provider IDs
|
|
29
|
+
*/
|
|
30
|
+
export const useStakingProviders = <selectData = GetStakingProvidersData>(
|
|
31
|
+
parameters: UseStakingProvidersParameters<selectData> = {},
|
|
32
|
+
): UseStakingProvidersReturnType<selectData> => {
|
|
33
|
+
const appKit = useAppKit();
|
|
34
|
+
return useQuery(getStakingProvidersQueryOptions(appKit, parameters));
|
|
35
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
|
|
9
|
+
import { getStakingQuoteQueryOptions } from '@ton/appkit/queries';
|
|
10
|
+
import type { GetStakingQuoteData, GetStakingQuoteErrorType, GetStakingQuoteQueryConfig } from '@ton/appkit/queries';
|
|
11
|
+
|
|
12
|
+
import { useAppKit } from '../../../hooks/use-app-kit';
|
|
13
|
+
import { useQuery } from '../../../libs/query';
|
|
14
|
+
import type { UseQueryReturnType } from '../../../libs/query';
|
|
15
|
+
|
|
16
|
+
export type UseStakingQuoteParameters<selectData = GetStakingQuoteData> = GetStakingQuoteQueryConfig<selectData>;
|
|
17
|
+
export type UseStakingQuoteReturnType<selectData = GetStakingQuoteData> = UseQueryReturnType<
|
|
18
|
+
selectData,
|
|
19
|
+
GetStakingQuoteErrorType
|
|
20
|
+
>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Hook to get staking/unstaking quote
|
|
24
|
+
*/
|
|
25
|
+
export const useStakingQuote = <selectData = GetStakingQuoteData>(
|
|
26
|
+
parameters: UseStakingQuoteParameters<selectData> = {},
|
|
27
|
+
): UseStakingQuoteReturnType<selectData> => {
|
|
28
|
+
const appKit = useAppKit();
|
|
29
|
+
return useQuery(getStakingQuoteQueryOptions(appKit, parameters));
|
|
30
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
|
|
9
|
+
export { UnstakeMode, type UnstakeModes } from '@ton/appkit';
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
useStakingProviders,
|
|
13
|
+
type UseStakingProvidersParameters,
|
|
14
|
+
type UseStakingProvidersReturnType,
|
|
15
|
+
} from './hooks/use-staking-providers';
|
|
16
|
+
export {
|
|
17
|
+
useStakingQuote,
|
|
18
|
+
type UseStakingQuoteParameters,
|
|
19
|
+
type UseStakingQuoteReturnType,
|
|
20
|
+
} from './hooks/use-staking-quote';
|
|
21
|
+
export {
|
|
22
|
+
useStakedBalance,
|
|
23
|
+
type UseStakedBalanceParameters,
|
|
24
|
+
type UseStakedBalanceReturnType,
|
|
25
|
+
} from './hooks/use-staked-balance';
|
|
26
|
+
export {
|
|
27
|
+
useStakingProviderInfo,
|
|
28
|
+
type UseStakingProviderInfoParameters,
|
|
29
|
+
type UseStakingProviderInfoReturnType,
|
|
30
|
+
} from './hooks/use-staking-provider-info';
|
|
31
|
+
export { useBuildStakeTransaction, type UseBuildStakeTransactionReturnType } from './hooks/use-build-stake-transaction';
|
|
@@ -10,26 +10,26 @@ import { useCallback, useMemo } from 'react';
|
|
|
10
10
|
import type { FC, ReactNode, ComponentProps } from 'react';
|
|
11
11
|
import type { SendTransactionParameters, SendTransactionReturnType } from '@ton/appkit';
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { SendProvider, useSendContext } from '../transaction-provider';
|
|
14
14
|
import { useI18n } from '../../../../hooks/use-i18n';
|
|
15
15
|
import { Button } from '../../../../components/button';
|
|
16
16
|
|
|
17
|
-
export interface
|
|
17
|
+
export interface SendRenderProps {
|
|
18
18
|
isLoading: boolean;
|
|
19
19
|
onSubmit: () => void;
|
|
20
20
|
disabled: boolean;
|
|
21
21
|
text: ReactNode;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export type
|
|
24
|
+
export type SendRequest =
|
|
25
25
|
| SendTransactionParameters
|
|
26
26
|
| Promise<SendTransactionParameters>
|
|
27
27
|
| (() => SendTransactionParameters)
|
|
28
28
|
| (() => Promise<SendTransactionParameters>);
|
|
29
29
|
|
|
30
|
-
export interface
|
|
30
|
+
export interface SendProps extends Omit<ComponentProps<'button'>, 'children' | 'onError'> {
|
|
31
31
|
/** The transaction request parameters */
|
|
32
|
-
request:
|
|
32
|
+
request: SendRequest;
|
|
33
33
|
/** Callback when an error occurs */
|
|
34
34
|
onError?: (error: Error) => void;
|
|
35
35
|
/** Callback when the transaction is successful */
|
|
@@ -37,16 +37,16 @@ export interface TransactionProps extends Omit<ComponentProps<'button'>, 'childr
|
|
|
37
37
|
/** Custom button text */
|
|
38
38
|
text?: ReactNode;
|
|
39
39
|
/** Custom render function */
|
|
40
|
-
children?: (props:
|
|
40
|
+
children?: (props: SendRenderProps) => ReactNode;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
interface
|
|
43
|
+
interface SendContentProps extends Omit<ComponentProps<'button'>, 'children'> {
|
|
44
44
|
text?: ReactNode;
|
|
45
|
-
children?: (props:
|
|
45
|
+
children?: (props: SendRenderProps) => ReactNode;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const
|
|
49
|
-
const { isLoading, onSubmit, disabled } =
|
|
48
|
+
const SendContent: FC<SendContentProps> = ({ text, children, ...props }) => {
|
|
49
|
+
const { isLoading, onSubmit, disabled } = useSendContext();
|
|
50
50
|
const { t } = useI18n();
|
|
51
51
|
|
|
52
52
|
const isDisabled = disabled || isLoading;
|
|
@@ -85,7 +85,7 @@ const TransactionContent: FC<TransactionContentProps> = ({ text, children, ...pr
|
|
|
85
85
|
);
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
export const
|
|
88
|
+
export const Send: FC<SendProps> = ({
|
|
89
89
|
request,
|
|
90
90
|
children,
|
|
91
91
|
className,
|
|
@@ -96,10 +96,10 @@ export const Transaction: FC<TransactionProps> = ({
|
|
|
96
96
|
...props
|
|
97
97
|
}) => {
|
|
98
98
|
return (
|
|
99
|
-
<
|
|
100
|
-
<
|
|
99
|
+
<SendProvider request={request} onError={onError} onSuccess={onSuccess} disabled={disabled}>
|
|
100
|
+
<SendContent className={className} text={text} {...props}>
|
|
101
101
|
{children}
|
|
102
|
-
</
|
|
103
|
-
</
|
|
102
|
+
</SendContent>
|
|
103
|
+
</SendProvider>
|
|
104
104
|
);
|
|
105
105
|
};
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
export {
|
|
10
|
-
export type {
|
|
9
|
+
export { SendProvider, useSendContext, SendContext } from './send-provider';
|
|
10
|
+
export type { SendProviderProps, SendContextType } from './send-provider';
|
|
@@ -11,9 +11,9 @@ import type { FC, PropsWithChildren } from 'react';
|
|
|
11
11
|
import type { SendTransactionReturnType } from '@ton/appkit';
|
|
12
12
|
|
|
13
13
|
import { useSendTransaction } from '../../hooks/use-send-transaction';
|
|
14
|
-
import type {
|
|
14
|
+
import type { SendRequest } from '../transaction/send';
|
|
15
15
|
|
|
16
|
-
export interface
|
|
16
|
+
export interface SendContextType {
|
|
17
17
|
/** Function to submit the transaction */
|
|
18
18
|
onSubmit: () => void;
|
|
19
19
|
/** Whether the transaction is currently loading */
|
|
@@ -26,22 +26,22 @@ export interface TransactionContextType {
|
|
|
26
26
|
disabled?: boolean;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export const
|
|
29
|
+
export const SendContext = createContext<SendContextType>({
|
|
30
30
|
onSubmit: () => {
|
|
31
31
|
throw new Error('onSubmit is not defined');
|
|
32
32
|
},
|
|
33
33
|
isLoading: false,
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
export function
|
|
37
|
-
const context = useContext(
|
|
36
|
+
export function useSendContext() {
|
|
37
|
+
const context = useContext(SendContext);
|
|
38
38
|
|
|
39
39
|
return context;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export interface
|
|
42
|
+
export interface SendProviderProps extends PropsWithChildren {
|
|
43
43
|
/** The transaction request parameters */
|
|
44
|
-
request:
|
|
44
|
+
request: SendRequest;
|
|
45
45
|
/** Callback when an error occurs */
|
|
46
46
|
onError?: (error: Error) => void;
|
|
47
47
|
/** Callback when the transaction is successful */
|
|
@@ -50,13 +50,7 @@ export interface TransactionProviderProps extends PropsWithChildren {
|
|
|
50
50
|
disabled?: boolean;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export const
|
|
54
|
-
children,
|
|
55
|
-
request,
|
|
56
|
-
onError,
|
|
57
|
-
onSuccess,
|
|
58
|
-
disabled = false,
|
|
59
|
-
}) => {
|
|
53
|
+
export const SendProvider: FC<SendProviderProps> = ({ children, request, onError, onSuccess, disabled = false }) => {
|
|
60
54
|
const [receipt, setReceipt] = useState<SendTransactionReturnType | null>(null);
|
|
61
55
|
const [isPreparing, setIsPreparing] = useState(false);
|
|
62
56
|
|
|
@@ -110,5 +104,5 @@ export const TransactionProvider: FC<TransactionProviderProps> = ({
|
|
|
110
104
|
[mutationError, isPreparing, isPending, handleSubmit, receipt, disabled],
|
|
111
105
|
);
|
|
112
106
|
|
|
113
|
-
return <
|
|
107
|
+
return <SendContext.Provider value={value}>{children}</SendContext.Provider>;
|
|
114
108
|
};
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
|
|
9
|
+
import { useEffect } from 'react';
|
|
10
|
+
import { watchTransactionsByAddress, hasStreamingProvider, resolveNetwork } from '@ton/appkit';
|
|
11
|
+
import type { WatchTransactionsByAddressOptions, TransactionsUpdate } from '@ton/appkit';
|
|
12
|
+
|
|
13
|
+
import { useAppKit } from '../../../hooks/use-app-kit';
|
|
14
|
+
|
|
15
|
+
export type UseWatchTransactionsByAddressParameters = Partial<WatchTransactionsByAddressOptions>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Hook to watch transactions for a specific address in real-time.
|
|
19
|
+
*/
|
|
20
|
+
export const useWatchTransactionsByAddress = (parameters: UseWatchTransactionsByAddressParameters): void => {
|
|
21
|
+
const { address, network } = parameters;
|
|
22
|
+
const appKit = useAppKit();
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!address) return;
|
|
26
|
+
|
|
27
|
+
const resolvedNetwork = resolveNetwork(appKit, network);
|
|
28
|
+
if (!resolvedNetwork || !hasStreamingProvider(appKit, resolvedNetwork)) {
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
console.warn(
|
|
31
|
+
resolvedNetwork
|
|
32
|
+
? `No streaming provider available for network: ${resolvedNetwork?.chainId}`
|
|
33
|
+
: 'No network provided',
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!parameters.onChange) {
|
|
40
|
+
// eslint-disable-next-line no-console
|
|
41
|
+
console.warn('No onChange callback provided for watchTransactionsByAddress');
|
|
42
|
+
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return watchTransactionsByAddress(appKit, {
|
|
47
|
+
...parameters,
|
|
48
|
+
address,
|
|
49
|
+
network: resolvedNetwork,
|
|
50
|
+
onChange: (update: TransactionsUpdate) => {
|
|
51
|
+
parameters.onChange?.(update);
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}, [address, network, appKit, parameters]);
|
|
55
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
|
|
9
|
+
import type { TransactionsUpdate } from '@ton/appkit';
|
|
10
|
+
|
|
11
|
+
import { useAddress } from '../../wallets/hooks/use-address';
|
|
12
|
+
import { useNetwork } from '../../network/hooks/use-network';
|
|
13
|
+
import { useWatchTransactionsByAddress } from './use-watch-transactions-by-address';
|
|
14
|
+
|
|
15
|
+
export interface UseWatchTransactionsParameters {
|
|
16
|
+
onChange?: (update: TransactionsUpdate) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Hook to watch transaction updates of the currently selected wallet in real-time.
|
|
21
|
+
*/
|
|
22
|
+
export const useWatchTransactions = (parameters: UseWatchTransactionsParameters = {}): void => {
|
|
23
|
+
const address = useAddress();
|
|
24
|
+
const network = useNetwork();
|
|
25
|
+
|
|
26
|
+
useWatchTransactionsByAddress({ ...parameters, address, network });
|
|
27
|
+
};
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
export * from './hooks/use-send-transaction';
|
|
10
10
|
export * from './hooks/use-transfer-ton';
|
|
11
11
|
export * from './hooks/use-transaction-status';
|
|
12
|
+
export * from './hooks/use-watch-transactions-by-address';
|
|
13
|
+
export * from './hooks/use-watch-transactions';
|
|
12
14
|
|
|
13
15
|
export * from './components/transaction';
|
|
14
16
|
export * from './components/transaction-progress';
|
|
@@ -28,5 +28,5 @@ export const useConnectedWallets = (): UseConnectedWalletsReturnType => {
|
|
|
28
28
|
return getConnectedWallets(appKit);
|
|
29
29
|
}, [appKit]);
|
|
30
30
|
|
|
31
|
-
return useSyncExternalStore(subscribe, getSnapshot,
|
|
31
|
+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
32
32
|
};
|
|
@@ -26,5 +26,5 @@ export const useConnectorById = (id: string): Connector | undefined => {
|
|
|
26
26
|
return getConnectorById(appKit, { id });
|
|
27
27
|
}, [appKit, id]);
|
|
28
28
|
|
|
29
|
-
return useSyncExternalStore(subscribe, getSnapshot,
|
|
29
|
+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
30
30
|
};
|