@sodax/wallet-sdk-react 1.5.1-beta → 1.5.3-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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sodax/wallet-sdk-react",
3
3
  "license": "MIT",
4
- "version": "1.5.1-beta",
4
+ "version": "1.5.3-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.16.10",
32
- "@injectivelabs/sdk-ts": "1.16.10",
33
- "@injectivelabs/ts-types": "1.16.10",
34
- "@injectivelabs/wallet-base": "1.16.10",
35
- "@injectivelabs/wallet-core": "1.16.10",
36
- "@injectivelabs/wallet-cosmos": "1.16.10",
37
- "@injectivelabs/wallet-evm": "1.16.10",
38
- "@injectivelabs/wallet-strategy": "1.16.10",
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/types": "1.5.1-beta",
55
- "@sodax/wallet-sdk-core": "1.5.1-beta"
54
+ "@sodax/types": "1.5.3-beta",
55
+ "@sodax/wallet-sdk-core": "1.5.3-beta"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/react": "^19.0.8",
@@ -22,6 +22,7 @@ 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';
27
28
  import type { State as WagmiState } from 'wagmi';
@@ -92,5 +93,5 @@ export const SodaxWalletProvider = ({ children, rpcConfig, options, initialState
92
93
  };
93
94
 
94
95
  reconnectIcon();
95
- // reconnectInjective();
96
+ reconnectInjective();
96
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
- const chainId = await walletStrategy.getEthereumChainId();
28
- setEthereumChainId(Number.parseInt(chainId));
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
- (walletStrategy.getStrategy() as EvmWalletStrategy).onChainIdChanged(getEthereumChainId);
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;
@@ -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 { InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService } from './xchains/injective';
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([new InjectiveMetamaskXConnector(), new InjectiveKelprXConnector()]);
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();
@@ -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: addresses?.[0],
25
+ address,
19
26
  xChainType: 'INJECTIVE',
20
27
  },
21
28
  xConnectorId: recentXConnectorId,
@@ -1,4 +1,2 @@
1
1
  export { InjectiveXService } from './InjectiveXService';
2
- export { InjectiveKelprXConnector } from './InjectiveKelprXConnector';
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
- };