@sodax/dapp-kit 0.0.1-rc.20 → 0.0.1-rc.22
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 +83 -1
- package/dist/contexts/index.d.ts +1 -2
- package/dist/contexts/index.d.ts.map +1 -1
- package/dist/hooks/bridge/index.d.ts +6 -0
- package/dist/hooks/bridge/index.d.ts.map +1 -0
- package/dist/hooks/bridge/useBridge.d.ts +33 -0
- package/dist/hooks/bridge/useBridge.d.ts.map +1 -0
- package/dist/hooks/bridge/useBridgeAllowance.d.ts +23 -0
- package/dist/hooks/bridge/useBridgeAllowance.d.ts.map +1 -0
- package/dist/hooks/bridge/useBridgeApprove.d.ts +29 -0
- package/dist/hooks/bridge/useBridgeApprove.d.ts.map +1 -0
- package/dist/hooks/bridge/useGetBridgeableAmount.d.ts +26 -0
- package/dist/hooks/bridge/useGetBridgeableAmount.d.ts.map +1 -0
- package/dist/hooks/bridge/useGetBridgeableTokens.d.ts +37 -0
- package/dist/hooks/bridge/useGetBridgeableTokens.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/mm/useUserFormattedSummary.d.ts +1 -1
- package/dist/hooks/mm/useUserFormattedSummary.d.ts.map +1 -1
- package/dist/hooks/mm/useUserReservesData.d.ts +1 -1
- package/dist/hooks/mm/useUserReservesData.d.ts.map +1 -1
- package/dist/hooks/provider/useHubProvider.d.ts +1 -1
- package/dist/hooks/provider/useHubProvider.d.ts.map +1 -1
- package/dist/hooks/provider/useSpokeProvider.d.ts.map +1 -1
- package/dist/hooks/shared/index.d.ts +1 -0
- package/dist/hooks/shared/index.d.ts.map +1 -1
- package/dist/hooks/shared/useDeriveUserWalletAddress.d.ts +24 -0
- package/dist/hooks/shared/useDeriveUserWalletAddress.d.ts.map +1 -0
- package/dist/index.js +139 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +135 -21
- package/dist/index.mjs.map +1 -1
- package/dist/providers/SodaxProvider.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/contexts/index.ts +1 -2
- package/src/hooks/bridge/index.ts +5 -0
- package/src/hooks/bridge/useBridge.ts +57 -0
- package/src/hooks/bridge/useBridgeAllowance.ts +49 -0
- package/src/hooks/bridge/useBridgeApprove.ts +68 -0
- package/src/hooks/bridge/useGetBridgeableAmount.ts +50 -0
- package/src/hooks/bridge/useGetBridgeableTokens.ts +62 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/mm/useUserFormattedSummary.ts +1 -1
- package/src/hooks/mm/useUserReservesData.ts +1 -1
- package/src/hooks/provider/useHubProvider.ts +3 -3
- package/src/hooks/provider/useSpokeProvider.ts +10 -4
- package/src/hooks/shared/index.ts +1 -0
- package/src/hooks/shared/useDeriveUserWalletAddress.ts +44 -0
- package/src/providers/SodaxProvider.tsx +4 -18
|
@@ -93,10 +93,16 @@ export function useSpokeProvider(
|
|
|
93
93
|
|
|
94
94
|
if (xChainType === 'STELLAR') {
|
|
95
95
|
const stellarConfig = spokeChainConfig[spokeChainId] as StellarSpokeChainConfig;
|
|
96
|
-
return new StellarSpokeProvider(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
return new StellarSpokeProvider(
|
|
97
|
+
walletProvider as IStellarWalletProvider,
|
|
98
|
+
stellarConfig,
|
|
99
|
+
rpcConfig.stellar
|
|
100
|
+
? rpcConfig.stellar
|
|
101
|
+
: {
|
|
102
|
+
horizonRpcUrl: stellarConfig.horizonRpcUrl,
|
|
103
|
+
sorobanRpcUrl: stellarConfig.sorobanRpcUrl,
|
|
104
|
+
},
|
|
105
|
+
);
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
if (xChainType === 'SOLANA') {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/shared/useDeriveUserWalletAddress.ts
|
|
2
|
+
import { deriveUserWalletAddress, type SpokeProvider, type EvmHubProvider } from '@sodax/sdk';
|
|
3
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
4
|
+
import { useSodaxContext } from './useSodaxContext';
|
|
5
|
+
import type { Address } from 'viem';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hook for deriving user wallet address for hub abstraction.
|
|
9
|
+
*
|
|
10
|
+
* This hook derives the user's abstracted wallet address for the hub chain.
|
|
11
|
+
* If the spoke chain is the same as the hub chain, it returns the original wallet address.
|
|
12
|
+
* Otherwise, it returns the abstracted wallet address for cross-chain operations.
|
|
13
|
+
*
|
|
14
|
+
* @param spokeProvider - The spoke provider instance for the origin chain
|
|
15
|
+
* @param walletAddress - Optional user wallet address on spoke chain. If not provided, will fetch from spokeProvider
|
|
16
|
+
* @returns A React Query result object containing:
|
|
17
|
+
* - data: The derived user wallet address when available
|
|
18
|
+
* - isLoading: Loading state indicator
|
|
19
|
+
* - error: Any error that occurred during derivation
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(spokeProvider, userAddress);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function useDeriveUserWalletAddress(
|
|
27
|
+
spokeProvider: SpokeProvider | undefined,
|
|
28
|
+
walletAddress?: string | undefined,
|
|
29
|
+
): UseQueryResult<Address, Error> {
|
|
30
|
+
const { sodax } = useSodaxContext();
|
|
31
|
+
|
|
32
|
+
return useQuery({
|
|
33
|
+
queryKey: ['deriveUserWalletAddress', spokeProvider?.chainConfig.chain.id, walletAddress],
|
|
34
|
+
queryFn: async (): Promise<Address> => {
|
|
35
|
+
if (!spokeProvider) {
|
|
36
|
+
throw new Error('Spoke provider is required');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return await deriveUserWalletAddress(spokeProvider, sodax.hubProvider, walletAddress);
|
|
40
|
+
},
|
|
41
|
+
enabled: !!spokeProvider,
|
|
42
|
+
refetchInterval: false, // This is a deterministic operation, no need to refetch
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ReactNode, ReactElement } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { Sodax, type SodaxConfig } from '@sodax/sdk';
|
|
3
5
|
import { SodaxContext } from '@/contexts';
|
|
4
|
-
import React, { useMemo } from 'react';
|
|
5
6
|
import type { RpcConfig } from '@/types';
|
|
6
7
|
|
|
7
8
|
interface SodaxProviderProps {
|
|
@@ -14,20 +15,5 @@ interface SodaxProviderProps {
|
|
|
14
15
|
export const SodaxProvider = ({ children, testnet = false, config, rpcConfig }: SodaxProviderProps): ReactElement => {
|
|
15
16
|
const sodax = new Sodax(config);
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
const hubRpcUrl = config?.hubProviderConfig?.hubRpcUrl;
|
|
19
|
-
|
|
20
|
-
const hubProvider = useMemo(() => {
|
|
21
|
-
if (hubChainId && hubRpcUrl) {
|
|
22
|
-
const hubChainCfg = getHubChainConfig(hubChainId);
|
|
23
|
-
|
|
24
|
-
return new EvmHubProvider({
|
|
25
|
-
hubRpcUrl: hubRpcUrl,
|
|
26
|
-
chainConfig: hubChainCfg,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
return undefined;
|
|
30
|
-
}, [hubChainId, hubRpcUrl]);
|
|
31
|
-
|
|
32
|
-
return <SodaxContext.Provider value={{ sodax, testnet, hubProvider, rpcConfig }}>{children}</SodaxContext.Provider>;
|
|
18
|
+
return <SodaxContext.Provider value={{ sodax, testnet, rpcConfig }}>{children}</SodaxContext.Provider>;
|
|
33
19
|
};
|