@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/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { detectBitcoinAddressType, baseChainInfo,
|
|
1
|
+
import { detectBitcoinAddressType, baseChainInfo, KAIA_MAINNET_CHAIN_ID, REDBELLY_MAINNET_CHAIN_ID, LIGHTLINK_MAINNET_CHAIN_ID, HYPEREVM_MAINNET_CHAIN_ID, POLYGON_MAINNET_CHAIN_ID, OPTIMISM_MAINNET_CHAIN_ID, SONIC_MAINNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BASE_MAINNET_CHAIN_ID, ARBITRUM_MAINNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, ETHEREUM_MAINNET_CHAIN_ID, ChainTypeArr } from '@sodax/types';
|
|
2
2
|
import { NearConnector } from '@hot-labs/near-connect';
|
|
3
3
|
import { JsonRpcProvider } from 'near-api-js';
|
|
4
4
|
import { fetchCallReadOnlyFunction, Cl } from '@stacks/transactions';
|
|
@@ -7,7 +7,7 @@ import { AddressPurpose, MessageSigningProtocols } from 'sats-connect';
|
|
|
7
7
|
import React2, { useMemo, useCallback, useEffect } from 'react';
|
|
8
8
|
import { useCurrentAccount, useCurrentWallet, useConnectWallet, useWallets, useDisconnectWallet, useSignPersonalMessage, SuiClientProvider, WalletProvider, useSuiClient } from '@mysten/dapp-kit';
|
|
9
9
|
import { useWallet, ConnectionProvider, WalletProvider as WalletProvider$1, useConnection } from '@solana/wallet-adapter-react';
|
|
10
|
-
import { useConnections, useAccount, useConnect, useConnectors, useDisconnect, useSwitchChain, usePublicClient, useWalletClient, useSignMessage, WagmiProvider,
|
|
10
|
+
import { createConfig, createStorage, http, cookieStorage, useConnections, useAccount, useConnect, useConnectors, useDisconnect, useSwitchChain, usePublicClient, useWalletClient, useSignMessage, WagmiProvider, useConfig } from 'wagmi';
|
|
11
11
|
import { create } from 'zustand';
|
|
12
12
|
import { devtools, persist, createJSONStorage } from 'zustand/middleware';
|
|
13
13
|
import { immer } from 'zustand/middleware/immer';
|
|
@@ -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,
|
|
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';
|
|
@@ -621,7 +621,11 @@ var createWagmiConfig = (config, options) => {
|
|
|
621
621
|
[lightlinkPhoenix.id]: http(config[LIGHTLINK_MAINNET_CHAIN_ID]),
|
|
622
622
|
[redbellyMainnet.id]: http(config[REDBELLY_MAINNET_CHAIN_ID]),
|
|
623
623
|
[kaia.id]: http(config[KAIA_MAINNET_CHAIN_ID])
|
|
624
|
-
}
|
|
624
|
+
},
|
|
625
|
+
storage: createStorage({
|
|
626
|
+
storage: cookieStorage,
|
|
627
|
+
key: "sodax"
|
|
628
|
+
})
|
|
625
629
|
});
|
|
626
630
|
};
|
|
627
631
|
var EvmXService = class _EvmXService extends XService {
|
|
@@ -763,76 +767,48 @@ var InjectiveXService = class _InjectiveXService extends XService {
|
|
|
763
767
|
return 0n;
|
|
764
768
|
}
|
|
765
769
|
};
|
|
766
|
-
var
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
if (!isCosmosWalletInstalled(Wallet.Keplr)) {
|
|
775
|
-
window.open("https://chrome.google.com/webstore/detail/keplr/dmkamcknogkgcdfhhbddcghachkejeap?hl=en", "_blank");
|
|
776
|
-
return;
|
|
777
|
-
}
|
|
778
|
-
this.getXService().walletStrategy.setWallet(Wallet.Keplr);
|
|
779
|
-
const addresses = await this.getXService().walletStrategy.getAddresses();
|
|
780
|
-
return {
|
|
781
|
-
address: addresses?.[0],
|
|
782
|
-
xChainType: this.xChainType
|
|
783
|
-
};
|
|
784
|
-
}
|
|
785
|
-
async disconnect() {
|
|
786
|
-
}
|
|
787
|
-
get icon() {
|
|
788
|
-
return "https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/keplr.svg";
|
|
789
|
-
}
|
|
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"
|
|
790
778
|
};
|
|
791
|
-
var
|
|
792
|
-
constructor() {
|
|
793
|
-
super("INJECTIVE",
|
|
779
|
+
var InjectiveXConnector = class extends XConnector {
|
|
780
|
+
constructor(name, wallet) {
|
|
781
|
+
super("INJECTIVE", name, wallet);
|
|
782
|
+
this.wallet = wallet;
|
|
794
783
|
}
|
|
795
784
|
getXService() {
|
|
796
785
|
return InjectiveXService.getInstance();
|
|
797
786
|
}
|
|
798
787
|
async connect() {
|
|
799
|
-
if (!
|
|
800
|
-
|
|
801
|
-
return;
|
|
788
|
+
if (isCosmosBrowserWallet(this.wallet) && !isCosmosWalletInstalled(this.wallet)) {
|
|
789
|
+
return void 0;
|
|
802
790
|
}
|
|
803
|
-
this.getXService().walletStrategy
|
|
804
|
-
|
|
805
|
-
const
|
|
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];
|
|
806
796
|
return {
|
|
807
|
-
address
|
|
797
|
+
address,
|
|
808
798
|
xChainType: this.xChainType
|
|
809
799
|
};
|
|
810
800
|
}
|
|
811
801
|
async disconnect() {
|
|
812
|
-
|
|
802
|
+
if (isEvmBrowserWallet(this.wallet)) {
|
|
803
|
+
const walletStrategy = this.getXService().walletStrategy;
|
|
804
|
+
await walletStrategy.setWallet(this.wallet);
|
|
805
|
+
await walletStrategy.disconnect();
|
|
806
|
+
}
|
|
813
807
|
}
|
|
814
808
|
get icon() {
|
|
815
|
-
return
|
|
809
|
+
return WALLET_ICONS[this.wallet];
|
|
816
810
|
}
|
|
817
811
|
};
|
|
818
|
-
|
|
819
|
-
// src/xchains/injective/utils.ts
|
|
820
|
-
var switchEthereumChain = async (chainId) => {
|
|
821
|
-
const metamaskProvider = window.ethereum;
|
|
822
|
-
await Promise.race([
|
|
823
|
-
metamaskProvider.request({
|
|
824
|
-
method: "wallet_switchEthereumChain",
|
|
825
|
-
params: [{ chainId: `0x${chainId}` }]
|
|
826
|
-
}),
|
|
827
|
-
new Promise(
|
|
828
|
-
(resolve) => metamaskProvider.on("change", ({ chain }) => {
|
|
829
|
-
if (chain?.id === chainId) {
|
|
830
|
-
resolve();
|
|
831
|
-
}
|
|
832
|
-
})
|
|
833
|
-
)
|
|
834
|
-
]);
|
|
835
|
-
};
|
|
836
812
|
var SolanaXService = class _SolanaXService extends XService {
|
|
837
813
|
constructor() {
|
|
838
814
|
super("SOLANA");
|
|
@@ -1307,16 +1283,18 @@ var initXServices = () => {
|
|
|
1307
1283
|
break;
|
|
1308
1284
|
case "BITCOIN":
|
|
1309
1285
|
xServices[xChainType] = BitcoinXService.getInstance();
|
|
1310
|
-
xServices[xChainType].setXConnectors([
|
|
1311
|
-
new UnisatXConnector(),
|
|
1312
|
-
new XverseXConnector(),
|
|
1313
|
-
new OKXXConnector()
|
|
1314
|
-
]);
|
|
1286
|
+
xServices[xChainType].setXConnectors([new UnisatXConnector(), new XverseXConnector(), new OKXXConnector()]);
|
|
1315
1287
|
break;
|
|
1316
1288
|
// Injective, Stellar, Icon wallet connectors are supported by sodax wallet-sdk-react sdk.
|
|
1317
1289
|
case "INJECTIVE":
|
|
1318
1290
|
xServices[xChainType] = InjectiveXService.getInstance();
|
|
1319
|
-
xServices[xChainType].setXConnectors([
|
|
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
|
+
]);
|
|
1320
1298
|
break;
|
|
1321
1299
|
case "STELLAR":
|
|
1322
1300
|
xServices[xChainType] = StellarXService.getInstance();
|
|
@@ -1718,15 +1696,23 @@ function useEthereumChainId() {
|
|
|
1718
1696
|
const walletStrategy = injectiveXService.walletStrategy;
|
|
1719
1697
|
if (walletStrategy.getWallet() !== Wallet.Metamask) return;
|
|
1720
1698
|
const getEthereumChainId = async () => {
|
|
1721
|
-
|
|
1722
|
-
|
|
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
|
+
}
|
|
1723
1705
|
};
|
|
1724
1706
|
getEthereumChainId();
|
|
1725
|
-
|
|
1707
|
+
try {
|
|
1708
|
+
walletStrategy.getStrategy().onChainIdChanged(getEthereumChainId);
|
|
1709
|
+
} catch (e) {
|
|
1710
|
+
console.warn("Failed to subscribe to chain ID changes:", e);
|
|
1711
|
+
}
|
|
1726
1712
|
}, [injectiveXService?.walletStrategy]);
|
|
1727
1713
|
return ethereumChainId;
|
|
1728
1714
|
}
|
|
1729
|
-
var
|
|
1715
|
+
var switchEthereumChain = async () => {
|
|
1730
1716
|
const metamaskProvider = window.ethereum;
|
|
1731
1717
|
return await Promise.race([
|
|
1732
1718
|
metamaskProvider.request({
|
|
@@ -1754,7 +1740,7 @@ var useEvmSwitchChain = (expectedXChainId) => {
|
|
|
1754
1740
|
const { switchChain } = useSwitchChain();
|
|
1755
1741
|
const handleSwitchChain = useCallback(() => {
|
|
1756
1742
|
if (xChainType === "INJECTIVE") {
|
|
1757
|
-
|
|
1743
|
+
switchEthereumChain();
|
|
1758
1744
|
} else {
|
|
1759
1745
|
switchChain({ chainId: expectedChainId });
|
|
1760
1746
|
}
|
|
@@ -2008,6 +1994,27 @@ var reconnectIcon = async () => {
|
|
|
2008
1994
|
});
|
|
2009
1995
|
}
|
|
2010
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
|
+
};
|
|
2011
2018
|
|
|
2012
2019
|
// src/xchains/stellar/actions.ts
|
|
2013
2020
|
var reconnectStellar = async () => {
|
|
@@ -2043,7 +2050,7 @@ var defaultOptions = {
|
|
|
2043
2050
|
autoConnect: true
|
|
2044
2051
|
}
|
|
2045
2052
|
};
|
|
2046
|
-
var SodaxWalletProvider = ({ children, rpcConfig, options }) => {
|
|
2053
|
+
var SodaxWalletProvider = ({ children, rpcConfig, options, initialState }) => {
|
|
2047
2054
|
const wagmi = useMemo(() => ({ ...defaultOptions.wagmi, ...options?.wagmi }), [options?.wagmi]);
|
|
2048
2055
|
const wagmiConfig = useMemo(() => {
|
|
2049
2056
|
return createWagmiConfig(rpcConfig, wagmi);
|
|
@@ -2051,9 +2058,10 @@ var SodaxWalletProvider = ({ children, rpcConfig, options }) => {
|
|
|
2051
2058
|
const wallets = useMemo(() => [new UnsafeBurnerWalletAdapter()], []);
|
|
2052
2059
|
const solana = useMemo(() => ({ ...defaultOptions.solana, ...options?.solana }), [options?.solana]);
|
|
2053
2060
|
const sui = useMemo(() => ({ ...defaultOptions.sui, ...options?.sui }), [options?.sui]);
|
|
2054
|
-
return /* @__PURE__ */ React2.createElement(QueryClientProvider, { client: queryClient }, /* @__PURE__ */ React2.createElement(WagmiProvider, { reconnectOnMount: wagmi.reconnectOnMount, config: wagmiConfig }, /* @__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))))));
|
|
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))))));
|
|
2055
2062
|
};
|
|
2056
2063
|
reconnectIcon();
|
|
2064
|
+
reconnectInjective();
|
|
2057
2065
|
reconnectStellar();
|
|
2058
2066
|
|
|
2059
2067
|
// src/types/index.ts
|
|
@@ -2066,6 +2074,6 @@ var WalletId = /* @__PURE__ */ ((WalletId2) => {
|
|
|
2066
2074
|
return WalletId2;
|
|
2067
2075
|
})(WalletId || {});
|
|
2068
2076
|
|
|
2069
|
-
export { BitcoinXConnector, BitcoinXService, EvmXConnector, EvmXService, IconHanaXConnector, IconXService,
|
|
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 };
|
|
2070
2078
|
//# sourceMappingURL=index.mjs.map
|
|
2071
2079
|
//# sourceMappingURL=index.mjs.map
|