@sodax/wallet-sdk-react 1.5.0-beta → 1.5.2-beta
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.cjs +79 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +974 -17
- package/dist/index.d.ts +974 -17
- package/dist/index.mjs +81 -73
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
- package/src/SodaxWalletProvider.tsx +6 -3
- package/src/hooks/useEthereumChainId.ts +11 -3
- package/src/useXWagmiStore.ts +10 -7
- package/src/xchains/evm/EvmXService.ts +5 -1
- package/src/xchains/evm/index.ts +1 -0
- package/src/xchains/injective/InjectiveXConnector.ts +60 -0
- package/src/xchains/injective/actions.ts +9 -2
- package/src/xchains/injective/index.ts +1 -3
- package/src/xchains/injective/InjectiveKelprXConnector.ts +0 -37
- package/src/xchains/injective/InjectiveMetamaskXConnector.ts +0 -40
- package/src/xchains/injective/utils.ts +0 -17
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sodax/wallet-sdk-react",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.2-beta",
|
|
5
5
|
"description": "Wallet SDK of Sodax",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
"@stacks/transactions": "7.3.1",
|
|
29
29
|
"@creit.tech/stellar-wallets-kit": "^1.7.5",
|
|
30
30
|
"@hot-labs/near-connect": "0.10.0",
|
|
31
|
-
"@injectivelabs/networks": "1.
|
|
32
|
-
"@injectivelabs/sdk-ts": "1.
|
|
33
|
-
"@injectivelabs/ts-types": "1.
|
|
34
|
-
"@injectivelabs/wallet-base": "1.
|
|
35
|
-
"@injectivelabs/wallet-core": "1.
|
|
36
|
-
"@injectivelabs/wallet-cosmos": "1.
|
|
37
|
-
"@injectivelabs/wallet-evm": "1.
|
|
38
|
-
"@injectivelabs/wallet-strategy": "1.
|
|
31
|
+
"@injectivelabs/networks": "1.18.14",
|
|
32
|
+
"@injectivelabs/sdk-ts": "1.18.14",
|
|
33
|
+
"@injectivelabs/ts-types": "1.18.14",
|
|
34
|
+
"@injectivelabs/wallet-base": "1.18.14",
|
|
35
|
+
"@injectivelabs/wallet-core": "1.18.14",
|
|
36
|
+
"@injectivelabs/wallet-cosmos": "1.18.14",
|
|
37
|
+
"@injectivelabs/wallet-evm": "1.18.14",
|
|
38
|
+
"@injectivelabs/wallet-strategy": "1.18.14",
|
|
39
39
|
"@mysten/dapp-kit": "0.14.18",
|
|
40
40
|
"@mysten/sui": "1.21.2",
|
|
41
41
|
"near-api-js": "7.2.0",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"wagmi": "2.16.9",
|
|
52
52
|
"zustand": "4.5.2",
|
|
53
53
|
"bs58": "6.0.0",
|
|
54
|
-
"@sodax/
|
|
55
|
-
"@sodax/
|
|
54
|
+
"@sodax/types": "1.5.2-beta",
|
|
55
|
+
"@sodax/wallet-sdk-core": "1.5.2-beta"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/react": "^19.0.8",
|
|
@@ -22,8 +22,10 @@ import type { RpcConfig } from '@sodax/types';
|
|
|
22
22
|
import { Hydrate } from './Hydrate';
|
|
23
23
|
import { createWagmiConfig } from './xchains/evm/EvmXService';
|
|
24
24
|
import { reconnectIcon } from './xchains/icon/actions';
|
|
25
|
+
import { reconnectInjective } from './xchains/injective/actions';
|
|
25
26
|
import { reconnectStellar } from './xchains/stellar/actions';
|
|
26
27
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
28
|
+
import type { State as WagmiState } from 'wagmi';
|
|
27
29
|
|
|
28
30
|
const queryClient = new QueryClient();
|
|
29
31
|
|
|
@@ -59,9 +61,10 @@ export type SodaxWalletProviderProps = {
|
|
|
59
61
|
children: React.ReactNode;
|
|
60
62
|
rpcConfig: RpcConfig;
|
|
61
63
|
options?: SodaxWalletProviderOptions;
|
|
64
|
+
initialState?: WagmiState;
|
|
62
65
|
};
|
|
63
66
|
|
|
64
|
-
export const SodaxWalletProvider = ({ children, rpcConfig, options }: SodaxWalletProviderProps) => {
|
|
67
|
+
export const SodaxWalletProvider = ({ children, rpcConfig, options, initialState }: SodaxWalletProviderProps) => {
|
|
65
68
|
const wagmi = useMemo(() => ({ ...defaultOptions.wagmi, ...options?.wagmi }), [options?.wagmi]);
|
|
66
69
|
const wagmiConfig = useMemo(() => {
|
|
67
70
|
return createWagmiConfig(rpcConfig, wagmi);
|
|
@@ -73,7 +76,7 @@ export const SodaxWalletProvider = ({ children, rpcConfig, options }: SodaxWalle
|
|
|
73
76
|
|
|
74
77
|
return (
|
|
75
78
|
<QueryClientProvider client={queryClient}>
|
|
76
|
-
<WagmiProvider reconnectOnMount={wagmi.reconnectOnMount} config={wagmiConfig}>
|
|
79
|
+
<WagmiProvider reconnectOnMount={wagmi.reconnectOnMount} config={wagmiConfig} initialState={initialState}>
|
|
77
80
|
<SuiClientProvider networks={{ mainnet: { url: getFullnodeUrl('mainnet') } }} defaultNetwork="mainnet">
|
|
78
81
|
<SuiWalletProvider autoConnect={sui.autoConnect}>
|
|
79
82
|
<SolanaConnectionProvider endpoint={rpcConfig['solana'] ?? 'https://api.mainnet-beta.solana.com'}>
|
|
@@ -90,5 +93,5 @@ export const SodaxWalletProvider = ({ children, rpcConfig, options }: SodaxWalle
|
|
|
90
93
|
};
|
|
91
94
|
|
|
92
95
|
reconnectIcon();
|
|
93
|
-
|
|
96
|
+
reconnectInjective();
|
|
94
97
|
reconnectStellar();
|
|
@@ -24,12 +24,20 @@ export default function useEthereumChainId(): number | null {
|
|
|
24
24
|
if (walletStrategy.getWallet() !== Wallet.Metamask) return;
|
|
25
25
|
|
|
26
26
|
const getEthereumChainId = async () => {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
try {
|
|
28
|
+
const chainId = await walletStrategy.getEthereumChainId();
|
|
29
|
+
setEthereumChainId(Number.parseInt(chainId));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
console.warn('Failed to get Ethereum chain ID:', e);
|
|
32
|
+
}
|
|
29
33
|
};
|
|
30
34
|
getEthereumChainId();
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
try {
|
|
37
|
+
(walletStrategy.getStrategy() as EvmWalletStrategy).onChainIdChanged(getEthereumChainId);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.warn('Failed to subscribe to chain ID changes:', e);
|
|
40
|
+
}
|
|
33
41
|
}, [injectiveXService?.walletStrategy]);
|
|
34
42
|
|
|
35
43
|
return ethereumChainId;
|
package/src/useXWagmiStore.ts
CHANGED
|
@@ -7,7 +7,8 @@ import { immer } from 'zustand/middleware/immer';
|
|
|
7
7
|
import type { XService } from './core';
|
|
8
8
|
import type { XConnection } from './types';
|
|
9
9
|
import { EvmXService } from './xchains/evm';
|
|
10
|
-
import {
|
|
10
|
+
import { InjectiveXConnector, InjectiveXService } from './xchains/injective';
|
|
11
|
+
import { Wallet } from '@injectivelabs/wallet-base';
|
|
11
12
|
import { SolanaXService } from './xchains/solana/SolanaXService';
|
|
12
13
|
import { StellarXService } from './xchains/stellar';
|
|
13
14
|
import { SuiXService } from './xchains/sui';
|
|
@@ -49,17 +50,19 @@ const initXServices = () => {
|
|
|
49
50
|
break;
|
|
50
51
|
case 'BITCOIN':
|
|
51
52
|
xServices[xChainType] = BitcoinXService.getInstance();
|
|
52
|
-
xServices[xChainType].setXConnectors([
|
|
53
|
-
new UnisatXConnector(),
|
|
54
|
-
new XverseXConnector(),
|
|
55
|
-
new OKXXConnector(),
|
|
56
|
-
]);
|
|
53
|
+
xServices[xChainType].setXConnectors([new UnisatXConnector(), new XverseXConnector(), new OKXXConnector()]);
|
|
57
54
|
break;
|
|
58
55
|
|
|
59
56
|
// Injective, Stellar, Icon wallet connectors are supported by sodax wallet-sdk-react sdk.
|
|
60
57
|
case 'INJECTIVE':
|
|
61
58
|
xServices[xChainType] = InjectiveXService.getInstance();
|
|
62
|
-
xServices[xChainType].setXConnectors([
|
|
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
|
+
]);
|
|
63
66
|
break;
|
|
64
67
|
case 'STELLAR':
|
|
65
68
|
xServices[xChainType] = StellarXService.getInstance();
|
|
@@ -19,7 +19,7 @@ import { getWagmiChainId, isNativeToken } from '@/utils';
|
|
|
19
19
|
|
|
20
20
|
import { type Address, type Chain, defineChain, erc20Abi } from 'viem';
|
|
21
21
|
import { getPublicClient } from 'wagmi/actions';
|
|
22
|
-
import { type Config, createConfig, http } from 'wagmi';
|
|
22
|
+
import { type Config, createConfig, http, createStorage, cookieStorage } from 'wagmi';
|
|
23
23
|
import {
|
|
24
24
|
mainnet,
|
|
25
25
|
avalanche,
|
|
@@ -92,6 +92,10 @@ export const createWagmiConfig = (config: RpcConfig, options?: WagmiOptions) =>
|
|
|
92
92
|
[redbellyMainnet.id]: http(config[REDBELLY_MAINNET_CHAIN_ID]),
|
|
93
93
|
[kaia.id]: http(config[KAIA_MAINNET_CHAIN_ID]),
|
|
94
94
|
},
|
|
95
|
+
storage: createStorage({
|
|
96
|
+
storage: cookieStorage,
|
|
97
|
+
key: 'sodax',
|
|
98
|
+
}),
|
|
95
99
|
});
|
|
96
100
|
};
|
|
97
101
|
|
package/src/xchains/evm/index.ts
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { XAccount } from '@/types';
|
|
2
|
+
import { XConnector } from '@/core';
|
|
3
|
+
import { getInjectiveAddress } from '@injectivelabs/sdk-ts';
|
|
4
|
+
import { type Wallet, isEvmBrowserWallet, isCosmosBrowserWallet } from '@injectivelabs/wallet-base';
|
|
5
|
+
import { isCosmosWalletInstalled } from '@injectivelabs/wallet-cosmos';
|
|
6
|
+
import { InjectiveXService } from './InjectiveXService';
|
|
7
|
+
|
|
8
|
+
const WALLET_ICONS: Partial<Record<Wallet, string>> = {
|
|
9
|
+
metamask: 'https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/metamask.svg',
|
|
10
|
+
keplr: 'https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/keplr.svg',
|
|
11
|
+
leap: 'https://assets.leapwallet.io/logos/leap-cosmos-logo.svg',
|
|
12
|
+
rabby: 'https://raw.githubusercontent.com/RabbyHub/logo/master/symbol.svg',
|
|
13
|
+
phantom: 'https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/phantom.svg',
|
|
14
|
+
'okx-wallet': 'https://static.okx.com/cdn/assets/imgs/247/58E63FEA47A2B7D7.png',
|
|
15
|
+
'trust-wallet': 'https://trustwallet.com/assets/images/media/assets/twLogo.svg',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export class InjectiveXConnector extends XConnector {
|
|
19
|
+
private wallet: Wallet;
|
|
20
|
+
|
|
21
|
+
constructor(name: string, wallet: Wallet) {
|
|
22
|
+
super('INJECTIVE', name, wallet);
|
|
23
|
+
this.wallet = wallet;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getXService(): InjectiveXService {
|
|
27
|
+
return InjectiveXService.getInstance();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async connect(): Promise<XAccount | undefined> {
|
|
31
|
+
if (isCosmosBrowserWallet(this.wallet) && !isCosmosWalletInstalled(this.wallet)) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const walletStrategy = this.getXService().walletStrategy;
|
|
36
|
+
await walletStrategy.setWallet(this.wallet);
|
|
37
|
+
const addresses = await walletStrategy.getAddresses();
|
|
38
|
+
|
|
39
|
+
if (!addresses?.length) return undefined;
|
|
40
|
+
|
|
41
|
+
const address = isEvmBrowserWallet(this.wallet) ? getInjectiveAddress(addresses[0]) : addresses[0];
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
address,
|
|
45
|
+
xChainType: this.xChainType,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async disconnect(): Promise<void> {
|
|
50
|
+
if (isEvmBrowserWallet(this.wallet)) {
|
|
51
|
+
const walletStrategy = this.getXService().walletStrategy;
|
|
52
|
+
await walletStrategy.setWallet(this.wallet);
|
|
53
|
+
await walletStrategy.disconnect();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public get icon(): string | undefined {
|
|
58
|
+
return WALLET_ICONS[this.wallet];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useXWagmiStore } from '@/useXWagmiStore';
|
|
2
2
|
import { InjectiveXService } from './InjectiveXService';
|
|
3
|
+
import { isEvmBrowserWallet } from '@injectivelabs/wallet-base';
|
|
4
|
+
import { getInjectiveAddress } from '@injectivelabs/sdk-ts';
|
|
3
5
|
import type { Wallet } from '@injectivelabs/wallet-base';
|
|
4
6
|
|
|
5
7
|
export const reconnectInjective = async () => {
|
|
@@ -8,14 +10,19 @@ export const reconnectInjective = async () => {
|
|
|
8
10
|
|
|
9
11
|
const recentXConnectorId = injectiveConnection.xConnectorId;
|
|
10
12
|
const walletStrategy = InjectiveXService.getInstance().walletStrategy;
|
|
11
|
-
walletStrategy.setWallet(recentXConnectorId as Wallet);
|
|
13
|
+
await walletStrategy.setWallet(recentXConnectorId as Wallet);
|
|
12
14
|
const addresses = await walletStrategy.getAddresses();
|
|
15
|
+
|
|
16
|
+
const address = isEvmBrowserWallet(recentXConnectorId as Wallet)
|
|
17
|
+
? getInjectiveAddress(addresses?.[0])
|
|
18
|
+
: addresses?.[0];
|
|
19
|
+
|
|
13
20
|
useXWagmiStore.setState({
|
|
14
21
|
xConnections: {
|
|
15
22
|
...useXWagmiStore.getState().xConnections,
|
|
16
23
|
INJECTIVE: {
|
|
17
24
|
xAccount: {
|
|
18
|
-
address
|
|
25
|
+
address,
|
|
19
26
|
xChainType: 'INJECTIVE',
|
|
20
27
|
},
|
|
21
28
|
xConnectorId: recentXConnectorId,
|
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
export { InjectiveXService } from './InjectiveXService';
|
|
2
|
-
export {
|
|
3
|
-
export { InjectiveMetamaskXConnector } from './InjectiveMetamaskXConnector';
|
|
4
|
-
export * from './utils';
|
|
2
|
+
export { InjectiveXConnector } from './InjectiveXConnector';
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { XAccount } from '@/types';
|
|
2
|
-
|
|
3
|
-
import { XConnector } from '@/core';
|
|
4
|
-
import { Wallet } from '@injectivelabs/wallet-base';
|
|
5
|
-
import { isCosmosWalletInstalled } from '@injectivelabs/wallet-cosmos';
|
|
6
|
-
import { InjectiveXService } from './InjectiveXService';
|
|
7
|
-
|
|
8
|
-
export class InjectiveKelprXConnector extends XConnector {
|
|
9
|
-
constructor() {
|
|
10
|
-
super('INJECTIVE', 'Keplr', Wallet.Keplr);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
getXService(): InjectiveXService {
|
|
14
|
-
return InjectiveXService.getInstance();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async connect(): Promise<XAccount | undefined> {
|
|
18
|
-
if (!isCosmosWalletInstalled(Wallet.Keplr)) {
|
|
19
|
-
window.open('https://chrome.google.com/webstore/detail/keplr/dmkamcknogkgcdfhhbddcghachkejeap?hl=en', '_blank');
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
this.getXService().walletStrategy.setWallet(Wallet.Keplr);
|
|
24
|
-
const addresses = await this.getXService().walletStrategy.getAddresses();
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
address: addresses?.[0],
|
|
28
|
-
xChainType: this.xChainType,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async disconnect(): Promise<void> {}
|
|
33
|
-
|
|
34
|
-
public get icon() {
|
|
35
|
-
return 'https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/keplr.svg';
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { XAccount } from '@/types';
|
|
2
|
-
|
|
3
|
-
import { XConnector } from '@/core';
|
|
4
|
-
import { getInjectiveAddress } from '@injectivelabs/sdk-ts';
|
|
5
|
-
import { isEvmBrowserWallet, Wallet } from '@injectivelabs/wallet-base';
|
|
6
|
-
import { InjectiveXService } from './InjectiveXService';
|
|
7
|
-
|
|
8
|
-
export class InjectiveMetamaskXConnector extends XConnector {
|
|
9
|
-
constructor() {
|
|
10
|
-
super('INJECTIVE', 'MetaMask', Wallet.Metamask);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
getXService(): InjectiveXService {
|
|
14
|
-
return InjectiveXService.getInstance();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async connect(): Promise<XAccount | undefined> {
|
|
18
|
-
if (!isEvmBrowserWallet(Wallet.Metamask)) {
|
|
19
|
-
window.open('https://chromewebstore.google.com/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en', '_blank');
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
this.getXService().walletStrategy.setWallet(Wallet.Metamask);
|
|
24
|
-
const addresses = await this.getXService().walletStrategy.getAddresses();
|
|
25
|
-
const injectiveAddresses = addresses.map(getInjectiveAddress);
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
address: injectiveAddresses?.[0],
|
|
29
|
-
xChainType: this.xChainType,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async disconnect(): Promise<void> {
|
|
34
|
-
await this.getXService().walletStrategy.disconnect();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public get icon() {
|
|
38
|
-
return 'https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/metamask.svg';
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const switchEthereumChain = async chainId => {
|
|
2
|
-
const metamaskProvider = (window as any).ethereum as any;
|
|
3
|
-
|
|
4
|
-
await Promise.race([
|
|
5
|
-
metamaskProvider.request({
|
|
6
|
-
method: 'wallet_switchEthereumChain',
|
|
7
|
-
params: [{ chainId: `0x${chainId}` }],
|
|
8
|
-
}),
|
|
9
|
-
new Promise<void>(resolve =>
|
|
10
|
-
metamaskProvider.on('change', ({ chain }: any) => {
|
|
11
|
-
if (chain?.id === chainId) {
|
|
12
|
-
resolve();
|
|
13
|
-
}
|
|
14
|
-
}),
|
|
15
|
-
),
|
|
16
|
-
]);
|
|
17
|
-
};
|