@sodax/dapp-kit 2.0.0-rc.9 → 2.1.0-rc.1
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 +141 -119
- package/dist/index.d.ts +939 -63
- package/dist/index.mjs +1086 -180
- package/package.json +3 -3
- package/src/hooks/_mutationContract.test.ts +17 -2
- package/src/hooks/backend/index.ts +1 -5
- package/src/hooks/backend/types.ts +1 -1
- package/src/hooks/bitcoin/index.ts +2 -0
- package/src/hooks/bitcoin/resolveBtcReadAddress.test.ts +54 -0
- package/src/hooks/bitcoin/resolveBtcReadAddress.ts +21 -0
- package/src/hooks/bitcoin/useBitcoinTradingSetup.ts +45 -0
- package/src/hooks/bitcoin/useEnsureRadfiAccessToken.ts +57 -0
- package/src/hooks/bitcoin/useFundTradingWallet.ts +1 -1
- package/src/hooks/bitcoin/useRadfiAuth.ts +2 -2
- package/src/hooks/bitcoin/useRadfiWithdraw.ts +2 -2
- package/src/hooks/bitcoin/useRenewUtxos.ts +2 -2
- package/src/hooks/bitcoin/useTradingWallet.ts +1 -1
- package/src/hooks/bridge/useBridgeApprove.ts +2 -1
- package/src/hooks/index.ts +3 -0
- package/src/hooks/leverageYield/index.ts +9 -0
- package/src/hooks/leverageYield/useLeverageYieldDeposit.ts +40 -0
- package/src/hooks/leverageYield/useLeverageYieldEffectiveApr.ts +42 -0
- package/src/hooks/leverageYield/useLeverageYieldNotifySolver.ts +34 -0
- package/src/hooks/leverageYield/useLeverageYieldPosition.ts +40 -0
- package/src/hooks/leverageYield/useLeverageYieldPreviewRedeem.ts +43 -0
- package/src/hooks/leverageYield/useLeverageYieldShareBalances.ts +74 -0
- package/src/hooks/leverageYield/useLeverageYieldTotalAssets.ts +36 -0
- package/src/hooks/leverageYield/useLeverageYieldVaultSwap.ts +50 -0
- package/src/hooks/leverageYield/useLeverageYieldWithdraw.ts +40 -0
- package/src/hooks/migrate/useMigrationApprove.ts +1 -3
- package/src/hooks/mm/useATokensBalances.ts +7 -1
- package/src/hooks/mm/useUserFormattedSummary.ts +5 -1
- package/src/hooks/mm/useUserReservesData.ts +5 -1
- package/src/hooks/mm/useWithdraw.ts +5 -1
- package/src/hooks/partner/index.ts +4 -0
- package/src/hooks/partner/useApproveToken.ts +1 -2
- package/src/hooks/partner/useFeeClaimWithdraw.ts +88 -0
- package/src/hooks/partner/useGetIntentDetails.ts +39 -0
- package/src/hooks/partner/useGetUserIntent.ts +35 -0
- package/src/hooks/partner/usePartnerCancelIntent.ts +52 -0
- package/src/hooks/shared/index.ts +6 -0
- package/src/hooks/shared/isUserRejectedError.test.ts +42 -0
- package/src/hooks/shared/isUserRejectedError.ts +30 -0
- package/src/hooks/shared/useEstablishTrustline.test.ts +89 -0
- package/src/hooks/shared/useEstablishTrustline.ts +72 -0
- package/src/hooks/shared/useGetUserHubWalletAddress.ts +5 -1
- package/src/hooks/shared/useNearStorageCheck.ts +45 -0
- package/src/hooks/shared/useNearStorageGate.ts +60 -0
- package/src/hooks/shared/useRegisterNearStorage.ts +46 -0
- package/src/hooks/shared/useRequestTrustline.test.ts +115 -0
- package/src/hooks/shared/useRequestTrustline.ts +41 -56
- package/src/hooks/shared/useSafeMutation.ts +1 -4
- package/src/hooks/shared/useStellarGate.test.ts +99 -0
- package/src/hooks/shared/useStellarGate.ts +102 -0
- package/src/hooks/shared/useStellarTrustlineCheck.test.ts +74 -0
- package/src/hooks/shared/useStellarTrustlineCheck.ts +39 -15
- package/src/hooks/sponsoring/index.ts +4 -0
- package/src/hooks/sponsoring/useActivateStellarAccount.test.ts +74 -0
- package/src/hooks/sponsoring/useActivateStellarAccount.ts +38 -0
- package/src/hooks/sponsoring/useSponsorConfig.test.ts +46 -0
- package/src/hooks/sponsoring/useSponsorConfig.ts +31 -0
- package/src/hooks/sponsoring/useStellarAccountActive.test.ts +50 -0
- package/src/hooks/sponsoring/useStellarAccountActive.ts +45 -0
- package/src/hooks/sponsoring/useStellarAccountStatus.test.ts +90 -0
- package/src/hooks/sponsoring/useStellarAccountStatus.ts +57 -0
- package/src/hooks/staking/useStakingConfig.ts +1 -3
- package/src/hooks/staking/useStakingInfo.ts +4 -4
- package/src/hooks/staking/useUnstake.ts +5 -1
- package/src/hooks/swap/useCreateLimitOrder.ts +1 -2
- package/src/hooks/swap/useSwap.ts +1 -5
- package/src/hooks/swapsApi/index.ts +41 -0
- package/src/hooks/swapsApi/isTerminalSwapIntentStatus.test.ts +24 -0
- package/src/hooks/swapsApi/isTerminalSwapIntentStatus.ts +11 -0
- package/src/hooks/swapsApi/useSwapsApiAllowance.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiApprove.ts +42 -0
- package/src/hooks/swapsApi/useSwapsApiCancelIntent.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiCreateIntent.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiDeadline.ts +36 -0
- package/src/hooks/swapsApi/useSwapsApiEstimateGas.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiFilledIntent.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiIntent.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiIntentExtraData.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiIntentHash.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiIntentPacket.ts +43 -0
- package/src/hooks/swapsApi/useSwapsApiPartnerFee.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiQuote.ts +55 -0
- package/src/hooks/swapsApi/useSwapsApiSolverFee.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiStatus.ts +45 -0
- package/src/hooks/swapsApi/useSwapsApiSubmitIntent.ts +43 -0
- package/src/hooks/{backend/useBackendSubmitSwapTx.ts → swapsApi/useSwapsApiSubmitTx.ts} +16 -17
- package/src/hooks/swapsApi/useSwapsApiSubmitTxStatus.ts +55 -0
- package/src/hooks/swapsApi/useSwapsApiTokens.ts +34 -0
- package/src/hooks/swapsApi/useSwapsApiTokensByChain.ts +40 -0
- package/src/index.ts +1 -1
- package/src/providers/SodaxProvider.tsx +2 -3
- package/src/providers/createSodaxQueryClient.ts +1 -5
- package/src/utils/dex-utils.ts +1 -4
- package/src/utils/index.ts +2 -0
- package/src/utils/nearStorageGate.test.ts +46 -0
- package/src/utils/nearStorageGate.ts +39 -0
- package/src/utils/stellarGate.test.ts +196 -0
- package/src/utils/stellarGate.ts +84 -0
- package/src/hooks/backend/useBackendSubmitSwapTxStatus.ts +0 -59
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { ChainKeys, type StellarAccountStatus } from '@sodax/sdk';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { resolveStellarGate, type StellarCheckResult } from './stellarGate.js';
|
|
4
|
+
|
|
5
|
+
const STELLAR = ChainKeys.STELLAR_MAINNET;
|
|
6
|
+
|
|
7
|
+
const resolved = <T>(data: T): StellarCheckResult<T> => ({ isLoading: false, isError: false, data });
|
|
8
|
+
const loading = <T>(): StellarCheckResult<T> => ({ isLoading: true, isError: false, data: undefined });
|
|
9
|
+
const errored = <T>(): StellarCheckResult<T> => ({ isLoading: false, isError: true, data: undefined });
|
|
10
|
+
const idle = <T>(): StellarCheckResult<T> => ({ isLoading: false, isError: false, data: undefined });
|
|
11
|
+
|
|
12
|
+
const status = (overrides: Partial<StellarAccountStatus> = {}): StellarAccountStatus => ({
|
|
13
|
+
exists: true,
|
|
14
|
+
nativeBalanceStroops: 10_000_000n,
|
|
15
|
+
availableBalanceStroops: 10_000_000n,
|
|
16
|
+
canAffordTrustline: true,
|
|
17
|
+
trustlineMinXlmStroops: 5_100_000n,
|
|
18
|
+
...overrides,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const gate = (
|
|
22
|
+
chainKey: typeof STELLAR | undefined,
|
|
23
|
+
inputs: {
|
|
24
|
+
statusCheck?: StellarCheckResult<StellarAccountStatus>;
|
|
25
|
+
trustlineCheck?: StellarCheckResult<boolean>;
|
|
26
|
+
isNativeToken?: boolean;
|
|
27
|
+
} = {},
|
|
28
|
+
) =>
|
|
29
|
+
resolveStellarGate(chainKey, {
|
|
30
|
+
statusCheck: inputs.statusCheck ?? resolved(status()),
|
|
31
|
+
trustlineCheck: inputs.trustlineCheck ?? resolved(true),
|
|
32
|
+
isNativeToken: inputs.isNativeToken ?? false,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('resolveStellarGate — non-Stellar destinations', () => {
|
|
36
|
+
it.each([[ChainKeys.SONIC_MAINNET], [undefined]])('is inert for %s', chainKey => {
|
|
37
|
+
expect(gate(chainKey as undefined, { statusCheck: idle(), trustlineCheck: idle() })).toEqual({
|
|
38
|
+
isStellar: false,
|
|
39
|
+
needsActivation: false,
|
|
40
|
+
needsFunding: false,
|
|
41
|
+
needsTrustline: false,
|
|
42
|
+
checkFailed: false,
|
|
43
|
+
blocksAction: false,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('does not report a failed check for a non-Stellar destination', () => {
|
|
48
|
+
const result = gate(undefined, { statusCheck: errored(), trustlineCheck: errored() });
|
|
49
|
+
expect(result.checkFailed).toBe(false);
|
|
50
|
+
expect(result.blocksAction).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('resolveStellarGate — unknown account state blocks without accusing', () => {
|
|
55
|
+
it.each([
|
|
56
|
+
['loading', loading<StellarAccountStatus>()],
|
|
57
|
+
['errored', errored<StellarAccountStatus>()],
|
|
58
|
+
['idle/disabled', idle<StellarAccountStatus>()],
|
|
59
|
+
])('blocks but does NOT claim needsActivation when the status check is %s', (_label, statusCheck) => {
|
|
60
|
+
// Unknown account state must not be classified as a missing prerequisite.
|
|
61
|
+
const result = gate(STELLAR, { statusCheck });
|
|
62
|
+
expect(result.blocksAction).toBe(true);
|
|
63
|
+
expect(result.needsActivation).toBe(false);
|
|
64
|
+
expect(result.needsFunding).toBe(false);
|
|
65
|
+
expect(result.needsTrustline).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('a disabled trustline query cannot block forever once the account is funded', () => {
|
|
69
|
+
// Disabled React Query checks are idle, not loading.
|
|
70
|
+
expect(gate(STELLAR, { trustlineCheck: idle() }).blocksAction).toBe(true);
|
|
71
|
+
expect(gate(STELLAR, { trustlineCheck: resolved(true) }).blocksAction).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it.each([
|
|
75
|
+
['the status read', { statusCheck: errored<StellarAccountStatus>() }],
|
|
76
|
+
['the trustline read', { trustlineCheck: errored<boolean>() }],
|
|
77
|
+
])('reports checkFailed when %s errors, so the UI can offer a retry', (_label, inputs) => {
|
|
78
|
+
const result = gate(STELLAR, inputs);
|
|
79
|
+
expect(result.checkFailed).toBe(true);
|
|
80
|
+
expect(result.blocksAction).toBe(true);
|
|
81
|
+
expect(result.needsActivation).toBe(false);
|
|
82
|
+
expect(result.needsFunding).toBe(false);
|
|
83
|
+
expect(result.needsTrustline).toBe(false);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it.each([
|
|
87
|
+
['loading', { statusCheck: loading<StellarAccountStatus>() }],
|
|
88
|
+
['idle/disabled', { statusCheck: idle<StellarAccountStatus>() }],
|
|
89
|
+
['an idle trustline read', { trustlineCheck: idle<boolean>() }],
|
|
90
|
+
])('does NOT report checkFailed for %s — nothing failed', (_label, inputs) => {
|
|
91
|
+
const result = gate(STELLAR, inputs);
|
|
92
|
+
expect(result.checkFailed).toBe(false);
|
|
93
|
+
expect(result.blocksAction).toBe(true);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('resolveStellarGate — stage ordering', () => {
|
|
98
|
+
it('reports activation first for a non-existent account, and nothing downstream', () => {
|
|
99
|
+
const result = gate(STELLAR, {
|
|
100
|
+
statusCheck: resolved(status({ exists: false, nativeBalanceStroops: 0n, canAffordTrustline: false })),
|
|
101
|
+
trustlineCheck: resolved(false),
|
|
102
|
+
});
|
|
103
|
+
expect(result).toEqual({
|
|
104
|
+
isStellar: true,
|
|
105
|
+
needsActivation: true,
|
|
106
|
+
needsFunding: false,
|
|
107
|
+
needsTrustline: false,
|
|
108
|
+
checkFailed: false,
|
|
109
|
+
blocksAction: true,
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('does NOT ask a broke account to fund itself when it ALREADY holds the trustline', () => {
|
|
114
|
+
// Receiving through an existing trustline requires no recipient reserve or fee.
|
|
115
|
+
const result = gate(STELLAR, {
|
|
116
|
+
statusCheck: resolved(
|
|
117
|
+
status({ nativeBalanceStroops: 0n, availableBalanceStroops: 0n, canAffordTrustline: false }),
|
|
118
|
+
),
|
|
119
|
+
trustlineCheck: resolved(true),
|
|
120
|
+
});
|
|
121
|
+
expect(result.needsFunding).toBe(false);
|
|
122
|
+
expect(result.needsTrustline).toBe(false);
|
|
123
|
+
expect(result.blocksAction).toBe(false);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('reports funding for a freshly activated 0-XLM account, NOT a trustline', () => {
|
|
127
|
+
const result = gate(STELLAR, {
|
|
128
|
+
statusCheck: resolved(status({ nativeBalanceStroops: 0n, canAffordTrustline: false })),
|
|
129
|
+
trustlineCheck: resolved(false),
|
|
130
|
+
});
|
|
131
|
+
expect(result.needsFunding).toBe(true);
|
|
132
|
+
expect(result.needsTrustline).toBe(false);
|
|
133
|
+
expect(result.blocksAction).toBe(true);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('reports a trustline only once the account exists and can pay for one', () => {
|
|
137
|
+
const result = gate(STELLAR, { trustlineCheck: resolved(false) });
|
|
138
|
+
expect(result).toEqual({
|
|
139
|
+
isStellar: true,
|
|
140
|
+
needsActivation: false,
|
|
141
|
+
needsFunding: false,
|
|
142
|
+
needsTrustline: true,
|
|
143
|
+
checkFailed: false,
|
|
144
|
+
blocksAction: true,
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('clears once every prerequisite is met', () => {
|
|
149
|
+
expect(gate(STELLAR, { trustlineCheck: resolved(true) })).toEqual({
|
|
150
|
+
isStellar: true,
|
|
151
|
+
needsActivation: false,
|
|
152
|
+
needsFunding: false,
|
|
153
|
+
needsTrustline: false,
|
|
154
|
+
checkFailed: false,
|
|
155
|
+
blocksAction: false,
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('never reports two stages at once', () => {
|
|
160
|
+
const cases = [
|
|
161
|
+
gate(STELLAR, { statusCheck: resolved(status({ exists: false, canAffordTrustline: false })) }),
|
|
162
|
+
gate(STELLAR, {
|
|
163
|
+
statusCheck: resolved(status({ canAffordTrustline: false })),
|
|
164
|
+
trustlineCheck: resolved(false),
|
|
165
|
+
}),
|
|
166
|
+
gate(STELLAR, { trustlineCheck: resolved(false) }),
|
|
167
|
+
];
|
|
168
|
+
for (const result of cases) {
|
|
169
|
+
const active = [result.needsActivation, result.needsFunding, result.needsTrustline].filter(Boolean);
|
|
170
|
+
expect(active).toHaveLength(1);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe('resolveStellarGate — native XLM skips funding and trustline', () => {
|
|
176
|
+
it('does not gate an activated 0-XLM account on funding when receiving native XLM', () => {
|
|
177
|
+
// Native XLM needs no trustline or recipient fee, so funding cannot gate receipt.
|
|
178
|
+
const result = gate(STELLAR, {
|
|
179
|
+
statusCheck: resolved(status({ nativeBalanceStroops: 0n, canAffordTrustline: false })),
|
|
180
|
+
trustlineCheck: resolved(false),
|
|
181
|
+
isNativeToken: true,
|
|
182
|
+
});
|
|
183
|
+
expect(result.needsFunding).toBe(false);
|
|
184
|
+
expect(result.needsTrustline).toBe(false);
|
|
185
|
+
expect(result.blocksAction).toBe(false);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('still requires the account to EXIST before it can receive native XLM', () => {
|
|
189
|
+
const result = gate(STELLAR, {
|
|
190
|
+
statusCheck: resolved(status({ exists: false, canAffordTrustline: false })),
|
|
191
|
+
isNativeToken: true,
|
|
192
|
+
});
|
|
193
|
+
expect(result.needsActivation).toBe(true);
|
|
194
|
+
expect(result.blocksAction).toBe(true);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ChainKeys, type SpokeChainKey, type StellarAccountStatus } from '@sodax/sdk';
|
|
2
|
+
import type { UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The subset of a query result the gate reads. A full `UseQueryResult<T>` satisfies it.
|
|
6
|
+
*
|
|
7
|
+
* `isLoading` is intentional: `isPending` remains true for disabled queries.
|
|
8
|
+
* Errors remain distinct from unmet prerequisites.
|
|
9
|
+
*/
|
|
10
|
+
export type StellarCheckResult<T> = Pick<UseQueryResult<T>, 'isLoading' | 'isError' | 'data'>;
|
|
11
|
+
|
|
12
|
+
export interface StellarGateState {
|
|
13
|
+
isStellar: boolean;
|
|
14
|
+
needsActivation: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The account needs a trustline but lacks spendable XLM. Never set for
|
|
17
|
+
* native XLM or an existing trustline.
|
|
18
|
+
*/
|
|
19
|
+
needsFunding: boolean;
|
|
20
|
+
needsTrustline: boolean;
|
|
21
|
+
/** A query failed; disabled or unresolved queries do not set this. */
|
|
22
|
+
checkFailed: boolean;
|
|
23
|
+
/** Whether the downstream action must remain disabled. */
|
|
24
|
+
blocksAction: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface StellarGateInputs {
|
|
28
|
+
/** Account existence and spending capacity from one Horizon read. */
|
|
29
|
+
statusCheck: StellarCheckResult<StellarAccountStatus>;
|
|
30
|
+
trustlineCheck: StellarCheckResult<boolean>;
|
|
31
|
+
/** Resolve from chain config, never by comparing token symbols. */
|
|
32
|
+
isNativeToken: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function unresolved<T>(check: StellarCheckResult<T>): boolean {
|
|
36
|
+
return check.isLoading || check.data === undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const NOT_STELLAR: StellarGateState = {
|
|
40
|
+
isStellar: false,
|
|
41
|
+
needsActivation: false,
|
|
42
|
+
needsFunding: false,
|
|
43
|
+
needsTrustline: false,
|
|
44
|
+
checkFailed: false,
|
|
45
|
+
blocksAction: false,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Resolve activation, trustline, and funding prerequisites in order.
|
|
50
|
+
*
|
|
51
|
+
* Check the trustline before affordability because an existing trustline needs
|
|
52
|
+
* no additional XLM. Unknown states fail closed.
|
|
53
|
+
*/
|
|
54
|
+
export function resolveStellarGate(chainKey: SpokeChainKey | undefined, inputs: StellarGateInputs): StellarGateState {
|
|
55
|
+
const { statusCheck, trustlineCheck, isNativeToken } = inputs;
|
|
56
|
+
|
|
57
|
+
if (chainKey !== ChainKeys.STELLAR_MAINNET) return NOT_STELLAR;
|
|
58
|
+
const base = {
|
|
59
|
+
isStellar: true,
|
|
60
|
+
needsActivation: false,
|
|
61
|
+
needsFunding: false,
|
|
62
|
+
needsTrustline: false,
|
|
63
|
+
checkFailed: false,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// A failed read is unknown, not evidence that activation is needed.
|
|
67
|
+
if (statusCheck.isError) return { ...base, checkFailed: true, blocksAction: true };
|
|
68
|
+
const status = statusCheck.data;
|
|
69
|
+
if (statusCheck.isLoading || status === undefined) return { ...base, blocksAction: true };
|
|
70
|
+
|
|
71
|
+
if (!status.exists) return { ...base, needsActivation: true, blocksAction: true };
|
|
72
|
+
|
|
73
|
+
// Native XLM can fund an activated zero-balance account without a trustline.
|
|
74
|
+
if (isNativeToken) return { ...base, blocksAction: false };
|
|
75
|
+
|
|
76
|
+
if (trustlineCheck.isError) return { ...base, checkFailed: true, blocksAction: true };
|
|
77
|
+
if (unresolved(trustlineCheck)) return { ...base, blocksAction: true };
|
|
78
|
+
|
|
79
|
+
if (trustlineCheck.data === true) return { ...base, blocksAction: false };
|
|
80
|
+
|
|
81
|
+
if (!status.canAffordTrustline) return { ...base, needsFunding: true, blocksAction: true };
|
|
82
|
+
|
|
83
|
+
return { ...base, needsTrustline: true, blocksAction: true };
|
|
84
|
+
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
-
import type { RequestOverrideConfig, SubmitSwapTxStatusResponse } from '@sodax/sdk';
|
|
3
|
-
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
-
import { unwrapResult } from './unwrapResult.js';
|
|
5
|
-
import type { ReadHookParams } from '../shared/types.js';
|
|
6
|
-
|
|
7
|
-
export type UseBackendSubmitSwapTxStatusParams = ReadHookParams<
|
|
8
|
-
SubmitSwapTxStatusResponse | undefined,
|
|
9
|
-
{
|
|
10
|
-
txHash: string | undefined;
|
|
11
|
-
srcChainKey?: string;
|
|
12
|
-
apiConfig?: RequestOverrideConfig;
|
|
13
|
-
}
|
|
14
|
-
>;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* React hook for polling the processing status of a submitted swap transaction.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* const { data: status } = useBackendSubmitSwapTxStatus({
|
|
21
|
-
* params: { txHash: '0x123...', srcChainKey: 'sonic' },
|
|
22
|
-
* });
|
|
23
|
-
*
|
|
24
|
-
* @remarks
|
|
25
|
-
* - Default refetch interval is 1 second; stops on 'executed' or 'failed' status.
|
|
26
|
-
*/
|
|
27
|
-
export const useBackendSubmitSwapTxStatus = ({
|
|
28
|
-
params,
|
|
29
|
-
queryOptions,
|
|
30
|
-
}: UseBackendSubmitSwapTxStatusParams = {}): UseQueryResult<SubmitSwapTxStatusResponse | undefined, Error> => {
|
|
31
|
-
const { sodax } = useSodaxContext();
|
|
32
|
-
const txHash = params?.txHash;
|
|
33
|
-
const srcChainKey = params?.srcChainKey;
|
|
34
|
-
const apiConfig = params?.apiConfig;
|
|
35
|
-
|
|
36
|
-
return useQuery({
|
|
37
|
-
queryKey: ['backend', 'submitSwapTx', 'status', txHash, srcChainKey],
|
|
38
|
-
queryFn: async (): Promise<SubmitSwapTxStatusResponse | undefined> => {
|
|
39
|
-
if (!txHash) return undefined;
|
|
40
|
-
return unwrapResult(
|
|
41
|
-
await sodax.backendApi.getSubmitSwapTxStatus(
|
|
42
|
-
{
|
|
43
|
-
txHash,
|
|
44
|
-
srcChainKey,
|
|
45
|
-
},
|
|
46
|
-
apiConfig,
|
|
47
|
-
),
|
|
48
|
-
);
|
|
49
|
-
},
|
|
50
|
-
enabled: !!txHash && txHash.length > 0,
|
|
51
|
-
retry: 3,
|
|
52
|
-
refetchInterval: query => {
|
|
53
|
-
const status = query.state.data?.data?.status;
|
|
54
|
-
if (status === 'executed' || status === 'failed') return false;
|
|
55
|
-
return 1000;
|
|
56
|
-
},
|
|
57
|
-
...queryOptions,
|
|
58
|
-
});
|
|
59
|
-
};
|