@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.cjs
CHANGED
|
@@ -646,7 +646,11 @@ var createWagmiConfig = (config, options) => {
|
|
|
646
646
|
[chains.lightlinkPhoenix.id]: wagmi.http(config[types.LIGHTLINK_MAINNET_CHAIN_ID]),
|
|
647
647
|
[chains.redbellyMainnet.id]: wagmi.http(config[types.REDBELLY_MAINNET_CHAIN_ID]),
|
|
648
648
|
[chains.kaia.id]: wagmi.http(config[types.KAIA_MAINNET_CHAIN_ID])
|
|
649
|
-
}
|
|
649
|
+
},
|
|
650
|
+
storage: wagmi.createStorage({
|
|
651
|
+
storage: wagmi.cookieStorage,
|
|
652
|
+
key: "sodax"
|
|
653
|
+
})
|
|
650
654
|
});
|
|
651
655
|
};
|
|
652
656
|
var EvmXService = class _EvmXService extends XService {
|
|
@@ -788,76 +792,48 @@ var InjectiveXService = class _InjectiveXService extends XService {
|
|
|
788
792
|
return 0n;
|
|
789
793
|
}
|
|
790
794
|
};
|
|
791
|
-
var
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
if (!walletCosmos.isCosmosWalletInstalled(walletBase.Wallet.Keplr)) {
|
|
800
|
-
window.open("https://chrome.google.com/webstore/detail/keplr/dmkamcknogkgcdfhhbddcghachkejeap?hl=en", "_blank");
|
|
801
|
-
return;
|
|
802
|
-
}
|
|
803
|
-
this.getXService().walletStrategy.setWallet(walletBase.Wallet.Keplr);
|
|
804
|
-
const addresses = await this.getXService().walletStrategy.getAddresses();
|
|
805
|
-
return {
|
|
806
|
-
address: addresses?.[0],
|
|
807
|
-
xChainType: this.xChainType
|
|
808
|
-
};
|
|
809
|
-
}
|
|
810
|
-
async disconnect() {
|
|
811
|
-
}
|
|
812
|
-
get icon() {
|
|
813
|
-
return "https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/keplr.svg";
|
|
814
|
-
}
|
|
795
|
+
var WALLET_ICONS = {
|
|
796
|
+
metamask: "https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/metamask.svg",
|
|
797
|
+
keplr: "https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/keplr.svg",
|
|
798
|
+
leap: "https://assets.leapwallet.io/logos/leap-cosmos-logo.svg",
|
|
799
|
+
rabby: "https://raw.githubusercontent.com/RabbyHub/logo/master/symbol.svg",
|
|
800
|
+
phantom: "https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/phantom.svg",
|
|
801
|
+
"okx-wallet": "https://static.okx.com/cdn/assets/imgs/247/58E63FEA47A2B7D7.png",
|
|
802
|
+
"trust-wallet": "https://trustwallet.com/assets/images/media/assets/twLogo.svg"
|
|
815
803
|
};
|
|
816
|
-
var
|
|
817
|
-
constructor() {
|
|
818
|
-
super("INJECTIVE",
|
|
804
|
+
var InjectiveXConnector = class extends XConnector {
|
|
805
|
+
constructor(name, wallet) {
|
|
806
|
+
super("INJECTIVE", name, wallet);
|
|
807
|
+
this.wallet = wallet;
|
|
819
808
|
}
|
|
820
809
|
getXService() {
|
|
821
810
|
return InjectiveXService.getInstance();
|
|
822
811
|
}
|
|
823
812
|
async connect() {
|
|
824
|
-
if (
|
|
825
|
-
|
|
826
|
-
return;
|
|
813
|
+
if (walletBase.isCosmosBrowserWallet(this.wallet) && !walletCosmos.isCosmosWalletInstalled(this.wallet)) {
|
|
814
|
+
return void 0;
|
|
827
815
|
}
|
|
828
|
-
this.getXService().walletStrategy
|
|
829
|
-
|
|
830
|
-
const
|
|
816
|
+
const walletStrategy = this.getXService().walletStrategy;
|
|
817
|
+
await walletStrategy.setWallet(this.wallet);
|
|
818
|
+
const addresses = await walletStrategy.getAddresses();
|
|
819
|
+
if (!addresses?.length) return void 0;
|
|
820
|
+
const address = walletBase.isEvmBrowserWallet(this.wallet) ? sdkTs.getInjectiveAddress(addresses[0]) : addresses[0];
|
|
831
821
|
return {
|
|
832
|
-
address
|
|
822
|
+
address,
|
|
833
823
|
xChainType: this.xChainType
|
|
834
824
|
};
|
|
835
825
|
}
|
|
836
826
|
async disconnect() {
|
|
837
|
-
|
|
827
|
+
if (walletBase.isEvmBrowserWallet(this.wallet)) {
|
|
828
|
+
const walletStrategy = this.getXService().walletStrategy;
|
|
829
|
+
await walletStrategy.setWallet(this.wallet);
|
|
830
|
+
await walletStrategy.disconnect();
|
|
831
|
+
}
|
|
838
832
|
}
|
|
839
833
|
get icon() {
|
|
840
|
-
return
|
|
834
|
+
return WALLET_ICONS[this.wallet];
|
|
841
835
|
}
|
|
842
836
|
};
|
|
843
|
-
|
|
844
|
-
// src/xchains/injective/utils.ts
|
|
845
|
-
var switchEthereumChain = async (chainId) => {
|
|
846
|
-
const metamaskProvider = window.ethereum;
|
|
847
|
-
await Promise.race([
|
|
848
|
-
metamaskProvider.request({
|
|
849
|
-
method: "wallet_switchEthereumChain",
|
|
850
|
-
params: [{ chainId: `0x${chainId}` }]
|
|
851
|
-
}),
|
|
852
|
-
new Promise(
|
|
853
|
-
(resolve) => metamaskProvider.on("change", ({ chain }) => {
|
|
854
|
-
if (chain?.id === chainId) {
|
|
855
|
-
resolve();
|
|
856
|
-
}
|
|
857
|
-
})
|
|
858
|
-
)
|
|
859
|
-
]);
|
|
860
|
-
};
|
|
861
837
|
var SolanaXService = class _SolanaXService extends XService {
|
|
862
838
|
constructor() {
|
|
863
839
|
super("SOLANA");
|
|
@@ -1332,16 +1308,18 @@ var initXServices = () => {
|
|
|
1332
1308
|
break;
|
|
1333
1309
|
case "BITCOIN":
|
|
1334
1310
|
xServices[xChainType] = BitcoinXService.getInstance();
|
|
1335
|
-
xServices[xChainType].setXConnectors([
|
|
1336
|
-
new UnisatXConnector(),
|
|
1337
|
-
new XverseXConnector(),
|
|
1338
|
-
new OKXXConnector()
|
|
1339
|
-
]);
|
|
1311
|
+
xServices[xChainType].setXConnectors([new UnisatXConnector(), new XverseXConnector(), new OKXXConnector()]);
|
|
1340
1312
|
break;
|
|
1341
1313
|
// Injective, Stellar, Icon wallet connectors are supported by sodax wallet-sdk-react sdk.
|
|
1342
1314
|
case "INJECTIVE":
|
|
1343
1315
|
xServices[xChainType] = InjectiveXService.getInstance();
|
|
1344
|
-
xServices[xChainType].setXConnectors([
|
|
1316
|
+
xServices[xChainType].setXConnectors([
|
|
1317
|
+
// EVM wallets (auto-detected via EIP-6963)
|
|
1318
|
+
new InjectiveXConnector("MetaMask", walletBase.Wallet.Metamask),
|
|
1319
|
+
// Cosmos wallets (detected via window globals)
|
|
1320
|
+
new InjectiveXConnector("Keplr", walletBase.Wallet.Keplr),
|
|
1321
|
+
new InjectiveXConnector("Leap", walletBase.Wallet.Leap)
|
|
1322
|
+
]);
|
|
1345
1323
|
break;
|
|
1346
1324
|
case "STELLAR":
|
|
1347
1325
|
xServices[xChainType] = StellarXService.getInstance();
|
|
@@ -1743,15 +1721,23 @@ function useEthereumChainId() {
|
|
|
1743
1721
|
const walletStrategy = injectiveXService.walletStrategy;
|
|
1744
1722
|
if (walletStrategy.getWallet() !== walletBase.Wallet.Metamask) return;
|
|
1745
1723
|
const getEthereumChainId = async () => {
|
|
1746
|
-
|
|
1747
|
-
|
|
1724
|
+
try {
|
|
1725
|
+
const chainId = await walletStrategy.getEthereumChainId();
|
|
1726
|
+
setEthereumChainId(Number.parseInt(chainId));
|
|
1727
|
+
} catch (e) {
|
|
1728
|
+
console.warn("Failed to get Ethereum chain ID:", e);
|
|
1729
|
+
}
|
|
1748
1730
|
};
|
|
1749
1731
|
getEthereumChainId();
|
|
1750
|
-
|
|
1732
|
+
try {
|
|
1733
|
+
walletStrategy.getStrategy().onChainIdChanged(getEthereumChainId);
|
|
1734
|
+
} catch (e) {
|
|
1735
|
+
console.warn("Failed to subscribe to chain ID changes:", e);
|
|
1736
|
+
}
|
|
1751
1737
|
}, [injectiveXService?.walletStrategy]);
|
|
1752
1738
|
return ethereumChainId;
|
|
1753
1739
|
}
|
|
1754
|
-
var
|
|
1740
|
+
var switchEthereumChain = async () => {
|
|
1755
1741
|
const metamaskProvider = window.ethereum;
|
|
1756
1742
|
return await Promise.race([
|
|
1757
1743
|
metamaskProvider.request({
|
|
@@ -1779,7 +1765,7 @@ var useEvmSwitchChain = (expectedXChainId) => {
|
|
|
1779
1765
|
const { switchChain } = wagmi.useSwitchChain();
|
|
1780
1766
|
const handleSwitchChain = React2.useCallback(() => {
|
|
1781
1767
|
if (xChainType === "INJECTIVE") {
|
|
1782
|
-
|
|
1768
|
+
switchEthereumChain();
|
|
1783
1769
|
} else {
|
|
1784
1770
|
switchChain({ chainId: expectedChainId });
|
|
1785
1771
|
}
|
|
@@ -2033,6 +2019,27 @@ var reconnectIcon = async () => {
|
|
|
2033
2019
|
});
|
|
2034
2020
|
}
|
|
2035
2021
|
};
|
|
2022
|
+
var reconnectInjective = async () => {
|
|
2023
|
+
const injectiveConnection = useXWagmiStore.getState().xConnections.INJECTIVE;
|
|
2024
|
+
if (!injectiveConnection) return;
|
|
2025
|
+
const recentXConnectorId = injectiveConnection.xConnectorId;
|
|
2026
|
+
const walletStrategy = InjectiveXService.getInstance().walletStrategy;
|
|
2027
|
+
await walletStrategy.setWallet(recentXConnectorId);
|
|
2028
|
+
const addresses = await walletStrategy.getAddresses();
|
|
2029
|
+
const address = walletBase.isEvmBrowserWallet(recentXConnectorId) ? sdkTs.getInjectiveAddress(addresses?.[0]) : addresses?.[0];
|
|
2030
|
+
useXWagmiStore.setState({
|
|
2031
|
+
xConnections: {
|
|
2032
|
+
...useXWagmiStore.getState().xConnections,
|
|
2033
|
+
INJECTIVE: {
|
|
2034
|
+
xAccount: {
|
|
2035
|
+
address,
|
|
2036
|
+
xChainType: "INJECTIVE"
|
|
2037
|
+
},
|
|
2038
|
+
xConnectorId: recentXConnectorId
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
});
|
|
2042
|
+
};
|
|
2036
2043
|
|
|
2037
2044
|
// src/xchains/stellar/actions.ts
|
|
2038
2045
|
var reconnectStellar = async () => {
|
|
@@ -2068,7 +2075,7 @@ var defaultOptions = {
|
|
|
2068
2075
|
autoConnect: true
|
|
2069
2076
|
}
|
|
2070
2077
|
};
|
|
2071
|
-
var SodaxWalletProvider = ({ children, rpcConfig, options }) => {
|
|
2078
|
+
var SodaxWalletProvider = ({ children, rpcConfig, options, initialState }) => {
|
|
2072
2079
|
const wagmi$1 = React2.useMemo(() => ({ ...defaultOptions.wagmi, ...options?.wagmi }), [options?.wagmi]);
|
|
2073
2080
|
const wagmiConfig = React2.useMemo(() => {
|
|
2074
2081
|
return createWagmiConfig(rpcConfig, wagmi$1);
|
|
@@ -2076,9 +2083,10 @@ var SodaxWalletProvider = ({ children, rpcConfig, options }) => {
|
|
|
2076
2083
|
const wallets = React2.useMemo(() => [new walletAdapterWallets.UnsafeBurnerWalletAdapter()], []);
|
|
2077
2084
|
const solana = React2.useMemo(() => ({ ...defaultOptions.solana, ...options?.solana }), [options?.solana]);
|
|
2078
2085
|
const sui = React2.useMemo(() => ({ ...defaultOptions.sui, ...options?.sui }), [options?.sui]);
|
|
2079
|
-
return /* @__PURE__ */ React2__default.default.createElement(reactQuery.QueryClientProvider, { client: queryClient }, /* @__PURE__ */ React2__default.default.createElement(wagmi.WagmiProvider, { reconnectOnMount: wagmi$1.reconnectOnMount, config: wagmiConfig }, /* @__PURE__ */ React2__default.default.createElement(dappKit.SuiClientProvider, { networks: { mainnet: { url: client.getFullnodeUrl("mainnet") } }, defaultNetwork: "mainnet" }, /* @__PURE__ */ React2__default.default.createElement(dappKit.WalletProvider, { autoConnect: sui.autoConnect }, /* @__PURE__ */ React2__default.default.createElement(walletAdapterReact.ConnectionProvider, { endpoint: rpcConfig["solana"] ?? "https://api.mainnet-beta.solana.com" }, /* @__PURE__ */ React2__default.default.createElement(walletAdapterReact.WalletProvider, { wallets, autoConnect: solana.autoConnect }, /* @__PURE__ */ React2__default.default.createElement(Hydrate, { rpcConfig }), children))))));
|
|
2086
|
+
return /* @__PURE__ */ React2__default.default.createElement(reactQuery.QueryClientProvider, { client: queryClient }, /* @__PURE__ */ React2__default.default.createElement(wagmi.WagmiProvider, { reconnectOnMount: wagmi$1.reconnectOnMount, config: wagmiConfig, initialState }, /* @__PURE__ */ React2__default.default.createElement(dappKit.SuiClientProvider, { networks: { mainnet: { url: client.getFullnodeUrl("mainnet") } }, defaultNetwork: "mainnet" }, /* @__PURE__ */ React2__default.default.createElement(dappKit.WalletProvider, { autoConnect: sui.autoConnect }, /* @__PURE__ */ React2__default.default.createElement(walletAdapterReact.ConnectionProvider, { endpoint: rpcConfig["solana"] ?? "https://api.mainnet-beta.solana.com" }, /* @__PURE__ */ React2__default.default.createElement(walletAdapterReact.WalletProvider, { wallets, autoConnect: solana.autoConnect }, /* @__PURE__ */ React2__default.default.createElement(Hydrate, { rpcConfig }), children))))));
|
|
2080
2087
|
};
|
|
2081
2088
|
reconnectIcon();
|
|
2089
|
+
reconnectInjective();
|
|
2082
2090
|
reconnectStellar();
|
|
2083
2091
|
|
|
2084
2092
|
// src/types/index.ts
|
|
@@ -2097,8 +2105,7 @@ exports.EvmXConnector = EvmXConnector;
|
|
|
2097
2105
|
exports.EvmXService = EvmXService;
|
|
2098
2106
|
exports.IconHanaXConnector = IconHanaXConnector;
|
|
2099
2107
|
exports.IconXService = IconXService;
|
|
2100
|
-
exports.
|
|
2101
|
-
exports.InjectiveMetamaskXConnector = InjectiveMetamaskXConnector;
|
|
2108
|
+
exports.InjectiveXConnector = InjectiveXConnector;
|
|
2102
2109
|
exports.InjectiveXService = InjectiveXService;
|
|
2103
2110
|
exports.OKXXConnector = OKXXConnector;
|
|
2104
2111
|
exports.STACKS_PROVIDERS = STACKS_PROVIDERS;
|
|
@@ -2116,11 +2123,12 @@ exports.WalletId = WalletId;
|
|
|
2116
2123
|
exports.XConnector = XConnector;
|
|
2117
2124
|
exports.XService = XService;
|
|
2118
2125
|
exports.XverseXConnector = XverseXConnector;
|
|
2126
|
+
exports.createWagmi = createWagmiConfig;
|
|
2127
|
+
exports.createWagmiConfig = createWagmiConfig;
|
|
2119
2128
|
exports.getWagmiChainId = getWagmiChainId;
|
|
2120
2129
|
exports.getXChainType = getXChainType;
|
|
2121
2130
|
exports.getXService = getXService;
|
|
2122
2131
|
exports.isNativeToken = isNativeToken;
|
|
2123
|
-
exports.switchEthereumChain = switchEthereumChain;
|
|
2124
2132
|
exports.useBitcoinXConnectors = useBitcoinXConnectors;
|
|
2125
2133
|
exports.useEvmSwitchChain = useEvmSwitchChain;
|
|
2126
2134
|
exports.useStacksXConnectors = useStacksXConnectors;
|