@sodax/wallet-sdk-react 1.5.7-beta → 2.0.0-rc.10
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 +107 -142
- package/dist/XConnector-12q0OVe5.d.ts +146 -0
- package/dist/chunk-7V7O3Q7Y.mjs +62 -0
- package/dist/chunk-C6M34IVL.mjs +86 -0
- package/dist/chunk-DQTYAMKF.mjs +1609 -0
- package/dist/chunk-FSOGMSJH.mjs +39 -0
- package/dist/chunk-IFXZQW4C.mjs +98 -0
- package/dist/chunk-JQ4H4GJ5.mjs +100 -0
- package/dist/chunk-LKSSME2J.mjs +31 -0
- package/dist/chunk-MWWVB7TD.mjs +123 -0
- package/dist/chunk-NAKCAL2M.mjs +32 -0
- package/dist/chunk-OPYSVPRW.mjs +144 -0
- package/dist/chunk-QMXBY3UI.mjs +1 -0
- package/dist/chunk-TACW7Z4D.mjs +31 -0
- package/dist/chunk-WPZOLGVB.mjs +148 -0
- package/dist/chunk-X7BHR7WS.mjs +200 -0
- package/dist/chunk-Z5GXDHGL.mjs +190 -0
- package/dist/config-DEsqgrG1.d.ts +151 -0
- package/dist/index.d.ts +768 -1498
- package/dist/index.mjs +453 -2005
- package/dist/xchains/bitcoin/index.d.ts +125 -0
- package/dist/xchains/bitcoin/index.mjs +14 -0
- package/dist/xchains/evm/index.d.ts +39 -0
- package/dist/xchains/evm/index.mjs +3 -0
- package/dist/xchains/icon/index.d.ts +37 -0
- package/dist/xchains/icon/index.mjs +5 -0
- package/dist/xchains/injective/index.d.ts +35 -0
- package/dist/xchains/injective/index.mjs +3 -0
- package/dist/xchains/near/index.d.ts +34 -0
- package/dist/xchains/near/index.mjs +4 -0
- package/dist/xchains/solana/index.d.ts +26 -0
- package/dist/xchains/solana/index.mjs +5 -0
- package/dist/xchains/stacks/index.d.ts +42 -0
- package/dist/xchains/stacks/index.mjs +3 -0
- package/dist/xchains/stellar/index.d.ts +44 -0
- package/dist/xchains/stellar/index.mjs +4 -0
- package/dist/xchains/sui/index.d.ts +37 -0
- package/dist/xchains/sui/index.mjs +5 -0
- package/docs/ADDING_A_NEW_CHAIN.md +440 -0
- package/docs/ARCHITECTURE.md +291 -0
- package/docs/BATCH_OPERATIONS.md +267 -0
- package/docs/CHAIN_DETECTION.md +216 -0
- package/docs/CONFIGURE_PROVIDER.md +360 -0
- package/docs/CONNECTORS.md +247 -0
- package/docs/CONNECT_FLOW.md +276 -0
- package/docs/EVM_SWITCH_CHAIN.md +161 -0
- package/docs/SIGN_MESSAGE.md +213 -0
- package/docs/SUB_PATH_EXPORTS.md +218 -0
- package/docs/WALLETCONNECT.md +154 -0
- package/docs/WALLET_MODAL.md +331 -0
- package/docs/WALLET_PROVIDER_BRIDGE.md +226 -0
- package/package.json +56 -22
- package/dist/index.cjs +0 -2147
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1579
- package/dist/index.mjs.map +0 -1
- package/src/Hydrate.ts +0 -65
- package/src/SodaxWalletProvider.tsx +0 -97
- package/src/actions/getXChainType.ts +0 -8
- package/src/actions/getXService.ts +0 -33
- package/src/actions/index.ts +0 -2
- package/src/assets/wallets/hana.svg +0 -6
- package/src/assets/wallets/havah.svg +0 -76
- package/src/assets/wallets/keplr.svg +0 -30
- package/src/assets/wallets/metamask.svg +0 -60
- package/src/assets/wallets/phantom.svg +0 -4
- package/src/assets/wallets/sui.svg +0 -20
- package/src/core/XConnector.ts +0 -54
- package/src/core/XService.ts +0 -85
- package/src/core/index.ts +0 -2
- package/src/hooks/index.ts +0 -11
- package/src/hooks/useEthereumChainId.ts +0 -44
- package/src/hooks/useEvmSwitchChain.ts +0 -91
- package/src/hooks/useWalletProvider.ts +0 -206
- package/src/hooks/useXAccount.ts +0 -51
- package/src/hooks/useXAccounts.ts +0 -56
- package/src/hooks/useXBalances.ts +0 -65
- package/src/hooks/useXConnect.ts +0 -118
- package/src/hooks/useXConnection.ts +0 -72
- package/src/hooks/useXConnectors.ts +0 -72
- package/src/hooks/useXDisconnect.ts +0 -73
- package/src/hooks/useXService.ts +0 -8
- package/src/hooks/useXSignMessage.ts +0 -82
- package/src/index.ts +0 -19
- package/src/types/index.ts +0 -22
- package/src/useXWagmiStore.ts +0 -116
- package/src/utils/index.ts +0 -21
- package/src/xchains/bitcoin/BitcoinXConnector.ts +0 -34
- package/src/xchains/bitcoin/BitcoinXService.ts +0 -40
- package/src/xchains/bitcoin/OKXXConnector.ts +0 -117
- package/src/xchains/bitcoin/UnisatXConnector.ts +0 -117
- package/src/xchains/bitcoin/XverseXConnector.ts +0 -232
- package/src/xchains/bitcoin/index.ts +0 -7
- package/src/xchains/bitcoin/useBitcoinXConnectors.ts +0 -14
- package/src/xchains/evm/EvmXConnector.ts +0 -27
- package/src/xchains/evm/EvmXService.ts +0 -211
- package/src/xchains/evm/index.ts +0 -3
- package/src/xchains/icon/IconHanaXConnector.ts +0 -39
- package/src/xchains/icon/IconXService.ts +0 -117
- package/src/xchains/icon/actions.ts +0 -28
- package/src/xchains/icon/iconex/index.tsx +0 -46
- package/src/xchains/icon/index.ts +0 -2
- package/src/xchains/injective/InjectiveXConnector.ts +0 -60
- package/src/xchains/injective/InjectiveXService.ts +0 -62
- package/src/xchains/injective/actions.ts +0 -32
- package/src/xchains/injective/index.ts +0 -2
- package/src/xchains/near/NearXConnector.ts +0 -42
- package/src/xchains/near/NearXService.ts +0 -46
- package/src/xchains/near/useNearXConnectors.ts +0 -23
- package/src/xchains/solana/SolanaXConnector.ts +0 -26
- package/src/xchains/solana/SolanaXService.ts +0 -46
- package/src/xchains/solana/index.ts +0 -2
- package/src/xchains/stacks/StacksXConnector.ts +0 -63
- package/src/xchains/stacks/StacksXService.ts +0 -59
- package/src/xchains/stacks/constants.ts +0 -42
- package/src/xchains/stacks/index.ts +0 -4
- package/src/xchains/stacks/useStacksXConnectors.ts +0 -7
- package/src/xchains/stellar/CustomSorobanServer.ts +0 -93
- package/src/xchains/stellar/StellarWalletsKitXConnector.ts +0 -53
- package/src/xchains/stellar/StellarXService.ts +0 -93
- package/src/xchains/stellar/actions.ts +0 -24
- package/src/xchains/stellar/index.tsx +0 -2
- package/src/xchains/stellar/useStellarXConnectors.ts +0 -21
- package/src/xchains/stellar/utils.ts +0 -49
- package/src/xchains/sui/SuiXConnector.ts +0 -28
- package/src/xchains/sui/SuiXService.ts +0 -66
- package/src/xchains/sui/index.ts +0 -2
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { ChainType } from '@sodax/types';
|
|
2
|
-
import { useWallets } from '@mysten/dapp-kit';
|
|
3
|
-
import { useWallet } from '@solana/wallet-adapter-react';
|
|
4
|
-
import { useMemo } from 'react';
|
|
5
|
-
import { useConnectors } from 'wagmi';
|
|
6
|
-
import type { XConnector } from '../core';
|
|
7
|
-
import { EvmXConnector } from '../xchains/evm';
|
|
8
|
-
import { SolanaXConnector } from '../xchains/solana';
|
|
9
|
-
import { useStellarXConnectors } from '../xchains/stellar/useStellarXConnectors';
|
|
10
|
-
import { SuiXConnector } from '../xchains/sui';
|
|
11
|
-
import { useXService } from './useXService';
|
|
12
|
-
import { useNearXConnectors } from '../xchains/near/useNearXConnectors';
|
|
13
|
-
import { useStacksXConnectors } from '../xchains/stacks/useStacksXConnectors';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Hook to retrieve available wallet connectors for a specific blockchain type.
|
|
17
|
-
*
|
|
18
|
-
* This hook aggregates wallet connectors from different blockchain ecosystems:
|
|
19
|
-
* - EVM: Uses wagmi connectors
|
|
20
|
-
* - Sui: Uses Sui wallet adapters
|
|
21
|
-
* - Stellar: Uses custom Stellar connectors
|
|
22
|
-
* - Solana: Uses Solana wallet adapters (filtered to installed wallets only)
|
|
23
|
-
*
|
|
24
|
-
* @param xChainType - The blockchain type to get connectors for ('EVM' | 'SUI' | 'STELLAR' | 'SOLANA' | 'NEAR' | 'STACKS')
|
|
25
|
-
* @returns An array of XConnector instances compatible with the specified chain type
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
export function useXConnectors(xChainType: ChainType | undefined): XConnector[] {
|
|
29
|
-
const xService = useXService(xChainType);
|
|
30
|
-
const evmConnectors = useConnectors();
|
|
31
|
-
const suiWallets = useWallets();
|
|
32
|
-
const { data: stellarXConnectors } = useStellarXConnectors();
|
|
33
|
-
const { data: nearXConnectors } = useNearXConnectors();
|
|
34
|
-
const stacksXConnectors = useStacksXConnectors();
|
|
35
|
-
const { wallets: solanaWallets } = useWallet();
|
|
36
|
-
|
|
37
|
-
const xConnectors = useMemo((): XConnector[] => {
|
|
38
|
-
if (!xChainType || !xService) {
|
|
39
|
-
return [];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
switch (xChainType) {
|
|
43
|
-
case 'EVM':
|
|
44
|
-
return evmConnectors.map(connector => new EvmXConnector(connector));
|
|
45
|
-
case 'SUI':
|
|
46
|
-
return suiWallets.map(wallet => new SuiXConnector(wallet));
|
|
47
|
-
case 'STELLAR':
|
|
48
|
-
return stellarXConnectors || [];
|
|
49
|
-
case 'SOLANA':
|
|
50
|
-
return solanaWallets
|
|
51
|
-
.filter(wallet => wallet.readyState === 'Installed')
|
|
52
|
-
.map(wallet => new SolanaXConnector(wallet));
|
|
53
|
-
case 'NEAR':
|
|
54
|
-
return nearXConnectors || [];
|
|
55
|
-
case 'STACKS':
|
|
56
|
-
return stacksXConnectors;
|
|
57
|
-
default:
|
|
58
|
-
return xService.getXConnectors();
|
|
59
|
-
}
|
|
60
|
-
}, [
|
|
61
|
-
xService,
|
|
62
|
-
xChainType,
|
|
63
|
-
evmConnectors,
|
|
64
|
-
suiWallets,
|
|
65
|
-
stellarXConnectors,
|
|
66
|
-
solanaWallets,
|
|
67
|
-
nearXConnectors,
|
|
68
|
-
stacksXConnectors,
|
|
69
|
-
]);
|
|
70
|
-
|
|
71
|
-
return xConnectors;
|
|
72
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import type { ChainType } from '@sodax/types';
|
|
2
|
-
import { useDisconnectWallet } from '@mysten/dapp-kit';
|
|
3
|
-
import { useWallet } from '@solana/wallet-adapter-react';
|
|
4
|
-
import { useCallback } from 'react';
|
|
5
|
-
import { useDisconnect } from 'wagmi';
|
|
6
|
-
import { getXService } from '../actions';
|
|
7
|
-
import { useXWagmiStore } from '../useXWagmiStore';
|
|
8
|
-
import type { NearXService } from '@/xchains/near/NearXService';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Hook for disconnecting from a specific blockchain wallet
|
|
12
|
-
*
|
|
13
|
-
* Handles disconnection logic for EVM, SUI, Solana and other supported chains.
|
|
14
|
-
* Clears connection state from XWagmiStore.
|
|
15
|
-
*
|
|
16
|
-
* @param {void} - No parameters required
|
|
17
|
-
* @returns {(xChainType: ChainType) => Promise<void>} Async function that disconnects from the specified chain
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* const disconnect = useXDisconnect();
|
|
22
|
-
*
|
|
23
|
-
* const handleDisconnect = async (xChainType: ChainType) => {
|
|
24
|
-
* await disconnect(xChainType);
|
|
25
|
-
* };
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export function useXDisconnect(): (xChainType: ChainType) => Promise<void> {
|
|
29
|
-
// Get connection state and disconnect handler from store
|
|
30
|
-
const xConnections = useXWagmiStore(state => state.xConnections);
|
|
31
|
-
const unsetXConnection = useXWagmiStore(state => state.unsetXConnection);
|
|
32
|
-
|
|
33
|
-
// Get chain-specific disconnect handlers
|
|
34
|
-
const { disconnectAsync } = useDisconnect();
|
|
35
|
-
const { mutateAsync: suiDisconnectAsync } = useDisconnectWallet();
|
|
36
|
-
const solanaWallet = useWallet();
|
|
37
|
-
|
|
38
|
-
return useCallback(
|
|
39
|
-
async (xChainType: ChainType) => {
|
|
40
|
-
// Handle disconnection based on chain type
|
|
41
|
-
switch (xChainType) {
|
|
42
|
-
case 'EVM':
|
|
43
|
-
await disconnectAsync();
|
|
44
|
-
break;
|
|
45
|
-
case 'SUI':
|
|
46
|
-
await suiDisconnectAsync();
|
|
47
|
-
break;
|
|
48
|
-
case 'SOLANA':
|
|
49
|
-
await solanaWallet.disconnect();
|
|
50
|
-
break;
|
|
51
|
-
|
|
52
|
-
case 'NEAR': {
|
|
53
|
-
const nearXService = getXService('NEAR') as NearXService;
|
|
54
|
-
nearXService.walletSelector.disconnect();
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
default: {
|
|
59
|
-
// Handle other chain types
|
|
60
|
-
const xService = getXService(xChainType);
|
|
61
|
-
const xConnectorId = xConnections[xChainType]?.xConnectorId;
|
|
62
|
-
const xConnector = xConnectorId ? xService.getXConnectorById(xConnectorId) : undefined;
|
|
63
|
-
await xConnector?.disconnect();
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Clear connection state from store
|
|
69
|
-
unsetXConnection(xChainType);
|
|
70
|
-
},
|
|
71
|
-
[xConnections, unsetXConnection, disconnectAsync, suiDisconnectAsync, solanaWallet],
|
|
72
|
-
);
|
|
73
|
-
}
|
package/src/hooks/useXService.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ChainType } from '@sodax/types';
|
|
2
|
-
import type { XService } from '../core';
|
|
3
|
-
import { useXWagmiStore } from '../useXWagmiStore';
|
|
4
|
-
|
|
5
|
-
export function useXService(xChainType: ChainType | undefined): XService | undefined {
|
|
6
|
-
const xService = useXWagmiStore(state => (xChainType ? state.xServices[xChainType] : undefined));
|
|
7
|
-
return xService;
|
|
8
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { useWallet } from '@solana/wallet-adapter-react';
|
|
2
|
-
import { useMutation, type UseMutationResult } from '@tanstack/react-query';
|
|
3
|
-
import type { ChainType } from '@sodax/types';
|
|
4
|
-
import { useSignMessage } from 'wagmi';
|
|
5
|
-
import { useSignPersonalMessage } from '@mysten/dapp-kit';
|
|
6
|
-
import { StellarXService } from '@/xchains/stellar';
|
|
7
|
-
import { InjectiveXService } from '@/xchains/injective';
|
|
8
|
-
import { useXAccount } from './useXAccount';
|
|
9
|
-
import { getEthereumAddress } from '@injectivelabs/sdk-ts';
|
|
10
|
-
import { Wallet } from '@injectivelabs/wallet-base';
|
|
11
|
-
|
|
12
|
-
type SignMessageReturnType = `0x${string}` | Uint8Array | string | undefined;
|
|
13
|
-
|
|
14
|
-
export function useXSignMessage(): UseMutationResult<
|
|
15
|
-
SignMessageReturnType,
|
|
16
|
-
Error,
|
|
17
|
-
{ xChainType: ChainType; message: string },
|
|
18
|
-
unknown
|
|
19
|
-
> {
|
|
20
|
-
const { signMessage } = useWallet();
|
|
21
|
-
const { signMessageAsync: evmSignMessage } = useSignMessage();
|
|
22
|
-
|
|
23
|
-
const { mutateAsync: signPersonalMessage } = useSignPersonalMessage();
|
|
24
|
-
|
|
25
|
-
const { address: injectiveAddress } = useXAccount('INJECTIVE');
|
|
26
|
-
|
|
27
|
-
return useMutation({
|
|
28
|
-
mutationFn: async ({ xChainType, message }: { xChainType: ChainType; message: string }) => {
|
|
29
|
-
let signature: SignMessageReturnType;
|
|
30
|
-
|
|
31
|
-
switch (xChainType) {
|
|
32
|
-
case 'EVM': {
|
|
33
|
-
signature = await evmSignMessage({ message });
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
case 'SUI': {
|
|
37
|
-
const res = await signPersonalMessage({ message: new Uint8Array(new TextEncoder().encode(message)) });
|
|
38
|
-
signature = res.signature;
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
case 'SOLANA': {
|
|
42
|
-
if (!signMessage) {
|
|
43
|
-
throw new Error('Solana wallet not connected');
|
|
44
|
-
}
|
|
45
|
-
signature = await signMessage(new TextEncoder().encode(message));
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
case 'STELLAR': {
|
|
50
|
-
const res = await StellarXService.getInstance().walletsKit.signMessage(message);
|
|
51
|
-
signature = res.signedMessage;
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
case 'INJECTIVE': {
|
|
56
|
-
if (!injectiveAddress) {
|
|
57
|
-
throw new Error('Injective address not found');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const ethereumAddress = getEthereumAddress(injectiveAddress);
|
|
61
|
-
const walletStrategy = InjectiveXService.getInstance().walletStrategy;
|
|
62
|
-
const res = await walletStrategy.signArbitrary(
|
|
63
|
-
walletStrategy.getWallet() === Wallet.Metamask ? ethereumAddress : injectiveAddress,
|
|
64
|
-
message,
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
if (!res) {
|
|
68
|
-
throw new Error('Injective signature not found');
|
|
69
|
-
}
|
|
70
|
-
signature = res;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
default:
|
|
75
|
-
console.warn('Unsupported chain type');
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return signature;
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export * from './actions';
|
|
2
|
-
export * from './core';
|
|
3
|
-
|
|
4
|
-
export * from './utils';
|
|
5
|
-
|
|
6
|
-
export * from './xchains/bitcoin';
|
|
7
|
-
export * from './xchains/evm';
|
|
8
|
-
export * from './xchains/icon';
|
|
9
|
-
export * from './xchains/injective';
|
|
10
|
-
export * from './xchains/solana';
|
|
11
|
-
export * from './xchains/stellar';
|
|
12
|
-
export * from './xchains/sui';
|
|
13
|
-
export * from './xchains/stacks';
|
|
14
|
-
export * from './hooks';
|
|
15
|
-
export * from './useXWagmiStore';
|
|
16
|
-
export * from './SodaxWalletProvider';
|
|
17
|
-
|
|
18
|
-
export * from './types';
|
|
19
|
-
export type * from './types';
|
package/src/types/index.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { ChainType } from '@sodax/types';
|
|
2
|
-
|
|
3
|
-
export type XAccount = {
|
|
4
|
-
address: string | undefined;
|
|
5
|
-
xChainType: ChainType | undefined;
|
|
6
|
-
publicKey?: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export type XConnection = {
|
|
10
|
-
xAccount: XAccount;
|
|
11
|
-
xConnectorId: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type CurrencyKey = string;
|
|
15
|
-
|
|
16
|
-
export enum WalletId {
|
|
17
|
-
METAMASK = 'metamask',
|
|
18
|
-
HANA = 'hana',
|
|
19
|
-
PHANTOM = 'phantom',
|
|
20
|
-
SUI = 'sui',
|
|
21
|
-
KEPLR = 'keplr',
|
|
22
|
-
}
|
package/src/useXWagmiStore.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import type { ChainType } from '@sodax/types';
|
|
4
|
-
import { create } from 'zustand';
|
|
5
|
-
import { createJSONStorage, persist, devtools } from 'zustand/middleware';
|
|
6
|
-
import { immer } from 'zustand/middleware/immer';
|
|
7
|
-
import type { XService } from './core';
|
|
8
|
-
import type { XConnection } from './types';
|
|
9
|
-
import { EvmXService } from './xchains/evm';
|
|
10
|
-
import { InjectiveXConnector, InjectiveXService } from './xchains/injective';
|
|
11
|
-
import { Wallet } from '@injectivelabs/wallet-base';
|
|
12
|
-
import { SolanaXService } from './xchains/solana/SolanaXService';
|
|
13
|
-
import { StellarXService } from './xchains/stellar';
|
|
14
|
-
import { SuiXService } from './xchains/sui';
|
|
15
|
-
import { IconXService } from './xchains/icon';
|
|
16
|
-
import { IconHanaXConnector } from './xchains/icon/IconHanaXConnector';
|
|
17
|
-
import { BitcoinXService } from './xchains/bitcoin';
|
|
18
|
-
import { UnisatXConnector } from './xchains/bitcoin/UnisatXConnector';
|
|
19
|
-
import { XverseXConnector } from './xchains/bitcoin/XverseXConnector';
|
|
20
|
-
import { OKXXConnector } from './xchains/bitcoin/OKXXConnector';
|
|
21
|
-
import { NearXService } from './xchains/near/NearXService';
|
|
22
|
-
import { StacksXService, StacksXConnector, STACKS_PROVIDERS } from './xchains/stacks';
|
|
23
|
-
|
|
24
|
-
type XWagmiStore = {
|
|
25
|
-
xServices: Partial<Record<ChainType, XService>>;
|
|
26
|
-
xConnections: Partial<Record<ChainType, XConnection>>;
|
|
27
|
-
|
|
28
|
-
setXConnection: (xChainType: ChainType, xConnection: XConnection) => void;
|
|
29
|
-
unsetXConnection: (xChainType: ChainType) => void;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const initXServices = () => {
|
|
33
|
-
const xServices = {};
|
|
34
|
-
['EVM', 'BITCOIN', 'INJECTIVE', 'STELLAR', 'SUI', 'SOLANA', 'ICON', 'NEAR', 'STACKS'].forEach(key => {
|
|
35
|
-
const xChainType = key as ChainType;
|
|
36
|
-
|
|
37
|
-
switch (xChainType) {
|
|
38
|
-
// EVM, SUI, Solana wallet connectors are supported by their own sdks. wagmi, @mysten/dapp-kit, @solana/wallet-adapter-react.
|
|
39
|
-
case 'EVM':
|
|
40
|
-
xServices[xChainType] = EvmXService.getInstance();
|
|
41
|
-
xServices[xChainType].setXConnectors([]);
|
|
42
|
-
break;
|
|
43
|
-
case 'SUI':
|
|
44
|
-
xServices[xChainType] = SuiXService.getInstance();
|
|
45
|
-
xServices[xChainType].setXConnectors([]);
|
|
46
|
-
break;
|
|
47
|
-
case 'SOLANA':
|
|
48
|
-
xServices[xChainType] = SolanaXService.getInstance();
|
|
49
|
-
xServices[xChainType].setXConnectors([]);
|
|
50
|
-
break;
|
|
51
|
-
case 'BITCOIN':
|
|
52
|
-
xServices[xChainType] = BitcoinXService.getInstance();
|
|
53
|
-
xServices[xChainType].setXConnectors([new UnisatXConnector(), new XverseXConnector(), new OKXXConnector()]);
|
|
54
|
-
break;
|
|
55
|
-
|
|
56
|
-
// Injective, Stellar, Icon wallet connectors are supported by sodax wallet-sdk-react sdk.
|
|
57
|
-
case 'INJECTIVE':
|
|
58
|
-
xServices[xChainType] = InjectiveXService.getInstance();
|
|
59
|
-
xServices[xChainType].setXConnectors([
|
|
60
|
-
// EVM wallets (auto-detected via EIP-6963)
|
|
61
|
-
new InjectiveXConnector('MetaMask', Wallet.Metamask),
|
|
62
|
-
// Cosmos wallets (detected via window globals)
|
|
63
|
-
new InjectiveXConnector('Keplr', Wallet.Keplr),
|
|
64
|
-
new InjectiveXConnector('Leap', Wallet.Leap),
|
|
65
|
-
]);
|
|
66
|
-
break;
|
|
67
|
-
case 'STELLAR':
|
|
68
|
-
xServices[xChainType] = StellarXService.getInstance();
|
|
69
|
-
xServices[xChainType].setXConnectors([]);
|
|
70
|
-
break;
|
|
71
|
-
case 'ICON':
|
|
72
|
-
xServices[xChainType] = IconXService.getInstance();
|
|
73
|
-
xServices[xChainType].setXConnectors([new IconHanaXConnector()]);
|
|
74
|
-
break;
|
|
75
|
-
case 'NEAR':
|
|
76
|
-
xServices[xChainType] = NearXService.getInstance();
|
|
77
|
-
xServices[xChainType].setXConnectors([]);
|
|
78
|
-
break;
|
|
79
|
-
case 'STACKS':
|
|
80
|
-
xServices[xChainType] = StacksXService.getInstance();
|
|
81
|
-
xServices[xChainType].setXConnectors(STACKS_PROVIDERS.map(config => new StacksXConnector(config)));
|
|
82
|
-
break;
|
|
83
|
-
default:
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
return xServices;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export const useXWagmiStore = create<XWagmiStore>()(
|
|
92
|
-
devtools(
|
|
93
|
-
persist(
|
|
94
|
-
immer((set, get) => ({
|
|
95
|
-
xServices: initXServices(),
|
|
96
|
-
xConnections: {},
|
|
97
|
-
setXConnection: (xChainType: ChainType, xConnection: XConnection) => {
|
|
98
|
-
set(state => {
|
|
99
|
-
state.xConnections[xChainType] = xConnection;
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
unsetXConnection: (xChainType: ChainType) => {
|
|
103
|
-
set(state => {
|
|
104
|
-
delete state.xConnections[xChainType];
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
})),
|
|
108
|
-
{
|
|
109
|
-
name: 'xwagmi-store',
|
|
110
|
-
storage: createJSONStorage(() => localStorage),
|
|
111
|
-
partialize: state => ({ xConnections: state.xConnections }),
|
|
112
|
-
},
|
|
113
|
-
),
|
|
114
|
-
{ name: 'xwagmi-store' },
|
|
115
|
-
),
|
|
116
|
-
);
|
package/src/utils/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { baseChainInfo, type ChainId, type XToken } from '@sodax/types';
|
|
2
|
-
|
|
3
|
-
export const isNativeToken = (xToken: XToken) => {
|
|
4
|
-
const nativeAddresses = [
|
|
5
|
-
'cx0000000000000000000000000000000000000000',
|
|
6
|
-
'0x0000000000000000000000000000000000000000',
|
|
7
|
-
'inj',
|
|
8
|
-
'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI',
|
|
9
|
-
'hx0000000000000000000000000000000000000000',
|
|
10
|
-
'11111111111111111111111111111111', // solana
|
|
11
|
-
'CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA', // stellar
|
|
12
|
-
'ST000000000000000000002AMW42H.nativetoken', // stacks
|
|
13
|
-
'0:0', // bitcoin
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
return nativeAddresses.includes(xToken.address);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const getWagmiChainId = (xChainId: ChainId): number => {
|
|
20
|
-
return baseChainInfo[xChainId].chainId as number;
|
|
21
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { XConnector } from '@/core';
|
|
2
|
-
import type { XAccount } from '@/types';
|
|
3
|
-
import type { IBitcoinWalletProvider } from '@sodax/types';
|
|
4
|
-
import { BitcoinXService } from './BitcoinXService';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Abstract base class for Bitcoin wallet connectors.
|
|
8
|
-
* Subclasses implement wallet-specific connection logic (Unisat, Xverse, OKX).
|
|
9
|
-
*/
|
|
10
|
-
export abstract class BitcoinXConnector extends XConnector {
|
|
11
|
-
constructor(name: string, id: string) {
|
|
12
|
-
super('BITCOIN', name, id);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
getXService(): BitcoinXService {
|
|
16
|
-
return BitcoinXService.getInstance();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
abstract connect(): Promise<XAccount | undefined>;
|
|
20
|
-
abstract disconnect(): Promise<void>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Returns an IBitcoinWalletProvider instance after connecting.
|
|
24
|
-
* Used by useSpokeProvider to build BitcoinSpokeProvider.
|
|
25
|
-
*/
|
|
26
|
-
abstract getWalletProvider(): IBitcoinWalletProvider | undefined;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Recreates a walletProvider from the browser extension window object
|
|
30
|
-
* and stored xAccount data (no connect() call, no popup).
|
|
31
|
-
* Used to restore provider after page reload without requiring reconnect.
|
|
32
|
-
*/
|
|
33
|
-
abstract recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
|
|
34
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { XService } from '@/core/XService';
|
|
2
|
-
import { isNativeToken } from '@/utils';
|
|
3
|
-
import type { XToken } from '@sodax/types';
|
|
4
|
-
|
|
5
|
-
export class BitcoinXService extends XService {
|
|
6
|
-
private static instance: BitcoinXService;
|
|
7
|
-
private rpcUrl: string;
|
|
8
|
-
|
|
9
|
-
private constructor(rpcUrl = 'https://mempool.space/api') {
|
|
10
|
-
super('BITCOIN');
|
|
11
|
-
this.rpcUrl = rpcUrl;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public static getInstance(rpcUrl?: string): BitcoinXService {
|
|
15
|
-
if (!BitcoinXService.instance) {
|
|
16
|
-
BitcoinXService.instance = new BitcoinXService(rpcUrl);
|
|
17
|
-
} else if (rpcUrl && rpcUrl !== BitcoinXService.instance.rpcUrl) {
|
|
18
|
-
BitcoinXService.instance.rpcUrl = rpcUrl;
|
|
19
|
-
}
|
|
20
|
-
return BitcoinXService.instance;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async getBalance(address: string | undefined, xToken: XToken): Promise<bigint> {
|
|
24
|
-
if (!address) return 0n;
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
if (isNativeToken(xToken)) {
|
|
28
|
-
const response = await fetch(`${this.rpcUrl}/address/${address}/utxo`);
|
|
29
|
-
if (!response.ok) return 0n;
|
|
30
|
-
const utxos: Array<{ value: number }> = await response.json();
|
|
31
|
-
const totalBalance = utxos.reduce((sum, utxo) => sum + utxo.value, 0);
|
|
32
|
-
return BigInt(totalBalance);
|
|
33
|
-
}
|
|
34
|
-
} catch {
|
|
35
|
-
return 0n;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return 0n;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import type { XAccount } from '@/types';
|
|
2
|
-
import { detectBitcoinAddressType, type IBitcoinWalletProvider, type AddressType } from '@sodax/types';
|
|
3
|
-
import { BitcoinXConnector } from './BitcoinXConnector';
|
|
4
|
-
|
|
5
|
-
// OKX Bitcoin wallet window API types
|
|
6
|
-
interface OKXBitcoinWallet {
|
|
7
|
-
getAccounts(): Promise<string[]>;
|
|
8
|
-
getPublicKey(): Promise<string>;
|
|
9
|
-
signPsbt(psbtHex: string, options?: { autoFinalized?: boolean }): Promise<string>;
|
|
10
|
-
signMessage(message: string, type?: 'bip322-simple' | 'ecdsa'): Promise<string>;
|
|
11
|
-
connect(): Promise<{ address: string; publicKey: string }>;
|
|
12
|
-
sendBitcoin(toAddress: string, satoshis: number): Promise<string>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare global {
|
|
16
|
-
interface Window {
|
|
17
|
-
okxwallet?: {
|
|
18
|
-
bitcoin?: OKXBitcoinWallet;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
class OKXWalletProvider implements IBitcoinWalletProvider {
|
|
24
|
-
private okx: OKXBitcoinWallet;
|
|
25
|
-
private cachedAddress: string;
|
|
26
|
-
|
|
27
|
-
constructor(okx: OKXBitcoinWallet, address: string) {
|
|
28
|
-
this.okx = okx;
|
|
29
|
-
this.cachedAddress = address;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async getWalletAddress(): Promise<string> {
|
|
33
|
-
try {
|
|
34
|
-
const accounts = await this.okx.getAccounts();
|
|
35
|
-
if (accounts[0]) this.cachedAddress = accounts[0];
|
|
36
|
-
} catch {
|
|
37
|
-
// wallet locked — fall through to cached address
|
|
38
|
-
}
|
|
39
|
-
return this.cachedAddress;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async getPublicKey(): Promise<string> {
|
|
43
|
-
return this.okx.getPublicKey();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async getAddressType(_address: string): Promise<AddressType> {
|
|
47
|
-
const address = await this.getWalletAddress();
|
|
48
|
-
return detectBitcoinAddressType(address);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async signTransaction(psbtBase64: string, finalize = false): Promise<string> {
|
|
52
|
-
const psbtHex = Buffer.from(psbtBase64, 'base64').toString('hex');
|
|
53
|
-
return this.okx.signPsbt(psbtHex, { autoFinalized: finalize });
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async signEcdsaMessage(message: string): Promise<string> {
|
|
57
|
-
return this.okx.signMessage(message, 'ecdsa');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async signBip322Message(message: string): Promise<string> {
|
|
61
|
-
return this.okx.signMessage(message, 'bip322-simple');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async sendBitcoin(toAddress: string, satoshis: bigint): Promise<string> {
|
|
65
|
-
if (satoshis > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
66
|
-
throw new Error(`Amount ${satoshis} satoshis exceeds safe integer range`);
|
|
67
|
-
}
|
|
68
|
-
return this.okx.sendBitcoin(toAddress, Number(satoshis));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export class OKXXConnector extends BitcoinXConnector {
|
|
73
|
-
private walletProvider: OKXWalletProvider | undefined;
|
|
74
|
-
|
|
75
|
-
constructor() {
|
|
76
|
-
super('OKX Wallet', 'okx-bitcoin');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public static isAvailable(): boolean {
|
|
80
|
-
return typeof window !== 'undefined' && !!window.okxwallet?.bitcoin;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public get icon(): string {
|
|
84
|
-
return 'https://static.okx.com/cdn/assets/imgs/247/58E63FEA47A2B7D7.png';
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async connect(): Promise<XAccount | undefined> {
|
|
88
|
-
const okx = window.okxwallet?.bitcoin;
|
|
89
|
-
if (!okx) {
|
|
90
|
-
throw new Error('OKX wallet is not installed');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const { address } = await okx.connect();
|
|
94
|
-
if (!address) return undefined;
|
|
95
|
-
|
|
96
|
-
this.walletProvider = new OKXWalletProvider(okx, address);
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
address,
|
|
100
|
-
xChainType: 'BITCOIN',
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async disconnect(): Promise<void> {
|
|
105
|
-
this.walletProvider = undefined;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
getWalletProvider(): IBitcoinWalletProvider | undefined {
|
|
109
|
-
return this.walletProvider;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined {
|
|
113
|
-
const okx = window.okxwallet?.bitcoin;
|
|
114
|
-
if (!okx || !xAccount.address) return undefined;
|
|
115
|
-
return new OKXWalletProvider(okx, xAccount.address);
|
|
116
|
-
}
|
|
117
|
-
}
|