@sodax/dapp-kit 2.2.0-rc.1 → 2.2.0-rc.2
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 +2 -0
- package/dist/index.d.ts +96 -3
- package/dist/index.mjs +98 -39
- package/package.json +3 -3
- package/src/hooks/_apiKeyWire.test.ts +1 -1
- package/src/hooks/_mutationContract.test.ts +6 -0
- package/src/hooks/backend/index.ts +4 -0
- package/src/hooks/backend/useBackendOracleCandles.ts +47 -0
- package/src/hooks/backend/useBackendOracleMarkets.ts +30 -0
- package/src/hooks/bitcoin/useFundTradingWallet.ts +2 -1
- package/src/hooks/bitcoin/useRadfiWithdraw.ts +2 -1
- package/src/hooks/bridge/useBridge.ts +2 -2
- package/src/hooks/dex/useDexDeposit.ts +2 -1
- package/src/hooks/dex/useDexWithdraw.ts +2 -1
- package/src/hooks/dex/useSupplyLiquidity.ts +2 -1
- package/src/hooks/leverageYield/useLeverageYieldVaultSwap.ts +2 -2
- package/src/hooks/migrate/useMigrateBaln.ts +2 -2
- package/src/hooks/migrate/useMigrateIcxToSoda.ts +2 -2
- package/src/hooks/migrate/useMigratebnUSD.ts +2 -2
- package/src/hooks/migrate/useRevertMigrateSodaToIcx.ts +2 -2
- package/src/hooks/mm/useBorrow.ts +2 -4
- package/src/hooks/mm/useRepay.ts +2 -1
- package/src/hooks/mm/useSupply.ts +2 -1
- package/src/hooks/mm/useWithdraw.ts +2 -4
- package/src/hooks/partner/useFeeClaimWithdraw.ts +2 -1
- package/src/hooks/recovery/useWithdrawHubAsset.ts +2 -1
- package/src/hooks/shared/index.ts +2 -0
- package/src/hooks/shared/invalidateBalances.test.ts +71 -0
- package/src/hooks/shared/invalidateBalances.ts +25 -0
- package/src/hooks/shared/useBalances.test.ts +118 -0
- package/src/hooks/shared/useBalances.ts +81 -0
- package/src/hooks/shared/useEstablishTrustline.test.ts +2 -0
- package/src/hooks/shared/useEstablishTrustline.ts +2 -1
- package/src/hooks/shared/useStellarGate.test.ts +1 -1
- package/src/hooks/sponsoring/useActivateStellarAccount.test.ts +6 -4
- package/src/hooks/sponsoring/useActivateStellarAccount.ts +2 -1
- package/src/hooks/sponsoring/useSponsorConfig.test.ts +8 -2
- package/src/hooks/sponsoring/useStellarAccountActive.test.ts +2 -2
- package/src/hooks/sponsoring/useStellarAccountStatus.test.ts +8 -2
- package/src/hooks/staking/useClaim.ts +2 -1
- package/src/hooks/staking/useInstantUnstake.ts +2 -1
- package/src/hooks/staking/useStake.ts +2 -1
- package/src/hooks/swap/useDetailedStatus.test.ts +2 -2
- package/src/hooks/swap/useSwap.ts +2 -2
- package/src/providers/SodaxProvider.test.ts +1 -1
|
@@ -47,6 +47,7 @@ describe('useEstablishTrustline — invalidation after a broadcast trustline', (
|
|
|
47
47
|
expect(invalidatedKeys()).toEqual([
|
|
48
48
|
['shared', 'stellarTrustlineCheck', ChainKeys.STELLAR_MAINNET, TOKEN, ADDRESS],
|
|
49
49
|
['sponsoring', 'stellarAccountStatus', ADDRESS],
|
|
50
|
+
['shared', 'balances', ChainKeys.STELLAR_MAINNET],
|
|
50
51
|
['shared', 'xBalances', ChainKeys.STELLAR_MAINNET],
|
|
51
52
|
]);
|
|
52
53
|
});
|
|
@@ -64,6 +65,7 @@ describe('useEstablishTrustline — invalidation after a broadcast trustline', (
|
|
|
64
65
|
expect(invalidatedKeys()).toEqual([
|
|
65
66
|
['shared', 'stellarTrustlineCheck'],
|
|
66
67
|
['sponsoring', 'stellarAccountStatus'],
|
|
68
|
+
['shared', 'balances', ChainKeys.STELLAR_MAINNET],
|
|
67
69
|
['shared', 'xBalances', ChainKeys.STELLAR_MAINNET],
|
|
68
70
|
]);
|
|
69
71
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IStellarWalletProvider, StellarChainKey } from '@sodax/sdk';
|
|
2
2
|
import { ChainKeys } from '@sodax/sdk';
|
|
3
3
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { invalidateBalances } from './invalidateBalances.js';
|
|
4
5
|
import type { MutationHookParams } from './types.js';
|
|
5
6
|
import { useSafeMutation, type SafeUseMutationResult } from './useSafeMutation.js';
|
|
6
7
|
import { useSodaxContext } from './useSodaxContext.js';
|
|
@@ -65,7 +66,7 @@ export function useEstablishTrustline({
|
|
|
65
66
|
? ['sponsoring', 'stellarAccountStatus', srcAddress]
|
|
66
67
|
: ['sponsoring', 'stellarAccountStatus'],
|
|
67
68
|
});
|
|
68
|
-
queryClient
|
|
69
|
+
invalidateBalances(queryClient, ChainKeys.STELLAR_MAINNET);
|
|
69
70
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
70
71
|
},
|
|
71
72
|
});
|
|
@@ -89,7 +89,7 @@ describe('useStellarGate — the trustline read is gated on account existence',
|
|
|
89
89
|
it('does not read a Stellar trustline for a non-Stellar destination', () => {
|
|
90
90
|
const { gate, trustlineAddress } = run(
|
|
91
91
|
{ data: { exists: true, canAffordTrustline: true } },
|
|
92
|
-
{ dstChainKey: ChainKeys.
|
|
92
|
+
{ dstChainKey: ChainKeys.SONIC_MAINNET },
|
|
93
93
|
);
|
|
94
94
|
|
|
95
95
|
expect(trustlineAddress).toBeUndefined();
|
|
@@ -23,8 +23,8 @@ function invalidatedKeyPrefixes(): string[][] {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
describe('useActivateStellarAccount — cache invalidation', () => {
|
|
26
|
-
it('
|
|
27
|
-
expect(invalidatedKeyPrefixes()).toHaveLength(
|
|
26
|
+
it('hand-rolls exactly three query invalidations on success, the fourth routed through invalidateBalances', () => {
|
|
27
|
+
expect(invalidatedKeyPrefixes()).toHaveLength(3);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
it("invalidates the account-active query using that query's own key prefix", () => {
|
|
@@ -63,8 +63,10 @@ describe('useActivateStellarAccount — cache invalidation', () => {
|
|
|
63
63
|
expect(invalidatedKeyPrefixes()).toContainEqual(['shared', 'stellarTrustlineCheck']);
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
it('invalidates the
|
|
67
|
-
|
|
66
|
+
it('invalidates Stellar balances through the shared invalidateBalances helper', () => {
|
|
67
|
+
// Routed through invalidateBalances (covers both useBalances and useXBalances) rather than a
|
|
68
|
+
// hand-rolled invalidateQueries call, so it is not one of the literal matches above.
|
|
69
|
+
expect(SRC).toMatch(/invalidateBalances\(queryClient,\s*ChainKeys\.STELLAR_MAINNET\)/);
|
|
68
70
|
});
|
|
69
71
|
|
|
70
72
|
it('passes the whole mutation vars through to the SDK', () => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ChainKeys, type ActivateStellarAccountParams, type ActivateStellarAccountResult } from '@sodax/sdk';
|
|
2
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
3
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { invalidateBalances } from '../shared/invalidateBalances.js';
|
|
4
5
|
import type { MutationHookParams } from '../shared/types.js';
|
|
5
6
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
7
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
@@ -31,7 +32,7 @@ export function useActivateStellarAccount({
|
|
|
31
32
|
queryClient.invalidateQueries({ queryKey: ['sponsoring', 'stellarAccountStatus', vars.address] });
|
|
32
33
|
// Clear trustline errors cached while the account did not exist.
|
|
33
34
|
queryClient.invalidateQueries({ queryKey: ['shared', 'stellarTrustlineCheck'] });
|
|
34
|
-
queryClient
|
|
35
|
+
invalidateBalances(queryClient, ChainKeys.STELLAR_MAINNET);
|
|
35
36
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
36
37
|
},
|
|
37
38
|
});
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
SodaxError,
|
|
3
|
+
SPONSOR_CONFIG_TTL_MS,
|
|
4
|
+
type Result,
|
|
5
|
+
type SponsoringConfigError,
|
|
6
|
+
type StellarSponsorConfig,
|
|
7
|
+
} from '@sodax/sdk';
|
|
2
8
|
import { describe, expect, it, vi } from 'vitest';
|
|
3
9
|
import { getSponsorConfigQueryOptions } from './useSponsorConfig.js';
|
|
4
10
|
|
|
@@ -15,7 +21,7 @@ const CONFIG: StellarSponsorConfig = {
|
|
|
15
21
|
requiredStartingBalance: '0',
|
|
16
22
|
};
|
|
17
23
|
|
|
18
|
-
const makeSodax = (result:
|
|
24
|
+
const makeSodax = (result: Result<StellarSponsorConfig, SponsoringConfigError>) => {
|
|
19
25
|
const getStellarSponsorConfig = vi.fn(async () => result);
|
|
20
26
|
return { sodax: { sponsoring: { getStellarSponsorConfig } }, getStellarSponsorConfig };
|
|
21
27
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { SodaxError } from '@sodax/sdk';
|
|
1
|
+
import { SodaxError, type Result, type SponsoringLookupError } from '@sodax/sdk';
|
|
2
2
|
import { describe, expect, it, vi } from 'vitest';
|
|
3
3
|
import { getStellarAccountActiveQueryOptions } from './useStellarAccountActive.js';
|
|
4
4
|
|
|
5
5
|
const ADDRESS = 'GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
|
|
6
6
|
const OTHER = 'GBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB';
|
|
7
7
|
|
|
8
|
-
const makeSodax = (result:
|
|
8
|
+
const makeSodax = (result: Result<boolean, SponsoringLookupError>) => {
|
|
9
9
|
const isStellarAccountActive = vi.fn(async () => result);
|
|
10
10
|
return { sodax: { sponsoring: { isStellarAccountActive } }, isStellarAccountActive };
|
|
11
11
|
};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
SodaxError,
|
|
3
|
+
STELLAR_TRUSTLINE_MIN_XLM_STROOPS,
|
|
4
|
+
type Result,
|
|
5
|
+
type SponsoringLookupError,
|
|
6
|
+
type StellarAccountStatus,
|
|
7
|
+
} from '@sodax/sdk';
|
|
2
8
|
import { describe, expect, it, vi } from 'vitest';
|
|
3
9
|
import { getStellarAccountStatusQueryOptions } from './useStellarAccountStatus.js';
|
|
4
10
|
|
|
@@ -13,7 +19,7 @@ const FUNDED: StellarAccountStatus = {
|
|
|
13
19
|
trustlineMinXlmStroops: STELLAR_TRUSTLINE_MIN_XLM_STROOPS,
|
|
14
20
|
};
|
|
15
21
|
|
|
16
|
-
const makeSodax = (result:
|
|
22
|
+
const makeSodax = (result: Result<StellarAccountStatus, SponsoringLookupError>) => {
|
|
17
23
|
const getStellarAccountStatus = vi.fn(async () => result);
|
|
18
24
|
return { sodax: { sponsoring: { getStellarAccountStatus } }, getStellarAccountStatus };
|
|
19
25
|
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { ClaimAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
3
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
4
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
5
|
+
import { invalidateBalances } from '../shared/invalidateBalances.js';
|
|
5
6
|
import type { MutationHookParams } from '../shared/types.js';
|
|
6
7
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
8
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
@@ -30,7 +31,7 @@ export function useClaim<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
30
31
|
queryClient.invalidateQueries({
|
|
31
32
|
queryKey: ['staking', 'unstakingInfoWithPenalty', params.srcChainKey, params.srcAddress],
|
|
32
33
|
});
|
|
33
|
-
queryClient
|
|
34
|
+
invalidateBalances(queryClient, params.srcChainKey);
|
|
34
35
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
35
36
|
},
|
|
36
37
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { InstantUnstakeAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
3
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
4
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
5
|
+
import { invalidateBalances } from '../shared/invalidateBalances.js';
|
|
5
6
|
import type { MutationHookParams } from '../shared/types.js';
|
|
6
7
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
8
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
@@ -36,7 +37,7 @@ export function useInstantUnstake<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
36
37
|
queryClient.invalidateQueries({ queryKey: ['staking', 'info', params.srcChainKey, params.srcAddress] });
|
|
37
38
|
queryClient.invalidateQueries({ queryKey: ['staking', 'instantUnstakeRatio'] });
|
|
38
39
|
queryClient.invalidateQueries({ queryKey: ['staking', 'allowance', params.srcChainKey, 'instantUnstake'] });
|
|
39
|
-
queryClient
|
|
40
|
+
invalidateBalances(queryClient, params.srcChainKey);
|
|
40
41
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
41
42
|
},
|
|
42
43
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { SpokeChainKey, StakeAction, TxHashPair } from '@sodax/sdk';
|
|
3
3
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
4
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
5
|
+
import { invalidateBalances } from '../shared/invalidateBalances.js';
|
|
5
6
|
import type { MutationHookParams } from '../shared/types.js';
|
|
6
7
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
8
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
@@ -35,7 +36,7 @@ export function useStake<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
35
36
|
queryClient.invalidateQueries({ queryKey: ['staking', 'allowance', params.srcChainKey, 'stake'] });
|
|
36
37
|
queryClient.invalidateQueries({ queryKey: ['staking', 'stakeRatio'] });
|
|
37
38
|
queryClient.invalidateQueries({ queryKey: ['staking', 'convertedAssets'] });
|
|
38
|
-
queryClient
|
|
39
|
+
invalidateBalances(queryClient, params.srcChainKey);
|
|
39
40
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
40
41
|
},
|
|
41
42
|
});
|
|
@@ -63,7 +63,7 @@ describe('getDetailedStatusRefetchInterval', () => {
|
|
|
63
63
|
// Both terminal states of the `SubmitSwapTxStatusV2` wire contract. `'failed'` is unreachable via
|
|
64
64
|
// `getDetailedStatus` today (the SDK routes abandoned records to the solver) — asserted here as
|
|
65
65
|
// the hook's own contract, so a terminal record is never polled forever if that routing changes.
|
|
66
|
-
it.each(['solved', 'failed'])('stops on a backend record at the terminal status %s', status => {
|
|
66
|
+
it.each(['solved', 'failed'] as const)('stops on a backend record at the terminal status %s', status => {
|
|
67
67
|
expect(getDetailedStatusRefetchInterval(ok(backend(status)), 0)).toBe(false);
|
|
68
68
|
});
|
|
69
69
|
|
|
@@ -73,7 +73,7 @@ describe('getDetailedStatusRefetchInterval', () => {
|
|
|
73
73
|
'relayed',
|
|
74
74
|
'posting_execution',
|
|
75
75
|
'posted_execution',
|
|
76
|
-
])('keeps polling a backend record at %s', status => {
|
|
76
|
+
] as const)('keeps polling a backend record at %s', status => {
|
|
77
77
|
expect(getDetailedStatusRefetchInterval(ok(backend(status)), 0)).toBe(STATUS_POLL_MS);
|
|
78
78
|
});
|
|
79
79
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// packages/dapp-kit/src/hooks/swap/useSwap.ts
|
|
2
2
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
3
|
+
import { invalidateBalances } from '../shared/invalidateBalances.js';
|
|
3
4
|
import type { SpokeChainKey, SwapActionParams, SwapResponse } from '@sodax/sdk';
|
|
4
5
|
import { useQueryClient } from '@tanstack/react-query';
|
|
5
6
|
import type { MutationHookParams } from '../shared/types.js';
|
|
@@ -30,8 +31,7 @@ export function useSwap<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
30
31
|
...mutationOptions,
|
|
31
32
|
mutationFn: async vars => unwrapResult(await sodax.swaps.swap({ ...vars, raw: false })),
|
|
32
33
|
onSuccess: async (data, vars, ctx) => {
|
|
33
|
-
queryClient
|
|
34
|
-
queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', vars.params.dstChainKey] });
|
|
34
|
+
invalidateBalances(queryClient, vars.params.srcChainKey, vars.params.dstChainKey);
|
|
35
35
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
36
36
|
},
|
|
37
37
|
});
|
|
@@ -19,7 +19,7 @@ vi.mock('react', async importOriginal => ({
|
|
|
19
19
|
|
|
20
20
|
const { SodaxProvider } = await import('./SodaxProvider.js');
|
|
21
21
|
|
|
22
|
-
const fetchMock = vi.fn(
|
|
22
|
+
const fetchMock = vi.fn<typeof globalThis.fetch>(
|
|
23
23
|
async () => new Response('{}', { status: 200, headers: { 'content-type': 'application/json' } }),
|
|
24
24
|
);
|
|
25
25
|
vi.stubGlobal('fetch', fetchMock);
|