@interchain-kit/store 0.3.48 → 0.3.50

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
+ };
@@ -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) {
@@ -201,7 +214,7 @@ export class WalletManagerStore {
201
214
  queryClient: await createCosmosQueryClient(rpcEndpoint),
202
215
  addressPrefix: chain.bech32Prefix,
203
216
  chainId: chain.chainId,
204
- ...defaultSignerOptions,
217
+ ...defaultSignerOptions.cosmosSignerConfig,
205
218
  };
206
219
  if (preferredSignType === 'direct') {
207
220
  return getSigner(offlineSigner, {
@@ -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) {
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.48",
3
+ "version": "0.3.50",
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": "763ba776cbfcbff8ef76a512ef5758c7187cb1f4"
34
+ "gitHead": "2b3813f0fb8f9c6beb7259845acbc0a0d52c72c0"
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;
@@ -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>;
@@ -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) {
@@ -204,7 +217,7 @@ class WalletManagerStore {
204
217
  queryClient: await (0, cosmos_1.createCosmosQueryClient)(rpcEndpoint),
205
218
  addressPrefix: chain.bech32Prefix,
206
219
  chainId: chain.chainId,
207
- ...defaultSignerOptions,
220
+ ...defaultSignerOptions.cosmosSignerConfig,
208
221
  };
209
222
  if (preferredSignType === 'direct') {
210
223
  return (0, interchainjs_1.getSigner)(offlineSigner, {
@@ -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) {