@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.cjs +70 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -14
- package/dist/index.d.ts +6 -14
- package/dist/index.mjs +72 -68
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
- package/src/SodaxWalletProvider.tsx +2 -1
- package/src/hooks/useEthereumChainId.ts +11 -3
- package/src/useXWagmiStore.ts +10 -7
- 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
|
@@ -792,76 +792,48 @@ var InjectiveXService = class _InjectiveXService extends XService {
|
|
|
792
792
|
return 0n;
|
|
793
793
|
}
|
|
794
794
|
};
|
|
795
|
-
var
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
if (!walletCosmos.isCosmosWalletInstalled(walletBase.Wallet.Keplr)) {
|
|
804
|
-
window.open("https://chrome.google.com/webstore/detail/keplr/dmkamcknogkgcdfhhbddcghachkejeap?hl=en", "_blank");
|
|
805
|
-
return;
|
|
806
|
-
}
|
|
807
|
-
this.getXService().walletStrategy.setWallet(walletBase.Wallet.Keplr);
|
|
808
|
-
const addresses = await this.getXService().walletStrategy.getAddresses();
|
|
809
|
-
return {
|
|
810
|
-
address: addresses?.[0],
|
|
811
|
-
xChainType: this.xChainType
|
|
812
|
-
};
|
|
813
|
-
}
|
|
814
|
-
async disconnect() {
|
|
815
|
-
}
|
|
816
|
-
get icon() {
|
|
817
|
-
return "https://raw.githubusercontent.com/balancednetwork/icons/master/wallets/keplr.svg";
|
|
818
|
-
}
|
|
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"
|
|
819
803
|
};
|
|
820
|
-
var
|
|
821
|
-
constructor() {
|
|
822
|
-
super("INJECTIVE",
|
|
804
|
+
var InjectiveXConnector = class extends XConnector {
|
|
805
|
+
constructor(name, wallet) {
|
|
806
|
+
super("INJECTIVE", name, wallet);
|
|
807
|
+
this.wallet = wallet;
|
|
823
808
|
}
|
|
824
809
|
getXService() {
|
|
825
810
|
return InjectiveXService.getInstance();
|
|
826
811
|
}
|
|
827
812
|
async connect() {
|
|
828
|
-
if (
|
|
829
|
-
|
|
830
|
-
return;
|
|
813
|
+
if (walletBase.isCosmosBrowserWallet(this.wallet) && !walletCosmos.isCosmosWalletInstalled(this.wallet)) {
|
|
814
|
+
return void 0;
|
|
831
815
|
}
|
|
832
|
-
this.getXService().walletStrategy
|
|
833
|
-
|
|
834
|
-
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];
|
|
835
821
|
return {
|
|
836
|
-
address
|
|
822
|
+
address,
|
|
837
823
|
xChainType: this.xChainType
|
|
838
824
|
};
|
|
839
825
|
}
|
|
840
826
|
async disconnect() {
|
|
841
|
-
|
|
827
|
+
if (walletBase.isEvmBrowserWallet(this.wallet)) {
|
|
828
|
+
const walletStrategy = this.getXService().walletStrategy;
|
|
829
|
+
await walletStrategy.setWallet(this.wallet);
|
|
830
|
+
await walletStrategy.disconnect();
|
|
831
|
+
}
|
|
842
832
|
}
|
|
843
833
|
get icon() {
|
|
844
|
-
return
|
|
834
|
+
return WALLET_ICONS[this.wallet];
|
|
845
835
|
}
|
|
846
836
|
};
|
|
847
|
-
|
|
848
|
-
// src/xchains/injective/utils.ts
|
|
849
|
-
var switchEthereumChain = async (chainId) => {
|
|
850
|
-
const metamaskProvider = window.ethereum;
|
|
851
|
-
await Promise.race([
|
|
852
|
-
metamaskProvider.request({
|
|
853
|
-
method: "wallet_switchEthereumChain",
|
|
854
|
-
params: [{ chainId: `0x${chainId}` }]
|
|
855
|
-
}),
|
|
856
|
-
new Promise(
|
|
857
|
-
(resolve) => metamaskProvider.on("change", ({ chain }) => {
|
|
858
|
-
if (chain?.id === chainId) {
|
|
859
|
-
resolve();
|
|
860
|
-
}
|
|
861
|
-
})
|
|
862
|
-
)
|
|
863
|
-
]);
|
|
864
|
-
};
|
|
865
837
|
var SolanaXService = class _SolanaXService extends XService {
|
|
866
838
|
constructor() {
|
|
867
839
|
super("SOLANA");
|
|
@@ -1336,16 +1308,18 @@ var initXServices = () => {
|
|
|
1336
1308
|
break;
|
|
1337
1309
|
case "BITCOIN":
|
|
1338
1310
|
xServices[xChainType] = BitcoinXService.getInstance();
|
|
1339
|
-
xServices[xChainType].setXConnectors([
|
|
1340
|
-
new UnisatXConnector(),
|
|
1341
|
-
new XverseXConnector(),
|
|
1342
|
-
new OKXXConnector()
|
|
1343
|
-
]);
|
|
1311
|
+
xServices[xChainType].setXConnectors([new UnisatXConnector(), new XverseXConnector(), new OKXXConnector()]);
|
|
1344
1312
|
break;
|
|
1345
1313
|
// Injective, Stellar, Icon wallet connectors are supported by sodax wallet-sdk-react sdk.
|
|
1346
1314
|
case "INJECTIVE":
|
|
1347
1315
|
xServices[xChainType] = InjectiveXService.getInstance();
|
|
1348
|
-
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
|
+
]);
|
|
1349
1323
|
break;
|
|
1350
1324
|
case "STELLAR":
|
|
1351
1325
|
xServices[xChainType] = StellarXService.getInstance();
|
|
@@ -1747,15 +1721,23 @@ function useEthereumChainId() {
|
|
|
1747
1721
|
const walletStrategy = injectiveXService.walletStrategy;
|
|
1748
1722
|
if (walletStrategy.getWallet() !== walletBase.Wallet.Metamask) return;
|
|
1749
1723
|
const getEthereumChainId = async () => {
|
|
1750
|
-
|
|
1751
|
-
|
|
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
|
+
}
|
|
1752
1730
|
};
|
|
1753
1731
|
getEthereumChainId();
|
|
1754
|
-
|
|
1732
|
+
try {
|
|
1733
|
+
walletStrategy.getStrategy().onChainIdChanged(getEthereumChainId);
|
|
1734
|
+
} catch (e) {
|
|
1735
|
+
console.warn("Failed to subscribe to chain ID changes:", e);
|
|
1736
|
+
}
|
|
1755
1737
|
}, [injectiveXService?.walletStrategy]);
|
|
1756
1738
|
return ethereumChainId;
|
|
1757
1739
|
}
|
|
1758
|
-
var
|
|
1740
|
+
var switchEthereumChain = async () => {
|
|
1759
1741
|
const metamaskProvider = window.ethereum;
|
|
1760
1742
|
return await Promise.race([
|
|
1761
1743
|
metamaskProvider.request({
|
|
@@ -1783,7 +1765,7 @@ var useEvmSwitchChain = (expectedXChainId) => {
|
|
|
1783
1765
|
const { switchChain } = wagmi.useSwitchChain();
|
|
1784
1766
|
const handleSwitchChain = React2.useCallback(() => {
|
|
1785
1767
|
if (xChainType === "INJECTIVE") {
|
|
1786
|
-
|
|
1768
|
+
switchEthereumChain();
|
|
1787
1769
|
} else {
|
|
1788
1770
|
switchChain({ chainId: expectedChainId });
|
|
1789
1771
|
}
|
|
@@ -2037,6 +2019,27 @@ var reconnectIcon = async () => {
|
|
|
2037
2019
|
});
|
|
2038
2020
|
}
|
|
2039
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
|
+
};
|
|
2040
2043
|
|
|
2041
2044
|
// src/xchains/stellar/actions.ts
|
|
2042
2045
|
var reconnectStellar = async () => {
|
|
@@ -2083,6 +2086,7 @@ var SodaxWalletProvider = ({ children, rpcConfig, options, initialState }) => {
|
|
|
2083
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))))));
|
|
2084
2087
|
};
|
|
2085
2088
|
reconnectIcon();
|
|
2089
|
+
reconnectInjective();
|
|
2086
2090
|
reconnectStellar();
|
|
2087
2091
|
|
|
2088
2092
|
// src/types/index.ts
|
|
@@ -2101,8 +2105,7 @@ exports.EvmXConnector = EvmXConnector;
|
|
|
2101
2105
|
exports.EvmXService = EvmXService;
|
|
2102
2106
|
exports.IconHanaXConnector = IconHanaXConnector;
|
|
2103
2107
|
exports.IconXService = IconXService;
|
|
2104
|
-
exports.
|
|
2105
|
-
exports.InjectiveMetamaskXConnector = InjectiveMetamaskXConnector;
|
|
2108
|
+
exports.InjectiveXConnector = InjectiveXConnector;
|
|
2106
2109
|
exports.InjectiveXService = InjectiveXService;
|
|
2107
2110
|
exports.OKXXConnector = OKXXConnector;
|
|
2108
2111
|
exports.STACKS_PROVIDERS = STACKS_PROVIDERS;
|
|
@@ -2126,7 +2129,6 @@ exports.getWagmiChainId = getWagmiChainId;
|
|
|
2126
2129
|
exports.getXChainType = getXChainType;
|
|
2127
2130
|
exports.getXService = getXService;
|
|
2128
2131
|
exports.isNativeToken = isNativeToken;
|
|
2129
|
-
exports.switchEthereumChain = switchEthereumChain;
|
|
2130
2132
|
exports.useBitcoinXConnectors = useBitcoinXConnectors;
|
|
2131
2133
|
exports.useEvmSwitchChain = useEvmSwitchChain;
|
|
2132
2134
|
exports.useStacksXConnectors = useStacksXConnectors;
|