@sodax/wallet-sdk-react 1.5.1-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.d.cts CHANGED
@@ -11,6 +11,7 @@ import { IconService } from 'icon-sdk-js';
11
11
  import { IndexerGrpcAccountPortfolioApi, ChainGrpcWasmApi } from '@injectivelabs/sdk-ts';
12
12
  import { MsgBroadcaster } from '@injectivelabs/wallet-core';
13
13
  import { WalletStrategy } from '@injectivelabs/wallet-strategy';
14
+ import { Wallet } from '@injectivelabs/wallet-base';
14
15
  import { Connection } from '@solana/web3.js';
15
16
  import { WalletContextState } from '@solana/wallet-adapter-react';
16
17
  import { StellarWalletsKit } from '@creit.tech/stellar-wallets-kit';
@@ -1276,24 +1277,15 @@ declare class InjectiveXService extends XService {
1276
1277
  getBalance(address: string | undefined, xToken: XToken): Promise<bigint>;
1277
1278
  }
1278
1279
 
1279
- declare class InjectiveKelprXConnector extends XConnector {
1280
- constructor();
1280
+ declare class InjectiveXConnector extends XConnector {
1281
+ private wallet;
1282
+ constructor(name: string, wallet: Wallet);
1281
1283
  getXService(): InjectiveXService;
1282
1284
  connect(): Promise<XAccount | undefined>;
1283
1285
  disconnect(): Promise<void>;
1284
- get icon(): string;
1285
- }
1286
-
1287
- declare class InjectiveMetamaskXConnector extends XConnector {
1288
- constructor();
1289
- getXService(): InjectiveXService;
1290
- connect(): Promise<XAccount | undefined>;
1291
- disconnect(): Promise<void>;
1292
- get icon(): string;
1286
+ get icon(): string | undefined;
1293
1287
  }
1294
1288
 
1295
- declare const switchEthereumChain: (chainId: any) => Promise<void>;
1296
-
1297
1289
  declare class SolanaXService extends XService {
1298
1290
  private static instance;
1299
1291
  connection: Connection | undefined;
@@ -1584,4 +1576,4 @@ declare const useXWagmiStore: zustand.UseBoundStore<Omit<Omit<Omit<zustand.Store
1584
1576
  } | undefined): void;
1585
1577
  }>;
1586
1578
 
1587
- export { BitcoinXConnector, BitcoinXService, type CurrencyKey, EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService, OKXXConnector, STACKS_PROVIDERS, SodaxWalletProvider, type SodaxWalletProviderOptions, type SodaxWalletProviderProps, SolanaXConnector, SolanaXService, type StacksProviderConfig, StacksXConnector, StacksXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, UnisatXConnector, type WagmiOptions, WalletId, type XAccount, type XConnection, XConnector, XService, XverseXConnector, createWagmiConfig as createWagmi, createWagmiConfig, getWagmiChainId, getXChainType, getXService, isNativeToken, switchEthereumChain, useBitcoinXConnectors, useEvmSwitchChain, useStacksXConnectors, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };
1579
+ export { BitcoinXConnector, BitcoinXService, type CurrencyKey, EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveXConnector, InjectiveXService, OKXXConnector, STACKS_PROVIDERS, SodaxWalletProvider, type SodaxWalletProviderOptions, type SodaxWalletProviderProps, SolanaXConnector, SolanaXService, type StacksProviderConfig, StacksXConnector, StacksXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, UnisatXConnector, type WagmiOptions, WalletId, type XAccount, type XConnection, XConnector, XService, XverseXConnector, createWagmiConfig as createWagmi, createWagmiConfig, getWagmiChainId, getXChainType, getXService, isNativeToken, useBitcoinXConnectors, useEvmSwitchChain, useStacksXConnectors, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ import { IconService } from 'icon-sdk-js';
11
11
  import { IndexerGrpcAccountPortfolioApi, ChainGrpcWasmApi } from '@injectivelabs/sdk-ts';
12
12
  import { MsgBroadcaster } from '@injectivelabs/wallet-core';
13
13
  import { WalletStrategy } from '@injectivelabs/wallet-strategy';
14
+ import { Wallet } from '@injectivelabs/wallet-base';
14
15
  import { Connection } from '@solana/web3.js';
15
16
  import { WalletContextState } from '@solana/wallet-adapter-react';
16
17
  import { StellarWalletsKit } from '@creit.tech/stellar-wallets-kit';
@@ -1276,24 +1277,15 @@ declare class InjectiveXService extends XService {
1276
1277
  getBalance(address: string | undefined, xToken: XToken): Promise<bigint>;
1277
1278
  }
1278
1279
 
1279
- declare class InjectiveKelprXConnector extends XConnector {
1280
- constructor();
1280
+ declare class InjectiveXConnector extends XConnector {
1281
+ private wallet;
1282
+ constructor(name: string, wallet: Wallet);
1281
1283
  getXService(): InjectiveXService;
1282
1284
  connect(): Promise<XAccount | undefined>;
1283
1285
  disconnect(): Promise<void>;
1284
- get icon(): string;
1285
- }
1286
-
1287
- declare class InjectiveMetamaskXConnector extends XConnector {
1288
- constructor();
1289
- getXService(): InjectiveXService;
1290
- connect(): Promise<XAccount | undefined>;
1291
- disconnect(): Promise<void>;
1292
- get icon(): string;
1286
+ get icon(): string | undefined;
1293
1287
  }
1294
1288
 
1295
- declare const switchEthereumChain: (chainId: any) => Promise<void>;
1296
-
1297
1289
  declare class SolanaXService extends XService {
1298
1290
  private static instance;
1299
1291
  connection: Connection | undefined;
@@ -1584,4 +1576,4 @@ declare const useXWagmiStore: zustand.UseBoundStore<Omit<Omit<Omit<zustand.Store
1584
1576
  } | undefined): void;
1585
1577
  }>;
1586
1578
 
1587
- export { BitcoinXConnector, BitcoinXService, type CurrencyKey, EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService, OKXXConnector, STACKS_PROVIDERS, SodaxWalletProvider, type SodaxWalletProviderOptions, type SodaxWalletProviderProps, SolanaXConnector, SolanaXService, type StacksProviderConfig, StacksXConnector, StacksXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, UnisatXConnector, type WagmiOptions, WalletId, type XAccount, type XConnection, XConnector, XService, XverseXConnector, createWagmiConfig as createWagmi, createWagmiConfig, getWagmiChainId, getXChainType, getXService, isNativeToken, switchEthereumChain, useBitcoinXConnectors, useEvmSwitchChain, useStacksXConnectors, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };
1579
+ export { BitcoinXConnector, BitcoinXService, type CurrencyKey, EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveXConnector, InjectiveXService, OKXXConnector, STACKS_PROVIDERS, SodaxWalletProvider, type SodaxWalletProviderOptions, type SodaxWalletProviderProps, SolanaXConnector, SolanaXService, type StacksProviderConfig, StacksXConnector, StacksXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, UnisatXConnector, type WagmiOptions, WalletId, type XAccount, type XConnection, XConnector, XService, XverseXConnector, createWagmiConfig as createWagmi, createWagmiConfig, getWagmiChainId, getXChainType, getXService, isNativeToken, useBitcoinXConnectors, useEvmSwitchChain, useStacksXConnectors, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };
package/dist/index.mjs CHANGED
@@ -15,11 +15,11 @@ import { erc20Abi, defineChain } from 'viem';
15
15
  import { getPublicClient } from 'wagmi/actions';
16
16
  import { mainnet, avalanche, arbitrum, base, bsc, sonic, optimism, polygon, lightlinkPhoenix, kaia, redbellyMainnet } from 'wagmi/chains';
17
17
  import { getNetworkEndpoints, Network } from '@injectivelabs/networks';
18
- import { IndexerGrpcAccountPortfolioApi, ChainGrpcWasmApi, getInjectiveAddress, getEthereumAddress } from '@injectivelabs/sdk-ts';
18
+ import { getInjectiveAddress, IndexerGrpcAccountPortfolioApi, ChainGrpcWasmApi, getEthereumAddress } from '@injectivelabs/sdk-ts';
19
19
  import { ChainId } from '@injectivelabs/ts-types';
20
20
  import { MsgBroadcaster } from '@injectivelabs/wallet-core';
21
21
  import { WalletStrategy } from '@injectivelabs/wallet-strategy';
22
- import { Wallet, isEvmBrowserWallet } from '@injectivelabs/wallet-base';
22
+ import { Wallet, isEvmBrowserWallet, isCosmosBrowserWallet } from '@injectivelabs/wallet-base';
23
23
  import { isCosmosWalletInstalled } from '@injectivelabs/wallet-cosmos';
24
24
  import { PublicKey } from '@solana/web3.js';
25
25
  import { getAssociatedTokenAddressSync, getAccount } from '@solana/spl-token';
@@ -767,76 +767,48 @@ var InjectiveXService = class _InjectiveXService extends XService {
767
767
  return 0n;
768
768
  }
769
769
  };
770
- var InjectiveKelprXConnector = class extends XConnector {
771
- constructor() {
772
- super("INJECTIVE", "Keplr", Wallet.Keplr);
773
- }
774
- getXService() {
775
- return InjectiveXService.getInstance();
776
- }
777
- async connect() {
778
- if (!isCosmosWalletInstalled(Wallet.Keplr)) {
779
- window.open("https://chrome.google.com/webstore/detail/keplr/dmkamcknogkgcdfhhbddcghachkejeap?hl=en", "_blank");
780
- return;
781
- }
782
- this.getXService().walletStrategy.setWallet(Wallet.Keplr);
783
- const addresses = await this.getXService().walletStrategy.getAddresses();
784
- return {
785
- address: addresses?.[0],
786
- xChainType: this.xChainType
787
- };
788
- }
789
- async disconnect() {
790
- }
791
- get icon() {
792
- return "https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/keplr.svg";
793
- }
770
+ var WALLET_ICONS = {
771
+ metamask: "https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/metamask.svg",
772
+ keplr: "https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/keplr.svg",
773
+ leap: "https://assets.leapwallet.io/logos/leap-cosmos-logo.svg",
774
+ rabby: "https://raw.githubusercontent.com/RabbyHub/logo/master/symbol.svg",
775
+ phantom: "https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/phantom.svg",
776
+ "okx-wallet": "https://static.okx.com/cdn/assets/imgs/247/58E63FEA47A2B7D7.png",
777
+ "trust-wallet": "https://trustwallet.com/assets/images/media/assets/twLogo.svg"
794
778
  };
795
- var InjectiveMetamaskXConnector = class extends XConnector {
796
- constructor() {
797
- super("INJECTIVE", "MetaMask", Wallet.Metamask);
779
+ var InjectiveXConnector = class extends XConnector {
780
+ constructor(name, wallet) {
781
+ super("INJECTIVE", name, wallet);
782
+ this.wallet = wallet;
798
783
  }
799
784
  getXService() {
800
785
  return InjectiveXService.getInstance();
801
786
  }
802
787
  async connect() {
803
- if (!isEvmBrowserWallet(Wallet.Metamask)) {
804
- window.open("https://chromewebstore.google.com/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en", "_blank");
805
- return;
788
+ if (isCosmosBrowserWallet(this.wallet) && !isCosmosWalletInstalled(this.wallet)) {
789
+ return void 0;
806
790
  }
807
- this.getXService().walletStrategy.setWallet(Wallet.Metamask);
808
- const addresses = await this.getXService().walletStrategy.getAddresses();
809
- const injectiveAddresses = addresses.map(getInjectiveAddress);
791
+ const walletStrategy = this.getXService().walletStrategy;
792
+ await walletStrategy.setWallet(this.wallet);
793
+ const addresses = await walletStrategy.getAddresses();
794
+ if (!addresses?.length) return void 0;
795
+ const address = isEvmBrowserWallet(this.wallet) ? getInjectiveAddress(addresses[0]) : addresses[0];
810
796
  return {
811
- address: injectiveAddresses?.[0],
797
+ address,
812
798
  xChainType: this.xChainType
813
799
  };
814
800
  }
815
801
  async disconnect() {
816
- await this.getXService().walletStrategy.disconnect();
802
+ if (isEvmBrowserWallet(this.wallet)) {
803
+ const walletStrategy = this.getXService().walletStrategy;
804
+ await walletStrategy.setWallet(this.wallet);
805
+ await walletStrategy.disconnect();
806
+ }
817
807
  }
818
808
  get icon() {
819
- return "https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/metamask.svg";
809
+ return WALLET_ICONS[this.wallet];
820
810
  }
821
811
  };
822
-
823
- // src/xchains/injective/utils.ts
824
- var switchEthereumChain = async (chainId) => {
825
- const metamaskProvider = window.ethereum;
826
- await Promise.race([
827
- metamaskProvider.request({
828
- method: "wallet_switchEthereumChain",
829
- params: [{ chainId: `0x${chainId}` }]
830
- }),
831
- new Promise(
832
- (resolve) => metamaskProvider.on("change", ({ chain }) => {
833
- if (chain?.id === chainId) {
834
- resolve();
835
- }
836
- })
837
- )
838
- ]);
839
- };
840
812
  var SolanaXService = class _SolanaXService extends XService {
841
813
  constructor() {
842
814
  super("SOLANA");
@@ -1311,16 +1283,18 @@ var initXServices = () => {
1311
1283
  break;
1312
1284
  case "BITCOIN":
1313
1285
  xServices[xChainType] = BitcoinXService.getInstance();
1314
- xServices[xChainType].setXConnectors([
1315
- new UnisatXConnector(),
1316
- new XverseXConnector(),
1317
- new OKXXConnector()
1318
- ]);
1286
+ xServices[xChainType].setXConnectors([new UnisatXConnector(), new XverseXConnector(), new OKXXConnector()]);
1319
1287
  break;
1320
1288
  // Injective, Stellar, Icon wallet connectors are supported by sodax wallet-sdk-react sdk.
1321
1289
  case "INJECTIVE":
1322
1290
  xServices[xChainType] = InjectiveXService.getInstance();
1323
- xServices[xChainType].setXConnectors([new InjectiveMetamaskXConnector(), new InjectiveKelprXConnector()]);
1291
+ xServices[xChainType].setXConnectors([
1292
+ // EVM wallets (auto-detected via EIP-6963)
1293
+ new InjectiveXConnector("MetaMask", Wallet.Metamask),
1294
+ // Cosmos wallets (detected via window globals)
1295
+ new InjectiveXConnector("Keplr", Wallet.Keplr),
1296
+ new InjectiveXConnector("Leap", Wallet.Leap)
1297
+ ]);
1324
1298
  break;
1325
1299
  case "STELLAR":
1326
1300
  xServices[xChainType] = StellarXService.getInstance();
@@ -1722,15 +1696,23 @@ function useEthereumChainId() {
1722
1696
  const walletStrategy = injectiveXService.walletStrategy;
1723
1697
  if (walletStrategy.getWallet() !== Wallet.Metamask) return;
1724
1698
  const getEthereumChainId = async () => {
1725
- const chainId = await walletStrategy.getEthereumChainId();
1726
- setEthereumChainId(Number.parseInt(chainId));
1699
+ try {
1700
+ const chainId = await walletStrategy.getEthereumChainId();
1701
+ setEthereumChainId(Number.parseInt(chainId));
1702
+ } catch (e) {
1703
+ console.warn("Failed to get Ethereum chain ID:", e);
1704
+ }
1727
1705
  };
1728
1706
  getEthereumChainId();
1729
- walletStrategy.getStrategy().onChainIdChanged(getEthereumChainId);
1707
+ try {
1708
+ walletStrategy.getStrategy().onChainIdChanged(getEthereumChainId);
1709
+ } catch (e) {
1710
+ console.warn("Failed to subscribe to chain ID changes:", e);
1711
+ }
1730
1712
  }, [injectiveXService?.walletStrategy]);
1731
1713
  return ethereumChainId;
1732
1714
  }
1733
- var switchEthereumChain2 = async () => {
1715
+ var switchEthereumChain = async () => {
1734
1716
  const metamaskProvider = window.ethereum;
1735
1717
  return await Promise.race([
1736
1718
  metamaskProvider.request({
@@ -1758,7 +1740,7 @@ var useEvmSwitchChain = (expectedXChainId) => {
1758
1740
  const { switchChain } = useSwitchChain();
1759
1741
  const handleSwitchChain = useCallback(() => {
1760
1742
  if (xChainType === "INJECTIVE") {
1761
- switchEthereumChain2();
1743
+ switchEthereumChain();
1762
1744
  } else {
1763
1745
  switchChain({ chainId: expectedChainId });
1764
1746
  }
@@ -2012,6 +1994,27 @@ var reconnectIcon = async () => {
2012
1994
  });
2013
1995
  }
2014
1996
  };
1997
+ var reconnectInjective = async () => {
1998
+ const injectiveConnection = useXWagmiStore.getState().xConnections.INJECTIVE;
1999
+ if (!injectiveConnection) return;
2000
+ const recentXConnectorId = injectiveConnection.xConnectorId;
2001
+ const walletStrategy = InjectiveXService.getInstance().walletStrategy;
2002
+ await walletStrategy.setWallet(recentXConnectorId);
2003
+ const addresses = await walletStrategy.getAddresses();
2004
+ const address = isEvmBrowserWallet(recentXConnectorId) ? getInjectiveAddress(addresses?.[0]) : addresses?.[0];
2005
+ useXWagmiStore.setState({
2006
+ xConnections: {
2007
+ ...useXWagmiStore.getState().xConnections,
2008
+ INJECTIVE: {
2009
+ xAccount: {
2010
+ address,
2011
+ xChainType: "INJECTIVE"
2012
+ },
2013
+ xConnectorId: recentXConnectorId
2014
+ }
2015
+ }
2016
+ });
2017
+ };
2015
2018
 
2016
2019
  // src/xchains/stellar/actions.ts
2017
2020
  var reconnectStellar = async () => {
@@ -2058,6 +2061,7 @@ var SodaxWalletProvider = ({ children, rpcConfig, options, initialState }) => {
2058
2061
  return /* @__PURE__ */ React2.createElement(QueryClientProvider, { client: queryClient }, /* @__PURE__ */ React2.createElement(WagmiProvider, { reconnectOnMount: wagmi.reconnectOnMount, config: wagmiConfig, initialState }, /* @__PURE__ */ React2.createElement(SuiClientProvider, { networks: { mainnet: { url: getFullnodeUrl("mainnet") } }, defaultNetwork: "mainnet" }, /* @__PURE__ */ React2.createElement(WalletProvider, { autoConnect: sui.autoConnect }, /* @__PURE__ */ React2.createElement(ConnectionProvider, { endpoint: rpcConfig["solana"] ?? "https://api.mainnet-beta.solana.com" }, /* @__PURE__ */ React2.createElement(WalletProvider$1, { wallets, autoConnect: solana.autoConnect }, /* @__PURE__ */ React2.createElement(Hydrate, { rpcConfig }), children))))));
2059
2062
  };
2060
2063
  reconnectIcon();
2064
+ reconnectInjective();
2061
2065
  reconnectStellar();
2062
2066
 
2063
2067
  // src/types/index.ts
@@ -2070,6 +2074,6 @@ var WalletId = /* @__PURE__ */ ((WalletId2) => {
2070
2074
  return WalletId2;
2071
2075
  })(WalletId || {});
2072
2076
 
2073
- export { BitcoinXConnector, BitcoinXService, EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService, OKXXConnector, STACKS_PROVIDERS, SodaxWalletProvider, SolanaXConnector, SolanaXService, StacksXConnector, StacksXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, UnisatXConnector, WalletId, XConnector, XService, XverseXConnector, createWagmiConfig as createWagmi, createWagmiConfig, getWagmiChainId, getXChainType, getXService, isNativeToken, switchEthereumChain, useBitcoinXConnectors, useEvmSwitchChain, useStacksXConnectors, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };
2077
+ export { BitcoinXConnector, BitcoinXService, EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveXConnector, InjectiveXService, OKXXConnector, STACKS_PROVIDERS, SodaxWalletProvider, SolanaXConnector, SolanaXService, StacksXConnector, StacksXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, UnisatXConnector, WalletId, XConnector, XService, XverseXConnector, createWagmiConfig as createWagmi, createWagmiConfig, getWagmiChainId, getXChainType, getXService, isNativeToken, useBitcoinXConnectors, useEvmSwitchChain, useStacksXConnectors, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };
2074
2078
  //# sourceMappingURL=index.mjs.map
2075
2079
  //# sourceMappingURL=index.mjs.map