@interchain-kit/react 0.0.1-beta.26 → 0.0.1-beta.28

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/README.md CHANGED
@@ -106,7 +106,7 @@ console.log(balance)
106
106
 
107
107
  ```
108
108
 
109
- ## useChainWallet
109
+ ### useChainWallet
110
110
  ```js
111
111
  import { keplrWallet } from "@interchain-kit/keplr-extension";
112
112
  import { leapWallet } from "@interchain-kit/leap-extension";
@@ -1,11 +1,15 @@
1
- import { useEffect, useState } from "react";
1
+ import { useEffect, useMemo, useState } from "react";
2
2
  import { WalletState } from "@interchain-kit/core";
3
3
  import { useWalletManager } from './useWalletManager';
4
4
  export const useAccount = (chainName, walletName) => {
5
5
  const walletManager = useWalletManager();
6
- const wallet = walletManager.wallets.find(w => w.option.name === walletName);
6
+ const wallet = useMemo(() => {
7
+ return walletManager.wallets.find(w => w.option.name === walletName);
8
+ }, [walletManager, walletName]);
7
9
  const [account, setAccount] = useState(null);
8
- const chain = walletManager.chains.find(c => c.chainName === chainName);
10
+ const chain = useMemo(() => {
11
+ return walletManager.chains.find(c => c.chainName === chainName);
12
+ }, [walletManager, chainName]);
9
13
  const getAccount = async () => {
10
14
  if (wallet && chain) {
11
15
  if (wallet.walletState === WalletState.Connected) {
@@ -16,6 +20,9 @@ export const useAccount = (chainName, walletName) => {
16
20
  setAccount(null);
17
21
  }
18
22
  }
23
+ if (!wallet) {
24
+ setAccount(null);
25
+ }
19
26
  };
20
27
  useEffect(() => {
21
28
  if (wallet) {
@@ -4,7 +4,7 @@ import { useCurrentWallet } from './useCurrentWallet';
4
4
  import { useInterchainClient } from './useInterchainClient';
5
5
  import { useWalletModal } from "../modal";
6
6
  import { ChainNameNotExist } from "@interchain-kit/core";
7
- import { getChainLogoUrl } from "../utils";
7
+ import { useCallback } from "react";
8
8
  export const useChain = (chainName) => {
9
9
  const walletManager = useWalletManager();
10
10
  const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
@@ -16,6 +16,12 @@ export const useChain = (chainName) => {
16
16
  throw new ChainNameNotExist(chainName);
17
17
  }
18
18
  const { open, close } = useWalletModal();
19
+ const getRpcEndpoint = useCallback(async () => {
20
+ return await walletManager.getRpcEndpoint(currentWallet, chainName);
21
+ }, [walletManager, currentWallet, chainName]);
22
+ const disconnect = useCallback(() => {
23
+ walletManager.disconnect(currentWallet?.option?.name);
24
+ }, [walletManager, currentWallet]);
19
25
  const cosmosKitUserChainReturnType = {
20
26
  connect: () => {
21
27
  if (currentWallet) {
@@ -23,9 +29,10 @@ export const useChain = (chainName) => {
23
29
  }
24
30
  open();
25
31
  },
32
+ disconnect,
26
33
  openView: open,
27
34
  closeView: close,
28
- getRpcEndpoint: () => walletManager.getRpcEndpoint(currentWallet, chainName),
35
+ getRpcEndpoint,
29
36
  status: currentWallet?.walletState,
30
37
  username: account?.username,
31
38
  message: currentWallet?.errorMessage,
@@ -33,7 +40,7 @@ export const useChain = (chainName) => {
33
40
  getSigningCosmosClient: () => walletManager.getSigningCosmosClient(currentWallet.option.name, chainName),
34
41
  };
35
42
  return {
36
- logoUrl: getChainLogoUrl(assetList),
43
+ logoUrl: walletManager.getChainLogoUrl(chainName),
37
44
  chain: chainToShow,
38
45
  assetList,
39
46
  address: account?.address,
@@ -1,7 +1,6 @@
1
1
  import { useWalletManager } from "./useWalletManager";
2
2
  import { useAccount } from "./useAccount";
3
3
  import { useInterchainClient } from "./useInterchainClient";
4
- import { getChainLogoUrl } from "../utils";
5
4
  export const useChainWallet = (chainName, walletName) => {
6
5
  const walletManager = useWalletManager();
7
6
  const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
@@ -10,7 +9,7 @@ export const useChainWallet = (chainName, walletName) => {
10
9
  const account = useAccount(chainName, walletName);
11
10
  const interchainClient = useInterchainClient(chainName, walletName);
12
11
  return {
13
- logoUrl: getChainLogoUrl(assetList),
12
+ logoUrl: walletManager.getChainLogoUrl(chainName),
14
13
  chain: chainToShow,
15
14
  assetList,
16
15
  address: account?.address,
package/esm/provider.js CHANGED
@@ -3,7 +3,6 @@ import { useEffect, useMemo, useState } 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 "@interchain-ui/react/styles";
7
6
  const InterchainWalletContext = createContext(null);
8
7
  export const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endpointOptions, children, }) => {
9
8
  const [_, forceRender] = useState({});
@@ -1,2 +1 @@
1
1
  export * from './wallet';
2
- export * from './chain';
@@ -6,9 +6,13 @@ const core_1 = require("@interchain-kit/core");
6
6
  const useWalletManager_1 = require("./useWalletManager");
7
7
  const useAccount = (chainName, walletName) => {
8
8
  const walletManager = (0, useWalletManager_1.useWalletManager)();
9
- const wallet = walletManager.wallets.find(w => w.option.name === walletName);
9
+ const wallet = (0, react_1.useMemo)(() => {
10
+ return walletManager.wallets.find(w => w.option.name === walletName);
11
+ }, [walletManager, walletName]);
10
12
  const [account, setAccount] = (0, react_1.useState)(null);
11
- const chain = walletManager.chains.find(c => c.chainName === chainName);
13
+ const chain = (0, react_1.useMemo)(() => {
14
+ return walletManager.chains.find(c => c.chainName === chainName);
15
+ }, [walletManager, chainName]);
12
16
  const getAccount = async () => {
13
17
  if (wallet && chain) {
14
18
  if (wallet.walletState === core_1.WalletState.Connected) {
@@ -19,6 +23,9 @@ const useAccount = (chainName, walletName) => {
19
23
  setAccount(null);
20
24
  }
21
25
  }
26
+ if (!wallet) {
27
+ setAccount(null);
28
+ }
22
29
  };
23
30
  (0, react_1.useEffect)(() => {
24
31
  if (wallet) {
package/hooks/useChain.js CHANGED
@@ -7,7 +7,7 @@ const useCurrentWallet_1 = require("./useCurrentWallet");
7
7
  const useInterchainClient_1 = require("./useInterchainClient");
8
8
  const modal_1 = require("../modal");
9
9
  const core_1 = require("@interchain-kit/core");
10
- const utils_1 = require("../utils");
10
+ const react_1 = require("react");
11
11
  const useChain = (chainName) => {
12
12
  const walletManager = (0, useWalletManager_1.useWalletManager)();
13
13
  const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
@@ -19,6 +19,12 @@ const useChain = (chainName) => {
19
19
  throw new core_1.ChainNameNotExist(chainName);
20
20
  }
21
21
  const { open, close } = (0, modal_1.useWalletModal)();
22
+ const getRpcEndpoint = (0, react_1.useCallback)(async () => {
23
+ return await walletManager.getRpcEndpoint(currentWallet, chainName);
24
+ }, [walletManager, currentWallet, chainName]);
25
+ const disconnect = (0, react_1.useCallback)(() => {
26
+ walletManager.disconnect(currentWallet?.option?.name);
27
+ }, [walletManager, currentWallet]);
22
28
  const cosmosKitUserChainReturnType = {
23
29
  connect: () => {
24
30
  if (currentWallet) {
@@ -26,9 +32,10 @@ const useChain = (chainName) => {
26
32
  }
27
33
  open();
28
34
  },
35
+ disconnect,
29
36
  openView: open,
30
37
  closeView: close,
31
- getRpcEndpoint: () => walletManager.getRpcEndpoint(currentWallet, chainName),
38
+ getRpcEndpoint,
32
39
  status: currentWallet?.walletState,
33
40
  username: account?.username,
34
41
  message: currentWallet?.errorMessage,
@@ -36,7 +43,7 @@ const useChain = (chainName) => {
36
43
  getSigningCosmosClient: () => walletManager.getSigningCosmosClient(currentWallet.option.name, chainName),
37
44
  };
38
45
  return {
39
- logoUrl: (0, utils_1.getChainLogoUrl)(assetList),
46
+ logoUrl: walletManager.getChainLogoUrl(chainName),
40
47
  chain: chainToShow,
41
48
  assetList,
42
49
  address: account?.address,
@@ -4,7 +4,6 @@ exports.useChainWallet = void 0;
4
4
  const useWalletManager_1 = require("./useWalletManager");
5
5
  const useAccount_1 = require("./useAccount");
6
6
  const useInterchainClient_1 = require("./useInterchainClient");
7
- const utils_1 = require("../utils");
8
7
  const useChainWallet = (chainName, walletName) => {
9
8
  const walletManager = (0, useWalletManager_1.useWalletManager)();
10
9
  const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
@@ -13,7 +12,7 @@ const useChainWallet = (chainName, walletName) => {
13
12
  const account = (0, useAccount_1.useAccount)(chainName, walletName);
14
13
  const interchainClient = (0, useInterchainClient_1.useInterchainClient)(chainName, walletName);
15
14
  return {
16
- logoUrl: (0, utils_1.getChainLogoUrl)(assetList),
15
+ logoUrl: walletManager.getChainLogoUrl(chainName),
17
16
  chain: chainToShow,
18
17
  assetList,
19
18
  address: account?.address,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interchain-kit/react",
3
- "version": "0.0.1-beta.26",
3
+ "version": "0.0.1-beta.28",
4
4
  "author": "cosmology-tech <developers@cosmology.zone>",
5
5
  "description": "interchain-kit wallet connector react package",
6
6
  "main": "index.js",
@@ -32,8 +32,8 @@
32
32
  },
33
33
  "keywords": [],
34
34
  "dependencies": {
35
- "@chain-registry/v2-types": "^0.49.6",
36
- "@interchain-kit/core": "0.0.1-beta.26",
35
+ "@chain-registry/v2-types": "^0.53.0",
36
+ "@interchain-kit/core": "0.0.1-beta.28",
37
37
  "@interchain-ui/react": "1.24.0",
38
38
  "@interchainjs/cosmos-types": "0.0.1-beta.9",
39
39
  "@interchainjs/injective": "0.0.1-beta.13",
@@ -43,5 +43,5 @@
43
43
  "react": "^18.3.1",
44
44
  "react-dom": "^18.3.1"
45
45
  },
46
- "gitHead": "3f531ca46617882f4c3c8f0ea431155223236570"
46
+ "gitHead": "f360ae081a1155e7457a951ae10a598d38e3e383"
47
47
  }
package/provider.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import React from "react";
2
2
  import { BaseWallet, SignerOptions, WalletManager, EndpointOptions } from "@interchain-kit/core";
3
3
  import { AssetList, Chain } from "@chain-registry/v2-types";
4
- import "@interchain-ui/react/styles";
5
4
  type InterchainWalletContextType = {
6
5
  walletManager: WalletManager;
7
6
  };
package/provider.js CHANGED
@@ -6,7 +6,6 @@ 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
- require("@interchain-ui/react/styles");
10
9
  const InterchainWalletContext = (0, react_2.createContext)(null);
11
10
  const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endpointOptions, children, }) => {
12
11
  const [_, forceRender] = (0, react_1.useState)({});
package/types/chain.d.ts CHANGED
@@ -7,6 +7,7 @@ import { Chain, AssetList } from '@chain-registry/v2-types';
7
7
  import { BaseWallet, WalletState } from '@interchain-kit/core';
8
8
  export type CosmosKitUseChainReturnType = {
9
9
  connect: () => void;
10
+ disconnect: () => void;
10
11
  openView: () => void;
11
12
  closeView: () => void;
12
13
  getRpcEndpoint: () => Promise<string | HttpEndpoint>;
package/utils/index.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  export * from './wallet';
2
- export * from './chain';
package/utils/index.js CHANGED
@@ -15,4 +15,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./wallet"), exports);
18
- __exportStar(require("./chain"), exports);
@@ -1,3 +0,0 @@
1
- export const getChainLogoUrl = (assetList) => {
2
- return assetList.assets?.[0].logoURIs.png || assetList.assets?.[0].logoURIs.svg || undefined;
3
- };
package/utils/chain.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { AssetList } from "@chain-registry/v2-types";
2
- export declare const getChainLogoUrl: (assetList: AssetList) => string | undefined;
package/utils/chain.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getChainLogoUrl = void 0;
4
- const getChainLogoUrl = (assetList) => {
5
- return assetList.assets?.[0].logoURIs.png || assetList.assets?.[0].logoURIs.svg || undefined;
6
- };
7
- exports.getChainLogoUrl = getChainLogoUrl;