@interchain-kit/store 0.3.47 → 0.3.49

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/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from './wallet-manager';
2
- export * from './types';
3
1
  export * from './store';
2
+ export * from './types';
3
+ export * from './wallet-manager';
@@ -1,8 +1,9 @@
1
- import { isInstanceOf } from '@interchain-kit/core';
1
+ import { isInstanceOf, SolanaWallet } from '@interchain-kit/core';
2
2
  import { CosmosWallet, EthereumWallet, MultiChainWallet } from '@interchain-kit/core';
3
3
  import { createCosmosWallet } from './cosmos-wallet';
4
4
  import { createEthereumWallet } from './ethereum-wallet';
5
5
  import { createMultiChainWallet } from './multi-chain-wallet';
6
+ import { createSolanaWallet } from './solana-wallet';
6
7
  // import { createWCWallet } from './wc-wallet';
7
8
  export const createProxiedWallet = (wallet, store) => {
8
9
  // WalletConnect wallets are now handled by the generic AOP system
@@ -13,6 +14,9 @@ export const createProxiedWallet = (wallet, store) => {
13
14
  if (isInstanceOf(wallet, EthereumWallet)) {
14
15
  return createEthereumWallet(wallet, store);
15
16
  }
17
+ if (isInstanceOf(wallet, SolanaWallet)) {
18
+ return createSolanaWallet(wallet, store);
19
+ }
16
20
  if (isInstanceOf(wallet, MultiChainWallet)) {
17
21
  Array.from(wallet.networkWalletMap.keys()).forEach(chainType => {
18
22
  const chainWallet = wallet.networkWalletMap.get(chainType);
@@ -22,6 +26,9 @@ export const createProxiedWallet = (wallet, store) => {
22
26
  if (isInstanceOf(chainWallet, EthereumWallet)) {
23
27
  wallet.setNetworkWallet(chainType, createEthereumWallet(chainWallet, store));
24
28
  }
29
+ if (isInstanceOf(chainWallet, SolanaWallet)) {
30
+ wallet.setNetworkWallet(chainType, createSolanaWallet(chainWallet, store));
31
+ }
25
32
  });
26
33
  return createMultiChainWallet(wallet, store);
27
34
  }
@@ -0,0 +1,13 @@
1
+ import { createAOPProxy } from '../utils';
2
+ export const createSolanaWallet = (target, store) => {
3
+ return createAOPProxy({
4
+ target,
5
+ advice: {
6
+ signTransaction: {
7
+ onError(methodName, target, error, transaction) {
8
+ store.updateChainWalletState(target.info.name, 'solana', { errorMessage: error.message });
9
+ },
10
+ },
11
+ }
12
+ });
13
+ };
@@ -120,6 +120,6 @@ export class InterchainStore {
120
120
  this.setState({ chainWalletStates: newChainWalletStates });
121
121
  }
122
122
  isChainWalletStateExisted(walletName, chainName) {
123
- return this.chainWalletIndexMap.get(`${walletName}-${chainName}`);
123
+ return this.chainWalletIndexMap.get(`${walletName}-${chainName}`) !== undefined;
124
124
  }
125
125
  }
@@ -11,6 +11,7 @@ export class ChainWalletStore extends BaseWallet {
11
11
  this.chain = chain;
12
12
  this.store = store;
13
13
  this.walletManager = walletManager;
14
+ this.info = this.wallet.info;
14
15
  }
15
16
  get walletState() {
16
17
  return this.store.getChainWalletState(this.chain.chainName, this.wallet.info.name)?.walletState || WalletState.NotExist;
@@ -35,7 +36,7 @@ export class ChainWalletStore extends BaseWallet {
35
36
  });
36
37
  }
37
38
  try {
38
- this.store.updateChainWalletState(this.wallet.info.name, this.chain.chainName, { walletState: WalletState.Connecting });
39
+ this.store.updateChainWalletState(this.wallet.info.name, this.chain.chainName, { walletState: WalletState.Connecting, errorMessage: '' });
39
40
  await this.wallet.connect(this.chain.chainId);
40
41
  const account = await this.getAccount();
41
42
  this.store.updateChainWalletState(this.wallet.info.name, this.chain.chainName, { walletState: WalletState.Connected, account });
@@ -61,7 +62,6 @@ export class ChainWalletStore extends BaseWallet {
61
62
  async refreshAccount() {
62
63
  try {
63
64
  const account = await this.wallet.getAccount(this.chain.chainId);
64
- console.log(this.wallet);
65
65
  this.store.updateChainWalletState(this.wallet.info.name, this.chain.chainName, { account });
66
66
  }
67
67
  catch (error) {
@@ -1,3 +1,3 @@
1
+ export * from './chain-wallet-store';
1
2
  export * from './wallet-manager-store';
2
3
  export * from './wallet-store';
3
- export * from './chain-wallet-store';
@@ -36,9 +36,7 @@ export class WalletManagerStore {
36
36
  currentChainName: state.currentChainName,
37
37
  });
38
38
  });
39
- await Promise.all(this.wallets.map(wallet => {
40
- return wallet.init();
41
- }));
39
+ await Promise.all(this.wallets.map(wallet => wallet.init()));
42
40
  this.store.setState({ isReady: true });
43
41
  }
44
42
  catch (error) {
@@ -48,11 +46,10 @@ export class WalletManagerStore {
48
46
  }
49
47
  restore() {
50
48
  const oldState = this.localStorage.load();
51
- // 直接设置state,避免触发emit
52
49
  this.store.setState({
53
50
  chainWalletStates: oldState.chainWalletStates || [],
54
51
  currentWalletName: oldState.currentWalletName || '',
55
- currentChainName: oldState.currentChainName || '',
52
+ currentChainName: oldState.currentChainName || ''
56
53
  });
57
54
  // 重建索引映射
58
55
  this.store.buildIndexMap();
@@ -82,6 +79,22 @@ export class WalletManagerStore {
82
79
  // 合并过滤后的状态和新增的状态
83
80
  const finalChainWalletStates = [...filteredChainWalletStates, ...newChainWalletStates];
84
81
  this.store.setState({ chainWalletStates: finalChainWalletStates });
82
+ let isOldWalletNameExisted = false;
83
+ let isOldChainNameExisted = false;
84
+ for (const cws of finalChainWalletStates) {
85
+ if (cws.walletName === oldState.currentWalletName) {
86
+ isOldWalletNameExisted = true;
87
+ }
88
+ if (cws.chainName === oldState.currentChainName) {
89
+ isOldChainNameExisted = true;
90
+ }
91
+ }
92
+ // 直接设置state,避免触发emit
93
+ this.store.setState({
94
+ chainWalletStates: finalChainWalletStates,
95
+ currentWalletName: isOldWalletNameExisted ? oldState.currentWalletName : '',
96
+ currentChainName: isOldChainNameExisted ? oldState.currentChainName : '',
97
+ });
85
98
  this.store.buildIndexMap();
86
99
  }
87
100
  subscribe(callback) {
@@ -1,4 +1,4 @@
1
- import { BaseWallet, WalletState } from '@interchain-kit/core';
1
+ import { BaseWallet, getWalletByType, WalletState } from '@interchain-kit/core';
2
2
  import { ChainWalletStore } from './chain-wallet-store';
3
3
  export class WalletStore extends BaseWallet {
4
4
  wallet;
@@ -51,7 +51,7 @@ export class WalletStore extends BaseWallet {
51
51
  await this.wallet.init();
52
52
  }
53
53
  catch (error) {
54
- this.store.updateWalletState(this.wallet.info.name, { walletState: WalletState.NotExist, errorMessage: '' });
54
+ this.store.updateWalletState(this.wallet.info.name, { walletState: WalletState.NotExist, errorMessage: error.message });
55
55
  }
56
56
  }
57
57
  getChainWalletStore(chainName) {
@@ -96,4 +96,7 @@ export class WalletStore extends BaseWallet {
96
96
  }
97
97
  return this.getChainWalletStore(chain.chainName).getProvider();
98
98
  }
99
+ getWalletOfType(WalletClass) {
100
+ return getWalletByType(this.wallet, WalletClass);
101
+ }
99
102
  }
package/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './wallet-manager';
2
- export * from './types';
3
1
  export * from './store';
2
+ export * from './types';
3
+ export * from './wallet-manager';
package/index.js CHANGED
@@ -14,6 +14,6 @@ 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-manager"), exports);
18
- __exportStar(require("./types"), exports);
19
17
  __exportStar(require("./store"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ __exportStar(require("./wallet-manager"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interchain-kit/store",
3
- "version": "0.3.47",
3
+ "version": "0.3.49",
4
4
  "author": "Hyperweb <developers@hyperweb.io>",
5
5
  "description": "interchain-kit wallet connector store package",
6
6
  "main": "index.js",
@@ -31,5 +31,5 @@
31
31
  "watch:dev": "tsc -w -p tsconfig.esm.json & tsc -w"
32
32
  },
33
33
  "keywords": [],
34
- "gitHead": "4583b572672abd85a0918f39f534a5bf9312c261"
34
+ "gitHead": "a509c9b1ac6935b1ee58926e25ad1e66f86711c1"
35
35
  }
@@ -6,6 +6,7 @@ const core_2 = require("@interchain-kit/core");
6
6
  const cosmos_wallet_1 = require("./cosmos-wallet");
7
7
  const ethereum_wallet_1 = require("./ethereum-wallet");
8
8
  const multi_chain_wallet_1 = require("./multi-chain-wallet");
9
+ const solana_wallet_1 = require("./solana-wallet");
9
10
  // import { createWCWallet } from './wc-wallet';
10
11
  const createProxiedWallet = (wallet, store) => {
11
12
  // WalletConnect wallets are now handled by the generic AOP system
@@ -16,6 +17,9 @@ const createProxiedWallet = (wallet, store) => {
16
17
  if ((0, core_1.isInstanceOf)(wallet, core_2.EthereumWallet)) {
17
18
  return (0, ethereum_wallet_1.createEthereumWallet)(wallet, store);
18
19
  }
20
+ if ((0, core_1.isInstanceOf)(wallet, core_1.SolanaWallet)) {
21
+ return (0, solana_wallet_1.createSolanaWallet)(wallet, store);
22
+ }
19
23
  if ((0, core_1.isInstanceOf)(wallet, core_2.MultiChainWallet)) {
20
24
  Array.from(wallet.networkWalletMap.keys()).forEach(chainType => {
21
25
  const chainWallet = wallet.networkWalletMap.get(chainType);
@@ -25,6 +29,9 @@ const createProxiedWallet = (wallet, store) => {
25
29
  if ((0, core_1.isInstanceOf)(chainWallet, core_2.EthereumWallet)) {
26
30
  wallet.setNetworkWallet(chainType, (0, ethereum_wallet_1.createEthereumWallet)(chainWallet, store));
27
31
  }
32
+ if ((0, core_1.isInstanceOf)(chainWallet, core_1.SolanaWallet)) {
33
+ wallet.setNetworkWallet(chainType, (0, solana_wallet_1.createSolanaWallet)(chainWallet, store));
34
+ }
28
35
  });
29
36
  return (0, multi_chain_wallet_1.createMultiChainWallet)(wallet, store);
30
37
  }
@@ -0,0 +1,3 @@
1
+ import { SolanaWallet } from '@interchain-kit/core';
2
+ import { InterchainStore } from '../store';
3
+ export declare const createSolanaWallet: (target: SolanaWallet, store: InterchainStore) => import("../utils").AOPProxyType<SolanaWallet>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSolanaWallet = void 0;
4
+ const utils_1 = require("../utils");
5
+ const createSolanaWallet = (target, store) => {
6
+ return (0, utils_1.createAOPProxy)({
7
+ target,
8
+ advice: {
9
+ signTransaction: {
10
+ onError(methodName, target, error, transaction) {
11
+ store.updateChainWalletState(target.info.name, 'solana', { errorMessage: error.message });
12
+ },
13
+ },
14
+ }
15
+ });
16
+ };
17
+ exports.createSolanaWallet = createSolanaWallet;
package/store/index.d.ts CHANGED
@@ -17,5 +17,5 @@ export declare class InterchainStore {
17
17
  getChainWalletState(walletName: string, chainName: string): ChainWalletState | undefined;
18
18
  buildIndexMap(): void;
19
19
  updateWalletState(walletName: string, state: Partial<ChainWalletState>): void;
20
- isChainWalletStateExisted(walletName: string, chainName: string): number;
20
+ isChainWalletStateExisted(walletName: string, chainName: string): boolean;
21
21
  }
package/store/index.js CHANGED
@@ -123,7 +123,7 @@ class InterchainStore {
123
123
  this.setState({ chainWalletStates: newChainWalletStates });
124
124
  }
125
125
  isChainWalletStateExisted(walletName, chainName) {
126
- return this.chainWalletIndexMap.get(`${walletName}-${chainName}`);
126
+ return this.chainWalletIndexMap.get(`${walletName}-${chainName}`) !== undefined;
127
127
  }
128
128
  }
129
129
  exports.InterchainStore = InterchainStore;
@@ -1,4 +1,4 @@
1
- import { InterchainStoreType } from "../types";
1
+ import { InterchainStoreType } from '../types';
2
2
  export declare class LocalStorage {
3
3
  save(value: Partial<InterchainStoreType>): void;
4
4
  load(): Partial<InterchainStoreType>;
@@ -14,6 +14,7 @@ class ChainWalletStore extends core_1.BaseWallet {
14
14
  this.chain = chain;
15
15
  this.store = store;
16
16
  this.walletManager = walletManager;
17
+ this.info = this.wallet.info;
17
18
  }
18
19
  get walletState() {
19
20
  return this.store.getChainWalletState(this.chain.chainName, this.wallet.info.name)?.walletState || core_1.WalletState.NotExist;
@@ -38,7 +39,7 @@ class ChainWalletStore extends core_1.BaseWallet {
38
39
  });
39
40
  }
40
41
  try {
41
- this.store.updateChainWalletState(this.wallet.info.name, this.chain.chainName, { walletState: core_1.WalletState.Connecting });
42
+ this.store.updateChainWalletState(this.wallet.info.name, this.chain.chainName, { walletState: core_1.WalletState.Connecting, errorMessage: '' });
42
43
  await this.wallet.connect(this.chain.chainId);
43
44
  const account = await this.getAccount();
44
45
  this.store.updateChainWalletState(this.wallet.info.name, this.chain.chainName, { walletState: core_1.WalletState.Connected, account });
@@ -64,7 +65,6 @@ class ChainWalletStore extends core_1.BaseWallet {
64
65
  async refreshAccount() {
65
66
  try {
66
67
  const account = await this.wallet.getAccount(this.chain.chainId);
67
- console.log(this.wallet);
68
68
  this.store.updateChainWalletState(this.wallet.info.name, this.chain.chainName, { account });
69
69
  }
70
70
  catch (error) {
@@ -1,3 +1,3 @@
1
+ export * from './chain-wallet-store';
1
2
  export * from './wallet-manager-store';
2
3
  export * from './wallet-store';
3
- export * from './chain-wallet-store';
@@ -14,6 +14,6 @@ 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("./chain-wallet-store"), exports);
17
18
  __exportStar(require("./wallet-manager-store"), exports);
18
19
  __exportStar(require("./wallet-store"), exports);
19
- __exportStar(require("./chain-wallet-store"), exports);
@@ -39,9 +39,7 @@ class WalletManagerStore {
39
39
  currentChainName: state.currentChainName,
40
40
  });
41
41
  });
42
- await Promise.all(this.wallets.map(wallet => {
43
- return wallet.init();
44
- }));
42
+ await Promise.all(this.wallets.map(wallet => wallet.init()));
45
43
  this.store.setState({ isReady: true });
46
44
  }
47
45
  catch (error) {
@@ -51,11 +49,10 @@ class WalletManagerStore {
51
49
  }
52
50
  restore() {
53
51
  const oldState = this.localStorage.load();
54
- // 直接设置state,避免触发emit
55
52
  this.store.setState({
56
53
  chainWalletStates: oldState.chainWalletStates || [],
57
54
  currentWalletName: oldState.currentWalletName || '',
58
- currentChainName: oldState.currentChainName || '',
55
+ currentChainName: oldState.currentChainName || ''
59
56
  });
60
57
  // 重建索引映射
61
58
  this.store.buildIndexMap();
@@ -85,6 +82,22 @@ class WalletManagerStore {
85
82
  // 合并过滤后的状态和新增的状态
86
83
  const finalChainWalletStates = [...filteredChainWalletStates, ...newChainWalletStates];
87
84
  this.store.setState({ chainWalletStates: finalChainWalletStates });
85
+ let isOldWalletNameExisted = false;
86
+ let isOldChainNameExisted = false;
87
+ for (const cws of finalChainWalletStates) {
88
+ if (cws.walletName === oldState.currentWalletName) {
89
+ isOldWalletNameExisted = true;
90
+ }
91
+ if (cws.chainName === oldState.currentChainName) {
92
+ isOldChainNameExisted = true;
93
+ }
94
+ }
95
+ // 直接设置state,避免触发emit
96
+ this.store.setState({
97
+ chainWalletStates: finalChainWalletStates,
98
+ currentWalletName: isOldWalletNameExisted ? oldState.currentWalletName : '',
99
+ currentChainName: isOldChainNameExisted ? oldState.currentChainName : '',
100
+ });
88
101
  this.store.buildIndexMap();
89
102
  }
90
103
  subscribe(callback) {
@@ -18,4 +18,5 @@ export declare class WalletStore extends BaseWallet {
18
18
  getAccount(chainId: Chain['chainId']): Promise<WalletAccount>;
19
19
  addSuggestChain(chainId: Chain['chainId']): Promise<void>;
20
20
  getProvider(chainId: Chain['chainId']): Promise<any>;
21
+ getWalletOfType<T>(WalletClass: new (...args: any[]) => T): T;
21
22
  }
@@ -54,7 +54,7 @@ class WalletStore extends core_1.BaseWallet {
54
54
  await this.wallet.init();
55
55
  }
56
56
  catch (error) {
57
- this.store.updateWalletState(this.wallet.info.name, { walletState: core_1.WalletState.NotExist, errorMessage: '' });
57
+ this.store.updateWalletState(this.wallet.info.name, { walletState: core_1.WalletState.NotExist, errorMessage: error.message });
58
58
  }
59
59
  }
60
60
  getChainWalletStore(chainName) {
@@ -99,5 +99,8 @@ class WalletStore extends core_1.BaseWallet {
99
99
  }
100
100
  return this.getChainWalletStore(chain.chainName).getProvider();
101
101
  }
102
+ getWalletOfType(WalletClass) {
103
+ return (0, core_1.getWalletByType)(this.wallet, WalletClass);
104
+ }
102
105
  }
103
106
  exports.WalletStore = WalletStore;