@interchain-kit/react 0.0.1-beta.57 → 0.0.1-beta.58

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,6 +1,7 @@
1
1
  import { useWalletModal } from "../modal";
2
2
  import { useWalletManager } from './useWalletManager';
3
3
  import { ChainNameNotExist } from '@interchain-kit/core';
4
+ import { ChainWallet } from '../store/chain-wallet';
4
5
  export const useChain = (chainName) => {
5
6
  const { assetLists, currentWalletName, disconnect, setCurrentChainName, getChainByName, getWalletByName, getChainWalletState, getChainLogoUrl, connect, getSigningClient, getRpcEndpoint, getAccount } = useWalletManager();
6
7
  const chain = getChainByName(chainName);
@@ -33,12 +34,7 @@ export const useChain = (chainName) => {
33
34
  chain,
34
35
  assetList,
35
36
  address: chainWalletStateToShow?.account?.address,
36
- wallet: wallet ? Object.assign(wallet, {
37
- walletState: chainWalletStateToShow?.walletState,
38
- connect: () => connect(currentWalletName, chainName),
39
- disconnect: () => disconnect(currentWalletName, chainName),
40
- getAccount: () => getAccount(currentWalletName, chainName)
41
- }) : undefined,
37
+ wallet: new ChainWallet(wallet, () => connect(currentWalletName, chainName), () => disconnect(currentWalletName, chainName), () => getAccount(currentWalletName, chainName)),
42
38
  rpcEndpoint: chainWalletStateToShow?.rpcEndpoint,
43
39
  getSigningClient: () => getSigningClient(currentWalletName, chainName),
44
40
  };
@@ -1,6 +1,7 @@
1
1
  import { useWalletManager } from "./useWalletManager";
2
+ import { ChainWallet } from "../store/chain-wallet";
2
3
  export const useChainWallet = (chainName, walletName) => {
3
- const { assetLists, disconnect, getChainByName, getWalletByName, getChainWalletState, getChainLogoUrl, connect, getSigningClient, getRpcEndpoint, getAccount } = useWalletManager();
4
+ const { assetLists, disconnect, setCurrentChainName, setCurrentWalletName, getChainByName, getWalletByName, getChainWalletState, getChainLogoUrl, connect, getSigningClient, getRpcEndpoint, getAccount } = useWalletManager();
4
5
  const chain = getChainByName(chainName);
5
6
  const wallet = getWalletByName(walletName);
6
7
  const assetList = assetLists.find(a => a.chainName === chainName);
@@ -9,6 +10,8 @@ export const useChainWallet = (chainName, walletName) => {
9
10
  //for migration cosmos kit
10
11
  connect: async () => {
11
12
  await connect(walletName, chainName);
13
+ setCurrentWalletName(walletName);
14
+ setCurrentChainName(chainName);
12
15
  await getAccount(walletName, chainName);
13
16
  },
14
17
  disconnect: () => disconnect(walletName, chainName),
@@ -21,12 +24,7 @@ export const useChainWallet = (chainName, walletName) => {
21
24
  chain,
22
25
  assetList,
23
26
  address: chainWalletStateToShow?.account?.address,
24
- wallet: wallet ? Object.assign(wallet, {
25
- walletState: chainWalletStateToShow?.walletState,
26
- connect: () => connect(walletName, chainName),
27
- disconnect: () => disconnect(walletName, chainName),
28
- getAccount: () => getAccount(walletName, chainName)
29
- }) : undefined,
27
+ wallet: new ChainWallet(wallet, () => connect(walletName, chainName), () => disconnect(walletName, chainName), () => getAccount(currentWalletName, chainName)),
30
28
  rpcEndpoint: chainWalletStateToShow?.rpcEndpoint,
31
29
  getSigningClient: () => getSigningClient(walletName, chainName),
32
30
  };
@@ -0,0 +1,59 @@
1
+ import { BaseWallet } from "@interchain-kit/core";
2
+ export class ChainWallet extends BaseWallet {
3
+ originalWallet;
4
+ connectWithState;
5
+ disconnectWithState;
6
+ getAccountWithState;
7
+ constructor(originalWallet, connectWithState, disconnectWithState, getAccountWithState) {
8
+ super(originalWallet.info);
9
+ this.originalWallet = originalWallet;
10
+ this.connectWithState = connectWithState;
11
+ this.disconnectWithState = disconnectWithState;
12
+ this.getAccountWithState = getAccountWithState;
13
+ }
14
+ async init(meta) {
15
+ return this.originalWallet.init(meta);
16
+ }
17
+ async connect(chainId) {
18
+ return this.connectWithState(chainId);
19
+ }
20
+ async disconnect(chainId) {
21
+ return this.disconnectWithState(chainId);
22
+ }
23
+ async getAccount(chainId) {
24
+ return this.getAccountWithState(chainId);
25
+ }
26
+ async getAccounts(chainIds) {
27
+ return this.originalWallet.getAccounts(chainIds);
28
+ }
29
+ async getSimpleAccount(chainId) {
30
+ return this.originalWallet.getSimpleAccount(chainId);
31
+ }
32
+ getOfflineSigner(chainId) {
33
+ return this.originalWallet.getOfflineSigner(chainId);
34
+ }
35
+ getOfflineSignerAmino(chainId) {
36
+ return this.originalWallet.getOfflineSignerAmino(chainId);
37
+ }
38
+ getOfflineSignerDirect(chainId) {
39
+ return this.originalWallet.getOfflineSignerDirect(chainId);
40
+ }
41
+ async signAmino(chainId, signer, signDoc, signOptions) {
42
+ return this.originalWallet.signAmino(chainId, signer, signDoc, signOptions);
43
+ }
44
+ async signArbitrary(chainId, signer, data) {
45
+ return this.originalWallet.signArbitrary(chainId, signer, data);
46
+ }
47
+ async verifyArbitrary(chainId, signer, data) {
48
+ return this.originalWallet.verifyArbitrary(chainId, signer, data);
49
+ }
50
+ async signDirect(chainId, signer, signDoc, signOptions) {
51
+ return this.originalWallet.signDirect(chainId, signer, signDoc, signOptions);
52
+ }
53
+ async sendTx(chainId, tx, mode) {
54
+ return this.originalWallet.sendTx(chainId, tx, mode);
55
+ }
56
+ async addSuggestChain(chain, assetLists) {
57
+ return this.originalWallet.addSuggestChain(chain, assetLists);
58
+ }
59
+ }
@@ -1,2 +1 @@
1
- export * from './wallet';
2
1
  export * from './sign-client';
package/hooks/useChain.js CHANGED
@@ -4,6 +4,7 @@ exports.useChain = void 0;
4
4
  const modal_1 = require("../modal");
5
5
  const useWalletManager_1 = require("./useWalletManager");
6
6
  const core_1 = require("@interchain-kit/core");
7
+ const chain_wallet_1 = require("../store/chain-wallet");
7
8
  const useChain = (chainName) => {
8
9
  const { assetLists, currentWalletName, disconnect, setCurrentChainName, getChainByName, getWalletByName, getChainWalletState, getChainLogoUrl, connect, getSigningClient, getRpcEndpoint, getAccount } = (0, useWalletManager_1.useWalletManager)();
9
10
  const chain = getChainByName(chainName);
@@ -36,12 +37,7 @@ const useChain = (chainName) => {
36
37
  chain,
37
38
  assetList,
38
39
  address: chainWalletStateToShow?.account?.address,
39
- wallet: wallet ? Object.assign(wallet, {
40
- walletState: chainWalletStateToShow?.walletState,
41
- connect: () => connect(currentWalletName, chainName),
42
- disconnect: () => disconnect(currentWalletName, chainName),
43
- getAccount: () => getAccount(currentWalletName, chainName)
44
- }) : undefined,
40
+ wallet: new chain_wallet_1.ChainWallet(wallet, () => connect(currentWalletName, chainName), () => disconnect(currentWalletName, chainName), () => getAccount(currentWalletName, chainName)),
45
41
  rpcEndpoint: chainWalletStateToShow?.rpcEndpoint,
46
42
  getSigningClient: () => getSigningClient(currentWalletName, chainName),
47
43
  };
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useChainWallet = void 0;
4
4
  const useWalletManager_1 = require("./useWalletManager");
5
+ const chain_wallet_1 = require("../store/chain-wallet");
5
6
  const useChainWallet = (chainName, walletName) => {
6
- const { assetLists, disconnect, getChainByName, getWalletByName, getChainWalletState, getChainLogoUrl, connect, getSigningClient, getRpcEndpoint, getAccount } = (0, useWalletManager_1.useWalletManager)();
7
+ const { assetLists, disconnect, setCurrentChainName, setCurrentWalletName, getChainByName, getWalletByName, getChainWalletState, getChainLogoUrl, connect, getSigningClient, getRpcEndpoint, getAccount } = (0, useWalletManager_1.useWalletManager)();
7
8
  const chain = getChainByName(chainName);
8
9
  const wallet = getWalletByName(walletName);
9
10
  const assetList = assetLists.find(a => a.chainName === chainName);
@@ -12,6 +13,8 @@ const useChainWallet = (chainName, walletName) => {
12
13
  //for migration cosmos kit
13
14
  connect: async () => {
14
15
  await connect(walletName, chainName);
16
+ setCurrentWalletName(walletName);
17
+ setCurrentChainName(chainName);
15
18
  await getAccount(walletName, chainName);
16
19
  },
17
20
  disconnect: () => disconnect(walletName, chainName),
@@ -24,12 +27,7 @@ const useChainWallet = (chainName, walletName) => {
24
27
  chain,
25
28
  assetList,
26
29
  address: chainWalletStateToShow?.account?.address,
27
- wallet: wallet ? Object.assign(wallet, {
28
- walletState: chainWalletStateToShow?.walletState,
29
- connect: () => connect(walletName, chainName),
30
- disconnect: () => disconnect(walletName, chainName),
31
- getAccount: () => getAccount(walletName, chainName)
32
- }) : undefined,
30
+ wallet: new chain_wallet_1.ChainWallet(wallet, () => connect(walletName, chainName), () => disconnect(walletName, chainName), () => getAccount(currentWalletName, chainName)),
33
31
  rpcEndpoint: chainWalletStateToShow?.rpcEndpoint,
34
32
  getSigningClient: () => getSigningClient(walletName, chainName),
35
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interchain-kit/react",
3
- "version": "0.0.1-beta.57",
3
+ "version": "0.0.1-beta.58",
4
4
  "author": "cosmology-tech <developers@cosmology.zone>",
5
5
  "description": "interchain-kit wallet connector react package",
6
6
  "main": "index.js",
@@ -33,7 +33,7 @@
33
33
  "keywords": [],
34
34
  "dependencies": {
35
35
  "@chain-registry/v2-types": "^0.53.40",
36
- "@interchain-kit/core": "0.0.1-beta.57",
36
+ "@interchain-kit/core": "0.0.1-beta.58",
37
37
  "@interchain-ui/react": "1.26.1",
38
38
  "@interchainjs/cosmos": "1.6.3",
39
39
  "@interchainjs/cosmos-types": "1.6.3",
@@ -46,5 +46,5 @@
46
46
  "react-dom": "^18.3.1",
47
47
  "zustand": "^5.0.3"
48
48
  },
49
- "gitHead": "7a34f9aff73cea139a65acaa2eae91948e26e281"
49
+ "gitHead": "3e181eabfedf82ee9321d10cf0d46d63a348da31"
50
50
  }
@@ -0,0 +1,26 @@
1
+ import { Chain, AssetList } from "@chain-registry/v2-types";
2
+ import { BaseWallet, BroadcastMode, DirectSignDoc, SignOptions, SimpleAccount, WalletAccount } from "@interchain-kit/core";
3
+ import { OfflineSigner, OfflineAminoSigner, OfflineDirectSigner, AminoSignResponse, StdSignature, DirectSignResponse } from "@interchainjs/cosmos/types/wallet";
4
+ import { StdSignDoc } from "@interchainjs/types";
5
+ export declare class ChainWallet<TWallet extends BaseWallet> extends BaseWallet {
6
+ originalWallet: TWallet;
7
+ connectWithState: TWallet['connect'];
8
+ disconnectWithState: TWallet['disconnect'];
9
+ getAccountWithState: TWallet['getAccount'];
10
+ constructor(originalWallet: TWallet, connectWithState: TWallet['connect'], disconnectWithState: TWallet['disconnect'], getAccountWithState: TWallet['getAccount']);
11
+ init(meta?: unknown): Promise<void>;
12
+ connect(chainId: string | string[]): Promise<void>;
13
+ disconnect(chainId: string | string[]): Promise<void>;
14
+ getAccount(chainId: string): Promise<WalletAccount>;
15
+ getAccounts(chainIds: string[]): Promise<WalletAccount[]>;
16
+ getSimpleAccount(chainId: string): Promise<SimpleAccount>;
17
+ getOfflineSigner(chainId: string): OfflineSigner;
18
+ getOfflineSignerAmino(chainId: string): OfflineAminoSigner;
19
+ getOfflineSignerDirect(chainId: string): OfflineDirectSigner;
20
+ signAmino(chainId: string, signer: string, signDoc: StdSignDoc, signOptions?: SignOptions): Promise<AminoSignResponse>;
21
+ signArbitrary(chainId: string, signer: string, data: string | Uint8Array): Promise<StdSignature>;
22
+ verifyArbitrary(chainId: string, signer: string, data: string | Uint8Array): Promise<boolean>;
23
+ signDirect(chainId: string, signer: string, signDoc: DirectSignDoc, signOptions?: SignOptions): Promise<DirectSignResponse>;
24
+ sendTx(chainId: string, tx: Uint8Array, mode: BroadcastMode): Promise<Uint8Array>;
25
+ addSuggestChain(chain: Chain, assetLists: AssetList[]): Promise<void>;
26
+ }
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChainWallet = void 0;
4
+ const core_1 = require("@interchain-kit/core");
5
+ class ChainWallet extends core_1.BaseWallet {
6
+ originalWallet;
7
+ connectWithState;
8
+ disconnectWithState;
9
+ getAccountWithState;
10
+ constructor(originalWallet, connectWithState, disconnectWithState, getAccountWithState) {
11
+ super(originalWallet.info);
12
+ this.originalWallet = originalWallet;
13
+ this.connectWithState = connectWithState;
14
+ this.disconnectWithState = disconnectWithState;
15
+ this.getAccountWithState = getAccountWithState;
16
+ }
17
+ async init(meta) {
18
+ return this.originalWallet.init(meta);
19
+ }
20
+ async connect(chainId) {
21
+ return this.connectWithState(chainId);
22
+ }
23
+ async disconnect(chainId) {
24
+ return this.disconnectWithState(chainId);
25
+ }
26
+ async getAccount(chainId) {
27
+ return this.getAccountWithState(chainId);
28
+ }
29
+ async getAccounts(chainIds) {
30
+ return this.originalWallet.getAccounts(chainIds);
31
+ }
32
+ async getSimpleAccount(chainId) {
33
+ return this.originalWallet.getSimpleAccount(chainId);
34
+ }
35
+ getOfflineSigner(chainId) {
36
+ return this.originalWallet.getOfflineSigner(chainId);
37
+ }
38
+ getOfflineSignerAmino(chainId) {
39
+ return this.originalWallet.getOfflineSignerAmino(chainId);
40
+ }
41
+ getOfflineSignerDirect(chainId) {
42
+ return this.originalWallet.getOfflineSignerDirect(chainId);
43
+ }
44
+ async signAmino(chainId, signer, signDoc, signOptions) {
45
+ return this.originalWallet.signAmino(chainId, signer, signDoc, signOptions);
46
+ }
47
+ async signArbitrary(chainId, signer, data) {
48
+ return this.originalWallet.signArbitrary(chainId, signer, data);
49
+ }
50
+ async verifyArbitrary(chainId, signer, data) {
51
+ return this.originalWallet.verifyArbitrary(chainId, signer, data);
52
+ }
53
+ async signDirect(chainId, signer, signDoc, signOptions) {
54
+ return this.originalWallet.signDirect(chainId, signer, signDoc, signOptions);
55
+ }
56
+ async sendTx(chainId, tx, mode) {
57
+ return this.originalWallet.sendTx(chainId, tx, mode);
58
+ }
59
+ async addSuggestChain(chain, assetLists) {
60
+ return this.originalWallet.addSuggestChain(chain, assetLists);
61
+ }
62
+ }
63
+ exports.ChainWallet = ChainWallet;
package/types/index.d.ts CHANGED
@@ -1,2 +1 @@
1
- export * from './wallet';
2
1
  export * from './sign-client';
package/types/index.js CHANGED
@@ -14,5 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./wallet"), exports);
18
17
  __exportStar(require("./sign-client"), exports);
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- export function bindAllMethodsToContext(context) {
2
- return new Proxy(context, {
3
- get(target, prop, receiver) {
4
- const value = Reflect.get(target, prop, receiver);
5
- if (typeof value === 'function') {
6
- return value.bind(context);
7
- }
8
- return value;
9
- }
10
- });
11
- }
package/types/wallet.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { BaseWallet } from "@interchain-kit/core";
2
- import { ConnectState } from "../enum";
3
- export type UseWalletReturnType = {
4
- wallet: BaseWallet;
5
- connect: (chainId: string | string[]) => void;
6
- connectState: ConnectState;
7
- };
8
- export type WalletState = {
9
- name: string;
10
- connectState: ConnectState;
11
- };
package/types/wallet.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export declare function bindAllMethodsToContext<T extends object>(context: T): T;
package/utils/helpers.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bindAllMethodsToContext = bindAllMethodsToContext;
4
- function bindAllMethodsToContext(context) {
5
- return new Proxy(context, {
6
- get(target, prop, receiver) {
7
- const value = Reflect.get(target, prop, receiver);
8
- if (typeof value === 'function') {
9
- return value.bind(context);
10
- }
11
- return value;
12
- }
13
- });
14
- }