Skip to content

Commit b81a88f

Browse files
committed
fix: resolve @interchain-kit getCurrentWallet compatibility issue
- Add polyfill for WalletManager.getCurrentWallet method - Update wallet composables to use current API - Fix premature balance queries causing "Client not exist" errors
1 parent 341a9a5 commit b81a88f

File tree

7 files changed

+133
-62
lines changed

7 files changed

+133
-62
lines changed

examples/injective-vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"@interchain-kit/keplr-extension": "0.2.222",
1616
"@interchain-kit/leap-extension": "0.2.222",
1717
"@interchain-kit/vue": "0.2.222",
18-
"@interchain-ui/vue": "^1.4.1",
18+
"@interchain-ui/vue": "1.4.1",
1919
"@interchainjs/cosmos": "1.11.2",
2020
"@interchainjs/injective": "1.6.5",
2121
"@interchainjs/vue": "1.11.2",

examples/injective-vue/src/composables/common/useInjectiveClient.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { ExtensionWallet } from '@interchain-kit/core';
2-
import { useChain, useWalletManager } from '@interchain-kit/vue';
1+
import { useChain } from '@interchain-kit/vue';
32
import { toConverters, toEncoders } from '@interchainjs/cosmos/utils';
43
import { InjSigningClient } from '@interchainjs/injective/signing-client';
54
import { MsgSend } from '@interchainjs/vue/cosmos/bank/v1beta1/tx';
65
import { Ref, computed, ref, watch } from 'vue';
76

87
export const useInjectiveClient = (chainName: Ref<string>) => {
9-
const { rpcEndpoint, chain } = useChain(chainName);
8+
const { rpcEndpoint, chain, wallet } = useChain(chainName);
109
const injectiveClient = ref();
11-
const wm = useWalletManager();
1210
const signer = computed(() => {
1311
if (!chain.value.chainId) {
1412
return;
1513
}
16-
const wallet = wm.getCurrentWallet() as unknown as ExtensionWallet;
17-
return wallet.getOfflineSigner(chain.value.chainId, 'direct'); // cosmoshub-4
14+
if (!wallet.value) {
15+
return;
16+
}
17+
return wallet.value.getOfflineSigner(chain.value.chainId, 'direct'); // cosmoshub-4
1818
});
1919
const _fetchClient = async (rpcEndpoint: string, signer: any) => {
2020
if (!rpcEndpoint || !signer) {

examples/injective-vue/src/composables/common/useStargateClient.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { Ref, computed, ref, watch } from 'vue';
2-
import { ExtensionWallet } from '@interchain-kit/core';
3-
import { useChain, useWalletManager } from '@interchain-kit/vue';
2+
import { useChain } from '@interchain-kit/vue';
43
import { SigningClient as SigningStargateClient } from '@interchainjs/cosmos/signing-client';
54

65
export const useStargateClient = (chainName: Ref<string>) => {
7-
const { rpcEndpoint, chain } = useChain(chainName);
6+
const { rpcEndpoint, chain, wallet } = useChain(chainName);
87
const stargazeClient = ref();
9-
const wm = useWalletManager();
108
const signer = computed(() => {
119
if (!chain.value.chainId) {
1210
return;
1311
}
14-
const wallet = wm.getCurrentWallet() as unknown as ExtensionWallet;
15-
return wallet.getOfflineSigner(chain.value.chainId, 'direct'); // cosmoshub-4
12+
if (!wallet.value) {
13+
return;
14+
}
15+
return wallet.value.getOfflineSigner(chain.value.chainId, 'direct'); // cosmoshub-4
1616
});
1717
const _fetchClient = async (rpcEndpoint: string, signer: any) => {
1818
if (!rpcEndpoint || !signer) {
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
import BigNumber from "bignumber.js";
2-
import { ref, computed } from "vue";
3-
import { assetLists } from "@chain-registry/v2";
1+
import BigNumber from 'bignumber.js';
2+
import { Ref, computed } from 'vue';
3+
import { assetLists } from '@chain-registry/v2';
44
import { useGetBalance } from '@interchainjs/vue/cosmos/bank/v1beta1/query.rpc.vue';
55
import { defaultRpcEndpoint } from '../../config/asset-list/defaults';
6-
import { useChain } from "@interchain-kit/vue";
6+
import { useChain } from '@interchain-kit/vue';
77

8-
9-
export const useBalanceVue = (chainName: ref) => {
8+
export const useBalanceVue = (chainName: Ref<string>) => {
109
const chainInfo = useChain(chainName);
11-
10+
1211
const { address } = chainInfo;
13-
14-
const defaultAssetList = assetLists.find((assetList) => assetList.chainName === chainName.value)
12+
13+
const defaultAssetList = assetLists.find(
14+
(assetList) => assetList.chainName === chainName.value
15+
);
1516

1617
const coin = defaultAssetList?.assets[0];
1718

18-
const denom = coin!.base!
19+
const denom = coin!.base!;
1920

2021
const COIN_DISPLAY_EXPONENT = coin!.denomUnits.find(
2122
(unit) => unit.denom === coin!.display
@@ -30,19 +31,19 @@ export const useBalanceVue = (chainName: ref) => {
3031
data: balance,
3132
isSuccess: isBalanceLoaded,
3233
isLoading: isFetchingBalance,
33-
refetch: refetchBalance
34+
refetch: refetchBalance,
3435
} = useGetBalance({
3536
request,
3637
options: {
37-
enabled: !!address,
38+
enabled: !!address.value,
3839
//@ts-ignore
3940
select: ({ balance }) =>
4041
new BigNumber(balance?.amount ?? 0).multipliedBy(
4142
10 ** -COIN_DISPLAY_EXPONENT
4243
),
4344
},
4445
clientResolver: defaultRpcEndpoint,
45-
})
46+
});
4647

4748
return {
4849
balance,
@@ -53,4 +54,4 @@ export const useBalanceVue = (chainName: ref) => {
5354
};
5455
};
5556

56-
export default useBalanceVue;
57+
export default useBalanceVue;

examples/injective-vue/src/main.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { createApp } from 'vue'
2-
import router from './router'
3-
import './style.css'
4-
import "@interchain-ui/vue/style.css";
1+
import { createApp } from 'vue';
2+
import router from './router';
3+
import './style.css';
4+
import '@interchain-ui/vue/style.css';
55
import { VueQueryPlugin, QueryClient } from '@tanstack/vue-query';
6-
// import "@interchain-ui/vue/globalStyles";
7-
import App from './App.vue'
6+
// import '@interchain-ui/vue/globalStyles';
7+
import App from './App.vue';
8+
// polyfill for @interchain-kit/vue <-> core compatibility
9+
import './polyfills/interchain-kit-compat';
810

911
const queryClient = new QueryClient({
1012
defaultOptions: {
@@ -17,10 +19,10 @@ const queryClient = new QueryClient({
1719

1820
// @ts-ignore
1921
BigInt.prototype['toJSON'] = function () {
20-
return this.toString()
21-
}
22+
return this.toString();
23+
};
2224

2325
const app = createApp(App);
2426
app.use(VueQueryPlugin, { queryClient });
25-
app.use(router)
27+
app.use(router);
2628
app.mount('#app');
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { WalletManager, WalletState } from '@interchain-kit/core';
2+
3+
// Runtime polyfill: older @interchain-kit/core versions may not expose getCurrentWallet,
4+
// but @interchain-kit/vue expects it. Provide a minimal implementation.
5+
const proto: any = (
6+
WalletManager as unknown as { prototype?: Record<string, unknown> }
7+
)?.prototype;
8+
9+
if (proto && typeof (proto as any).getCurrentWallet !== 'function') {
10+
(proto as any).getCurrentWallet = function () {
11+
try {
12+
const wallets: any[] = (this as any)?.wallets ?? [];
13+
return wallets.find((w: any) => w?.walletState === WalletState.Connected);
14+
} catch {
15+
return undefined;
16+
}
17+
};
18+
}

0 commit comments

Comments
 (0)