@interchain-kit/react 0.2.204 → 0.2.206

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.
@@ -1,17 +1,6 @@
1
- import { useStore } from "zustand";
2
1
  import { useInterchainWalletContext } from "../provider";
3
- function bindMethodsToContext(context) {
4
- for (const key of Object.getOwnPropertyNames(Object.getPrototypeOf(context))) {
5
- const value = context[key];
6
- if (typeof value === 'function') {
7
- context[key] = value.bind(context);
8
- }
9
- }
10
- }
2
+ import { useStore } from 'zustand';
11
3
  export const useWalletManager = () => {
12
- const object = useInterchainWalletContext();
13
- // put useStore here to update the hook
14
- const store = useStore(object.store);
15
- bindMethodsToContext(object);
16
- return object;
4
+ const store = useInterchainWalletContext();
5
+ return useStore(store);
17
6
  };
package/esm/provider.js CHANGED
@@ -1,16 +1,19 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect } from "react";
2
+ import { useEffect, useRef } from "react";
3
3
  import { createContext, useContext } from "react";
4
4
  import { WalletManager, } from "@interchain-kit/core";
5
5
  import { WalletModalProvider } from "./modal";
6
+ import { createInterchainStore } from "./store";
6
7
  const InterchainWalletContext = createContext(null);
7
8
  export const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endpointOptions, children, }) => {
8
9
  // const [_, forceRender] = useState({});
9
10
  const walletManager = new WalletManager(chains, assetLists, wallets, signerOptions, endpointOptions);
11
+ const store = useRef(createInterchainStore(walletManager));
10
12
  useEffect(() => {
11
- walletManager.init();
13
+ // walletManager.init();
14
+ store.current.getState().init();
12
15
  }, []);
13
- return (_jsx(InterchainWalletContext.Provider, { value: walletManager, children: _jsx(WalletModalProvider, { children: children }) }));
16
+ return (_jsx(InterchainWalletContext.Provider, { value: store.current, children: _jsx(WalletModalProvider, { children: children }) }));
14
17
  };
15
18
  export const useInterchainWalletContext = () => {
16
19
  const context = useContext(InterchainWalletContext);
@@ -17,23 +17,8 @@ const immerSyncUp = (newWalletManager) => {
17
17
  export const createInterchainStore = (walletManager) => {
18
18
  const { chains, assetLists, wallets, signerOptions, endpointOptions } = walletManager;
19
19
  // const walletManager = new WalletManager(chains, assetLists, wallets, signerOptions, endpointOptions)
20
- const chainWalletState = [];
21
- wallets.forEach(wallet => {
22
- chains.forEach(chain => {
23
- chainWalletState.push({
24
- chainName: chain.chainName,
25
- walletName: wallet.info.name,
26
- walletState: WalletState.Disconnected,
27
- rpcEndpoint: "",
28
- errorMessage: "",
29
- signerOption: undefined,
30
- account: undefined
31
- });
32
- });
33
- });
34
20
  return createStore(persist(immer((set, get) => ({
35
- store: walletManager.store,
36
- chainWalletState,
21
+ chainWalletState: [],
37
22
  currentWalletName: '',
38
23
  currentChainName: '',
39
24
  chains: [...walletManager.chains],
@@ -51,6 +36,23 @@ export const createInterchainStore = (walletManager) => {
51
36
  });
52
37
  },
53
38
  init: async () => {
39
+ const existedChainWalletStatesMap = new Map(get().chainWalletState.map(cws => [cws.walletName + cws.chainName, cws]));
40
+ wallets.forEach(wallet => {
41
+ chains.forEach(chain => {
42
+ if (!existedChainWalletStatesMap.has(wallet.info.name + chain.chainName)) {
43
+ set(draft => {
44
+ draft.chainWalletState.push({
45
+ chainName: chain.chainName,
46
+ walletName: wallet.info.name,
47
+ walletState: WalletState.Disconnected,
48
+ rpcEndpoint: "",
49
+ errorMessage: "",
50
+ account: undefined
51
+ });
52
+ });
53
+ }
54
+ });
55
+ });
54
56
  const NotExistWallets = [];
55
57
  await Promise.all(get().wallets.map(async (wallet) => {
56
58
  try {
@@ -106,7 +108,6 @@ export const createInterchainStore = (walletManager) => {
106
108
  walletState: WalletState.Disconnected,
107
109
  rpcEndpoint: "",
108
110
  errorMessage: "",
109
- signerOption: signerOptions?.signing?.(newChain.chainName),
110
111
  account: undefined
111
112
  });
112
113
  });
@@ -1 +1 @@
1
- export declare const useWalletManager: () => import("@interchain-kit/core").WalletManager;
1
+ export declare const useWalletManager: () => import("..").InterchainStore;
@@ -1,21 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useWalletManager = void 0;
4
- const zustand_1 = require("zustand");
5
4
  const provider_1 = require("../provider");
6
- function bindMethodsToContext(context) {
7
- for (const key of Object.getOwnPropertyNames(Object.getPrototypeOf(context))) {
8
- const value = context[key];
9
- if (typeof value === 'function') {
10
- context[key] = value.bind(context);
11
- }
12
- }
13
- }
5
+ const zustand_1 = require("zustand");
14
6
  const useWalletManager = () => {
15
- const object = (0, provider_1.useInterchainWalletContext)();
16
- // put useStore here to update the hook
17
- const store = (0, zustand_1.useStore)(object.store);
18
- bindMethodsToContext(object);
19
- return object;
7
+ const store = (0, provider_1.useInterchainWalletContext)();
8
+ return (0, zustand_1.useStore)(store);
20
9
  };
21
10
  exports.useWalletManager = useWalletManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interchain-kit/react",
3
- "version": "0.2.204",
3
+ "version": "0.2.206",
4
4
  "author": "Hyperweb <developers@hyperweb.io>",
5
5
  "description": "interchain-kit wallet connector react package",
6
6
  "main": "index.js",
@@ -33,18 +33,18 @@
33
33
  "keywords": [],
34
34
  "dependencies": {
35
35
  "@chain-registry/v2-types": "^0.53.40",
36
- "@interchain-kit/core": "0.2.204",
36
+ "@interchain-kit/core": "0.2.206",
37
37
  "@interchain-ui/react": "1.26.1",
38
- "@interchainjs/cosmos": "1.9.12",
39
- "@interchainjs/cosmos-types": "1.9.12",
38
+ "@interchainjs/cosmos": "1.9.16",
39
+ "@interchainjs/cosmos-types": "1.9.16",
40
40
  "@react-icons/all-files": "^4.1.0",
41
41
  "@types/react": "^18.3.3",
42
42
  "@types/react-dom": "^18.3.0",
43
43
  "@walletconnect/types": "^2.17.3",
44
- "interchainjs": "1.9.12",
44
+ "interchainjs": "1.9.16",
45
45
  "react": "^18.3.1",
46
46
  "react-dom": "^18.3.1",
47
47
  "zustand": "^5.0.3"
48
48
  },
49
- "gitHead": "256ae367a0ff176254eac9e8695f64099ba7b1a1"
49
+ "gitHead": "97627f5e83dc79e50bf62dd64577015fb582495c"
50
50
  }
package/provider.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import React from "react";
2
- import { BaseWallet, SignerOptions, EndpointOptions, WalletManager } from "@interchain-kit/core";
2
+ import { BaseWallet, SignerOptions, EndpointOptions } from "@interchain-kit/core";
3
3
  import { AssetList, Chain } from "@chain-registry/v2-types";
4
+ import { InterchainStore } from "./store";
5
+ import { StoreApi } from "zustand";
6
+ type InterchainWalletContextType = StoreApi<InterchainStore>;
4
7
  type InterchainWalletProviderProps = {
5
8
  chains: Chain[];
6
9
  assetLists: AssetList[];
@@ -10,5 +13,5 @@ type InterchainWalletProviderProps = {
10
13
  children: React.ReactNode;
11
14
  };
12
15
  export declare const ChainProvider: ({ chains, assetLists, wallets, signerOptions, endpointOptions, children, }: InterchainWalletProviderProps) => import("react/jsx-runtime").JSX.Element;
13
- export declare const useInterchainWalletContext: () => WalletManager;
16
+ export declare const useInterchainWalletContext: () => InterchainWalletContextType;
14
17
  export {};
package/provider.js CHANGED
@@ -6,14 +6,17 @@ const react_1 = require("react");
6
6
  const react_2 = require("react");
7
7
  const core_1 = require("@interchain-kit/core");
8
8
  const modal_1 = require("./modal");
9
+ const store_1 = require("./store");
9
10
  const InterchainWalletContext = (0, react_2.createContext)(null);
10
11
  const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endpointOptions, children, }) => {
11
12
  // const [_, forceRender] = useState({});
12
13
  const walletManager = new core_1.WalletManager(chains, assetLists, wallets, signerOptions, endpointOptions);
14
+ const store = (0, react_1.useRef)((0, store_1.createInterchainStore)(walletManager));
13
15
  (0, react_1.useEffect)(() => {
14
- walletManager.init();
16
+ // walletManager.init();
17
+ store.current.getState().init();
15
18
  }, []);
16
- return ((0, jsx_runtime_1.jsx)(InterchainWalletContext.Provider, { value: walletManager, children: (0, jsx_runtime_1.jsx)(modal_1.WalletModalProvider, { children: children }) }));
19
+ return ((0, jsx_runtime_1.jsx)(InterchainWalletContext.Provider, { value: store.current, children: (0, jsx_runtime_1.jsx)(modal_1.WalletModalProvider, { children: children }) }));
17
20
  };
18
21
  exports.ChainProvider = ChainProvider;
19
22
  const useInterchainWalletContext = () => {
package/store/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { AssetList, Chain } from "@chain-registry/v2-types";
2
2
  import { BaseWallet, EndpointOptions, SignerOptions, WalletAccount, WalletManager, WalletState } from "@interchain-kit/core";
3
- import { SigningOptions as InterchainSignerOptions } from '@interchainjs/cosmos/types/signing-client';
4
3
  import { HttpEndpoint } from '@interchainjs/types';
5
4
  type ChainWalletState = {
6
5
  chainName: string;
@@ -8,7 +7,6 @@ type ChainWalletState = {
8
7
  walletState: WalletState;
9
8
  rpcEndpoint: string | HttpEndpoint;
10
9
  errorMessage: string;
11
- signerOption: InterchainSignerOptions;
12
10
  account: WalletAccount;
13
11
  };
14
12
  export interface InterchainStore extends WalletManager {
package/store/index.js CHANGED
@@ -20,23 +20,8 @@ const immerSyncUp = (newWalletManager) => {
20
20
  const createInterchainStore = (walletManager) => {
21
21
  const { chains, assetLists, wallets, signerOptions, endpointOptions } = walletManager;
22
22
  // const walletManager = new WalletManager(chains, assetLists, wallets, signerOptions, endpointOptions)
23
- const chainWalletState = [];
24
- wallets.forEach(wallet => {
25
- chains.forEach(chain => {
26
- chainWalletState.push({
27
- chainName: chain.chainName,
28
- walletName: wallet.info.name,
29
- walletState: core_1.WalletState.Disconnected,
30
- rpcEndpoint: "",
31
- errorMessage: "",
32
- signerOption: undefined,
33
- account: undefined
34
- });
35
- });
36
- });
37
23
  return (0, zustand_1.createStore)((0, middleware_1.persist)((0, immer_1.immer)((set, get) => ({
38
- store: walletManager.store,
39
- chainWalletState,
24
+ chainWalletState: [],
40
25
  currentWalletName: '',
41
26
  currentChainName: '',
42
27
  chains: [...walletManager.chains],
@@ -54,6 +39,23 @@ const createInterchainStore = (walletManager) => {
54
39
  });
55
40
  },
56
41
  init: async () => {
42
+ const existedChainWalletStatesMap = new Map(get().chainWalletState.map(cws => [cws.walletName + cws.chainName, cws]));
43
+ wallets.forEach(wallet => {
44
+ chains.forEach(chain => {
45
+ if (!existedChainWalletStatesMap.has(wallet.info.name + chain.chainName)) {
46
+ set(draft => {
47
+ draft.chainWalletState.push({
48
+ chainName: chain.chainName,
49
+ walletName: wallet.info.name,
50
+ walletState: core_1.WalletState.Disconnected,
51
+ rpcEndpoint: "",
52
+ errorMessage: "",
53
+ account: undefined
54
+ });
55
+ });
56
+ }
57
+ });
58
+ });
57
59
  const NotExistWallets = [];
58
60
  await Promise.all(get().wallets.map(async (wallet) => {
59
61
  try {
@@ -109,7 +111,6 @@ const createInterchainStore = (walletManager) => {
109
111
  walletState: core_1.WalletState.Disconnected,
110
112
  rpcEndpoint: "",
111
113
  errorMessage: "",
112
- signerOption: signerOptions?.signing?.(newChain.chainName),
113
114
  account: undefined
114
115
  });
115
116
  });
package/utils/wallet.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BaseWallet } from "@interchain-kit/core";
2
2
  export declare const getWalletInfo: (wallet: BaseWallet) => {
3
- name: string;
4
- prettyName: string;
3
+ name: any;
4
+ prettyName: any;
5
5
  logo: string;
6
6
  mobileDisabled: boolean;
7
7
  };