@sodax/dapp-kit 0.0.1-rc.7 → 0.0.1-rc.8

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.
@@ -1,33 +0,0 @@
1
- import { useQuery } from '@tanstack/react-query';
2
- import type { SpokeChainId, XToken } from '@sodax/types';
3
- import { useSodaxContext } from '../shared/useSodaxContext';
4
- import { useSpokeProvider } from '../provider/useSpokeProvider';
5
- import { parseUnits } from 'viem';
6
- import type { MoneyMarketAction } from '@sodax/sdk';
7
-
8
- export function useAllowance(token: XToken, amount: string, action: MoneyMarketAction) {
9
- const { sodax } = useSodaxContext();
10
- const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);
11
-
12
- return useQuery({
13
- queryKey: ['allowance', token.address, amount, action],
14
- queryFn: async () => {
15
- if (!spokeProvider) {
16
- return false;
17
- }
18
- const allowance = await sodax.moneyMarket.isAllowanceValid(
19
- {
20
- token: token.address,
21
- amount: parseUnits(amount, token.decimals),
22
- action,
23
- },
24
- spokeProvider,
25
- );
26
- if (allowance.ok) {
27
- return allowance.value;
28
- }
29
- return false;
30
- },
31
- enabled: !!spokeProvider,
32
- });
33
- }