@sodax/dapp-kit 1.2.7-beta → 1.3.1-beta-rc1
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/dist/index.js +28 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/hooks/mm/useMMAllowance.ts +30 -2
- package/src/hooks/mm/useMMApprove.ts +0 -7
- package/src/hooks/provider/useSpokeProvider.ts +13 -0
- package/src/hooks/staking/useConvertedAssets.ts +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { createContext, useContext, useState, useCallback, useMemo, useRef, useEffect } from 'react';
|
|
2
|
-
import { SpokeService, deriveUserWalletAddress, STELLAR_MAINNET_CHAIN_ID, StellarSpokeProvider, StellarSpokeService, HubService, spokeChainConfig, SONIC_MAINNET_CHAIN_ID, SonicSpokeProvider, EvmSpokeProvider, SuiSpokeProvider, IconSpokeProvider, InjectiveSpokeProvider, SolanaSpokeProvider, isLegacybnUSDToken, Sodax } from '@sodax/sdk';
|
|
2
|
+
import { SpokeService, deriveUserWalletAddress, STELLAR_MAINNET_CHAIN_ID, StellarSpokeProvider, StellarSpokeService, HubService, spokeChainConfig, SONIC_MAINNET_CHAIN_ID, SonicSpokeProvider, EvmSpokeProvider, SuiSpokeProvider, IconSpokeProvider, InjectiveSpokeProvider, SolanaSpokeProvider, NearSpokeProvider, isLegacybnUSDToken, Sodax } from '@sodax/sdk';
|
|
3
3
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
4
4
|
import { isAddress, parseUnits } from 'viem';
|
|
5
5
|
import { ICON_MAINNET_CHAIN_ID } from '@sodax/types';
|
|
@@ -144,9 +144,11 @@ function useSpokeProvider(spokeChainId, walletProvider) {
|
|
|
144
144
|
spokeChainConfig[spokeChainId]
|
|
145
145
|
);
|
|
146
146
|
}
|
|
147
|
+
const evmRpcUrl = rpcConfig[spokeChainId];
|
|
147
148
|
return new EvmSpokeProvider(
|
|
148
149
|
walletProvider,
|
|
149
|
-
spokeChainConfig[spokeChainId]
|
|
150
|
+
spokeChainConfig[spokeChainId],
|
|
151
|
+
typeof evmRpcUrl === "string" ? evmRpcUrl : void 0
|
|
150
152
|
);
|
|
151
153
|
}
|
|
152
154
|
if (xChainType === "SUI") {
|
|
@@ -187,6 +189,12 @@ function useSpokeProvider(spokeChainId, walletProvider) {
|
|
|
187
189
|
} : spokeChainConfig[spokeChainId]
|
|
188
190
|
);
|
|
189
191
|
}
|
|
192
|
+
if (xChainType === "NEAR") {
|
|
193
|
+
return new NearSpokeProvider(
|
|
194
|
+
walletProvider,
|
|
195
|
+
spokeChainConfig[spokeChainId]
|
|
196
|
+
);
|
|
197
|
+
}
|
|
190
198
|
return void 0;
|
|
191
199
|
}, [spokeChainId, xChainType, walletProvider, rpcConfig]);
|
|
192
200
|
return spokeProvider;
|
|
@@ -312,8 +320,22 @@ function useMMAllowance({
|
|
|
312
320
|
const { sodax } = useSodaxContext();
|
|
313
321
|
const defaultQueryOptions = {
|
|
314
322
|
queryKey: ["mm", "allowance", params?.token, params?.action],
|
|
315
|
-
|
|
316
|
-
|
|
323
|
+
/**
|
|
324
|
+
* IMPORTANT: Skip allowance checks for 'borrow' and 'withdraw' actions.
|
|
325
|
+
*
|
|
326
|
+
* Reason: According to the SDK's MoneyMarketService.isAllowanceValid() implementation,
|
|
327
|
+
* borrow and withdraw actions do NOT require ERC-20 token approval. The SDK's
|
|
328
|
+
* isAllowanceValid() method always returns `true` for these actions without making
|
|
329
|
+
* any on-chain allowance checks.
|
|
330
|
+
*
|
|
331
|
+
* This optimization prevents unnecessary RPC calls and avoids showing confusing states for actions that don't actually need approval.
|
|
332
|
+
*
|
|
333
|
+
* Only 'supply' and 'repay' actions require token approval and should trigger allowance checks.
|
|
334
|
+
*/
|
|
335
|
+
enabled: !!spokeProvider && !!params && params.action !== "borrow" && params.action !== "withdraw",
|
|
336
|
+
refetchInterval: 5e3,
|
|
337
|
+
gcTime: 0
|
|
338
|
+
// Don't cache failed queries
|
|
317
339
|
};
|
|
318
340
|
queryOptions = {
|
|
319
341
|
...defaultQueryOptions,
|
|
@@ -325,6 +347,9 @@ function useMMAllowance({
|
|
|
325
347
|
queryFn: async () => {
|
|
326
348
|
if (!spokeProvider) throw new Error("Spoke provider is required");
|
|
327
349
|
if (!params) throw new Error("Params are required");
|
|
350
|
+
if (params.action === "borrow" || params.action === "withdraw") {
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
328
353
|
const allowance = await sodax.moneyMarket.isAllowanceValid(params, spokeProvider);
|
|
329
354
|
if (!allowance.ok) {
|
|
330
355
|
throw allowance.error;
|
|
@@ -348,13 +373,6 @@ function useMMApprove() {
|
|
|
348
373
|
return allowance.value;
|
|
349
374
|
},
|
|
350
375
|
onSuccess: (_, { params, spokeProvider }) => {
|
|
351
|
-
console.log("onSuccess invoked with queryKey:", [
|
|
352
|
-
"mm",
|
|
353
|
-
"allowance",
|
|
354
|
-
spokeProvider?.chainConfig.chain.id,
|
|
355
|
-
params.token,
|
|
356
|
-
params.action
|
|
357
|
-
]);
|
|
358
376
|
queryClient.invalidateQueries({
|
|
359
377
|
queryKey: ["mm", "allowance", spokeProvider?.chainConfig.chain.id, params.token, params.action]
|
|
360
378
|
});
|
|
@@ -1171,11 +1189,9 @@ function useInstantUnstakeRatio(amount, refetchInterval = 1e4) {
|
|
|
1171
1189
|
}
|
|
1172
1190
|
function useConvertedAssets(amount, refetchInterval = 1e4) {
|
|
1173
1191
|
const { sodax } = useSodaxContext();
|
|
1174
|
-
console.log("useConvertedAssets hook called with:", { amount: amount?.toString(), sodax: !!sodax });
|
|
1175
1192
|
return useQuery({
|
|
1176
1193
|
queryKey: ["soda", "convertedAssets", amount?.toString()],
|
|
1177
1194
|
queryFn: async () => {
|
|
1178
|
-
console.log("useConvertedAssets queryFn called with amount:", amount?.toString());
|
|
1179
1195
|
if (!amount || amount <= 0n) {
|
|
1180
1196
|
throw new Error("Amount must be greater than 0");
|
|
1181
1197
|
}
|