@sodax/dapp-kit 2.0.0-rc.11 → 2.0.0-rc.13

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.
Files changed (35) hide show
  1. package/README.md +5 -5
  2. package/dist/index.d.ts +282 -8
  3. package/dist/index.mjs +290 -47
  4. package/package.json +2 -2
  5. package/src/hooks/_mutationContract.test.ts +6 -1
  6. package/src/hooks/bitcoin/resolveBtcReadAddress.test.ts +54 -0
  7. package/src/hooks/bitcoin/resolveBtcReadAddress.ts +21 -0
  8. package/src/hooks/bitcoin/useFundTradingWallet.ts +1 -1
  9. package/src/hooks/bitcoin/useRadfiAuth.ts +2 -2
  10. package/src/hooks/bitcoin/useRadfiWithdraw.ts +2 -2
  11. package/src/hooks/bitcoin/useRenewUtxos.ts +2 -2
  12. package/src/hooks/bitcoin/useTradingWallet.ts +1 -1
  13. package/src/hooks/index.ts +1 -0
  14. package/src/hooks/leverageYield/index.ts +9 -0
  15. package/src/hooks/leverageYield/useLeverageYieldDeposit.ts +40 -0
  16. package/src/hooks/leverageYield/useLeverageYieldEffectiveApr.ts +42 -0
  17. package/src/hooks/leverageYield/useLeverageYieldNotifySolver.ts +34 -0
  18. package/src/hooks/leverageYield/useLeverageYieldPosition.ts +40 -0
  19. package/src/hooks/leverageYield/useLeverageYieldPreviewRedeem.ts +43 -0
  20. package/src/hooks/leverageYield/useLeverageYieldShareBalances.ts +74 -0
  21. package/src/hooks/leverageYield/useLeverageYieldTotalAssets.ts +36 -0
  22. package/src/hooks/leverageYield/useLeverageYieldVaultSwap.ts +50 -0
  23. package/src/hooks/leverageYield/useLeverageYieldWithdraw.ts +40 -0
  24. package/src/hooks/mm/useATokensBalances.ts +7 -1
  25. package/src/hooks/mm/useUserFormattedSummary.ts +5 -1
  26. package/src/hooks/mm/useUserReservesData.ts +5 -1
  27. package/src/hooks/shared/index.ts +3 -0
  28. package/src/hooks/shared/useGetUserHubWalletAddress.ts +5 -1
  29. package/src/hooks/shared/useNearStorageCheck.ts +45 -0
  30. package/src/hooks/shared/useNearStorageGate.ts +60 -0
  31. package/src/hooks/shared/useRegisterNearStorage.ts +46 -0
  32. package/src/providers/SodaxProvider.tsx +2 -3
  33. package/src/utils/index.ts +1 -0
  34. package/src/utils/nearStorageGate.test.ts +46 -0
  35. package/src/utils/nearStorageGate.ts +39 -0
@@ -1,7 +1,6 @@
1
1
  import { useMemo, type ReactNode, type ReactElement } from 'react';
2
- import { Sodax, type SodaxConfig } from '@sodax/sdk';
2
+ import { Sodax, type SodaxOptions } from '@sodax/sdk';
3
3
  import { SodaxContext } from '@/contexts/index.js';
4
- import type { DeepPartial } from '@sodax/sdk';
5
4
 
6
5
  interface SodaxProviderProps {
7
6
  children: ReactNode;
@@ -17,7 +16,7 @@ interface SodaxProviderProps {
17
16
  * <SodaxProvider config={config}>...</SodaxProvider>
18
17
  * ```
19
18
  */
20
- config?: DeepPartial<SodaxConfig>;
19
+ config?: SodaxOptions;
21
20
  }
22
21
 
23
22
  /** Root provider for `@sodax/dapp-kit`. Must be paired with `QueryClientProvider`. */
@@ -1 +1,2 @@
1
1
  export * from './dex-utils.js';
2
+ export * from './nearStorageGate.js';
@@ -0,0 +1,46 @@
1
+ import { ChainKeys } from '@sodax/sdk';
2
+ import { describe, expect, it } from 'vitest';
3
+ import { resolveNearStorageGate } from './nearStorageGate.js';
4
+
5
+ describe('resolveNearStorageGate', () => {
6
+ it('destination not NEAR → never gates', () => {
7
+ expect(resolveNearStorageGate(ChainKeys.POLYGON_MAINNET, { isLoading: false, data: false })).toEqual({
8
+ isNear: false,
9
+ needsRegistration: false,
10
+ blocksAction: false,
11
+ });
12
+ });
13
+
14
+ it('NEAR, check in flight → blocks action but does not yet prompt registration', () => {
15
+ expect(resolveNearStorageGate(ChainKeys.NEAR_MAINNET, { isLoading: true, data: undefined })).toEqual({
16
+ isNear: true,
17
+ needsRegistration: false,
18
+ blocksAction: true,
19
+ });
20
+ });
21
+
22
+ it('NEAR, check resolved, not registered → prompt registration and block action', () => {
23
+ expect(resolveNearStorageGate(ChainKeys.NEAR_MAINNET, { isLoading: false, data: false })).toEqual({
24
+ isNear: true,
25
+ needsRegistration: true,
26
+ blocksAction: true,
27
+ });
28
+ });
29
+
30
+ it('NEAR, check resolved, registered → no gate', () => {
31
+ expect(resolveNearStorageGate(ChainKeys.NEAR_MAINNET, { isLoading: false, data: true })).toEqual({
32
+ isNear: true,
33
+ needsRegistration: false,
34
+ blocksAction: false,
35
+ });
36
+ });
37
+
38
+ it('NEAR, query disabled (unresolved, not checking) → does not block', () => {
39
+ // isLoading is false for a disabled query; data stays undefined → action must not be blocked.
40
+ expect(resolveNearStorageGate(ChainKeys.NEAR_MAINNET, { isLoading: false, data: undefined })).toEqual({
41
+ isNear: true,
42
+ needsRegistration: false,
43
+ blocksAction: false,
44
+ });
45
+ });
46
+ });
@@ -0,0 +1,39 @@
1
+ import { ChainKeys, type SpokeChainKey } from '@sodax/sdk';
2
+ import type { UseQueryResult } from '@tanstack/react-query';
3
+
4
+ /** The subset of a `useNearStorageCheck` result the gate reads. A full `UseQueryResult<boolean>` satisfies it. */
5
+ export type NearStorageCheckResult = Pick<UseQueryResult<boolean>, 'isLoading' | 'data'>;
6
+
7
+ /** UI gate state for NEP-141 storage registration on NEAR. */
8
+ export interface NearStorageGateState {
9
+ /** Destination is NEAR — the only chain with a NEP-141 storage-registration prerequisite. */
10
+ isNear: boolean;
11
+ /** Show the "register storage" action: the check resolved and the recipient is not registered. */
12
+ needsRegistration: boolean;
13
+ /**
14
+ * Keep the downstream action (swap/bridge/borrow/withdraw) disabled: the NEAR gate is unresolved
15
+ * (still checking) or unmet (needs registration).
16
+ */
17
+ blocksAction: boolean;
18
+ }
19
+
20
+ /**
21
+ * Derives the NEP-141 storage-registration UI gate state for a flow that delivers a token to a user
22
+ * on NEAR — NEAR's analogue of the Stellar trustline gate. Unwrapped (no hook): pass the destination
23
+ * `chainKey` and the `useNearStorageCheck` result; the util owns the `=== NEAR` test and reads
24
+ * `isLoading` (NOT `isPending`, which stays `true` for a disabled query and would block forever).
25
+ *
26
+ * `blocksAction` deliberately also covers the in-flight check window so the action can't be
27
+ * triggered before registration status is known; `needsRegistration` only flips once the check has
28
+ * resolved (so the "register" button isn't shown speculatively while still checking).
29
+ */
30
+ export function resolveNearStorageGate(chainKey: SpokeChainKey, check: NearStorageCheckResult): NearStorageGateState {
31
+ const isNear = chainKey === ChainKeys.NEAR_MAINNET;
32
+ const isChecking = check.isLoading;
33
+ const isRegistered = check.data;
34
+ return {
35
+ isNear,
36
+ needsRegistration: isNear && !isChecking && isRegistered === false,
37
+ blocksAction: isNear && (isChecking || isRegistered === false),
38
+ };
39
+ }