@interchain-kit/react 0.3.39 → 0.3.40
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/hooks/useChain.js +2 -2
- package/esm/modal/modal.js +1 -0
- package/esm/store/stateful-wallet.js +9 -2
- package/esm/utils/isSameConstructor.js +17 -0
- package/hooks/useChain.js +1 -1
- package/modal/modal.d.ts +1 -0
- package/modal/modal.js +1 -0
- package/package.json +4 -3
- package/store/stateful-wallet.js +9 -2
- package/utils/isSameConstructor.d.ts +7 -0
- package/utils/isSameConstructor.js +20 -0
package/esm/hooks/useChain.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useWalletManager } from './useWalletManager';
|
|
2
|
-
import { ChainNameNotExist } from '@interchain-kit/core';
|
|
2
|
+
import { ChainNameNotExist, WalletState } from '@interchain-kit/core';
|
|
3
3
|
import { useSigningClient } from './useSigningClient';
|
|
4
4
|
import { useWalletModal } from './useWalletModal';
|
|
5
5
|
export const useChain = (chainName) => {
|
|
@@ -26,7 +26,7 @@ export const useChain = (chainName) => {
|
|
|
26
26
|
},
|
|
27
27
|
closeView: close,
|
|
28
28
|
getRpcEndpoint: () => getRpcEndpoint(currentWalletName, chainName),
|
|
29
|
-
status: chainWalletStateToShow?.walletState,
|
|
29
|
+
status: chainWalletStateToShow?.walletState || WalletState.Disconnected,
|
|
30
30
|
username: chainWalletStateToShow?.account?.username,
|
|
31
31
|
message: chainWalletStateToShow?.errorMessage,
|
|
32
32
|
// new api
|
package/esm/modal/modal.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import "@interchain-ui/react/styles";
|
|
2
3
|
import { ConnectedContent, ConnectedHeader, ConnectingContent, ConnectingHeader, ErrorContent, ErrorHeader, NotExistContent, NotExistHeader, QRCodeContent, QRCodeHeader, RejectContent, RejectHeader, WalletListContent, WalletListHeader, } from "./views";
|
|
3
4
|
import { useMemo, useState } from "react";
|
|
4
5
|
import { WalletState } from "@interchain-kit/core";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseWallet, clientNotExistError, CosmosWallet, EthereumWallet, MultiChainWallet, WalletState, WCWallet } from "@interchain-kit/core";
|
|
2
|
+
import { isSameConstructor } from "../utils/isSameConstructor";
|
|
2
3
|
export class StatefulWallet extends BaseWallet {
|
|
3
4
|
originalWallet;
|
|
4
5
|
walletName;
|
|
@@ -46,6 +47,12 @@ export class StatefulWallet extends BaseWallet {
|
|
|
46
47
|
return errors.length > 0 ? errors[0] : '';
|
|
47
48
|
}
|
|
48
49
|
async init() {
|
|
50
|
+
this.originalWallet.events.on('accountChanged', async () => {
|
|
51
|
+
const chains = Array.from(this.originalWallet.chainMap.values());
|
|
52
|
+
for (const chain of chains) {
|
|
53
|
+
await this.getAccount(chain.chainId);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
49
56
|
try {
|
|
50
57
|
await this.originalWallet.init();
|
|
51
58
|
this.store.chains.forEach(chain => {
|
|
@@ -147,13 +154,13 @@ export class StatefulWallet extends BaseWallet {
|
|
|
147
154
|
return this.originalWallet;
|
|
148
155
|
}
|
|
149
156
|
if (this.originalWallet instanceof MultiChainWallet) {
|
|
150
|
-
if (WalletClass
|
|
157
|
+
if (isSameConstructor(WalletClass, CosmosWallet)) {
|
|
151
158
|
const cosmosWallet = this.originalWallet.getWalletByChainType('cosmos');
|
|
152
159
|
if (cosmosWallet) {
|
|
153
160
|
return cosmosWallet;
|
|
154
161
|
}
|
|
155
162
|
}
|
|
156
|
-
if (WalletClass
|
|
163
|
+
if (isSameConstructor(WalletClass, EthereumWallet)) {
|
|
157
164
|
const ethereumWallet = this.originalWallet.getWalletByChainType('eip155');
|
|
158
165
|
if (ethereumWallet) {
|
|
159
166
|
return ethereumWallet;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given class (ctor) is the same as or extends the target class (targetCtor).
|
|
3
|
+
* @param ctor The class to test.
|
|
4
|
+
* @param targetCtor The target class to match against.
|
|
5
|
+
* @returns True if ctor is the same as or extends targetCtor, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export function isSameConstructor(ctor, targetCtor) {
|
|
8
|
+
if (ctor === targetCtor)
|
|
9
|
+
return true;
|
|
10
|
+
let proto = Object.getPrototypeOf(ctor);
|
|
11
|
+
while (proto && proto !== Function.prototype) {
|
|
12
|
+
if (proto === targetCtor)
|
|
13
|
+
return true;
|
|
14
|
+
proto = Object.getPrototypeOf(proto);
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
package/hooks/useChain.js
CHANGED
|
@@ -29,7 +29,7 @@ const useChain = (chainName) => {
|
|
|
29
29
|
},
|
|
30
30
|
closeView: close,
|
|
31
31
|
getRpcEndpoint: () => getRpcEndpoint(currentWalletName, chainName),
|
|
32
|
-
status: chainWalletStateToShow?.walletState,
|
|
32
|
+
status: chainWalletStateToShow?.walletState || core_1.WalletState.Disconnected,
|
|
33
33
|
username: chainWalletStateToShow?.account?.username,
|
|
34
34
|
message: chainWalletStateToShow?.errorMessage,
|
|
35
35
|
// new api
|
package/modal/modal.d.ts
CHANGED
package/modal/modal.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ModalRenderer = exports.WalletModalElement = exports.InterchainWalletModal = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
require("@interchain-ui/react/styles");
|
|
5
6
|
const views_1 = require("./views");
|
|
6
7
|
const react_1 = require("react");
|
|
7
8
|
const core_1 = require("@interchain-kit/core");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interchain-kit/react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.40",
|
|
4
4
|
"author": "Hyperweb <developers@hyperweb.io>",
|
|
5
5
|
"description": "interchain-kit wallet connector react package",
|
|
6
6
|
"main": "index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"keywords": [],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@chain-registry/types": "^2.0.1",
|
|
37
|
-
"@interchain-kit/core": "0.3.
|
|
37
|
+
"@interchain-kit/core": "0.3.40",
|
|
38
38
|
"@interchain-ui/react": "1.26.1",
|
|
39
39
|
"@interchainjs/cosmos": "1.11.11",
|
|
40
40
|
"@interchainjs/cosmos-types": "1.11.11",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"@react-icons/all-files": "^4.1.0",
|
|
43
43
|
"@walletconnect/types": "^2.17.3",
|
|
44
44
|
"interchainjs": "1.11.11",
|
|
45
|
+
"jest-transform-stub": "^2.0.0",
|
|
45
46
|
"zustand": "^5.0.3"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
@@ -64,5 +65,5 @@
|
|
|
64
65
|
"react": "^19.0.0",
|
|
65
66
|
"react-dom": "^19.0.0"
|
|
66
67
|
},
|
|
67
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "f81351e48dc111b25313d640da2752e87ebf8b20"
|
|
68
69
|
}
|
package/store/stateful-wallet.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StatefulWallet = void 0;
|
|
4
4
|
const core_1 = require("@interchain-kit/core");
|
|
5
|
+
const isSameConstructor_1 = require("../utils/isSameConstructor");
|
|
5
6
|
class StatefulWallet extends core_1.BaseWallet {
|
|
6
7
|
originalWallet;
|
|
7
8
|
walletName;
|
|
@@ -49,6 +50,12 @@ class StatefulWallet extends core_1.BaseWallet {
|
|
|
49
50
|
return errors.length > 0 ? errors[0] : '';
|
|
50
51
|
}
|
|
51
52
|
async init() {
|
|
53
|
+
this.originalWallet.events.on('accountChanged', async () => {
|
|
54
|
+
const chains = Array.from(this.originalWallet.chainMap.values());
|
|
55
|
+
for (const chain of chains) {
|
|
56
|
+
await this.getAccount(chain.chainId);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
52
59
|
try {
|
|
53
60
|
await this.originalWallet.init();
|
|
54
61
|
this.store.chains.forEach(chain => {
|
|
@@ -150,13 +157,13 @@ class StatefulWallet extends core_1.BaseWallet {
|
|
|
150
157
|
return this.originalWallet;
|
|
151
158
|
}
|
|
152
159
|
if (this.originalWallet instanceof core_1.MultiChainWallet) {
|
|
153
|
-
if (WalletClass
|
|
160
|
+
if ((0, isSameConstructor_1.isSameConstructor)(WalletClass, core_1.CosmosWallet)) {
|
|
154
161
|
const cosmosWallet = this.originalWallet.getWalletByChainType('cosmos');
|
|
155
162
|
if (cosmosWallet) {
|
|
156
163
|
return cosmosWallet;
|
|
157
164
|
}
|
|
158
165
|
}
|
|
159
|
-
if (WalletClass
|
|
166
|
+
if ((0, isSameConstructor_1.isSameConstructor)(WalletClass, core_1.EthereumWallet)) {
|
|
160
167
|
const ethereumWallet = this.originalWallet.getWalletByChainType('eip155');
|
|
161
168
|
if (ethereumWallet) {
|
|
162
169
|
return ethereumWallet;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given class (ctor) is the same as or extends the target class (targetCtor).
|
|
3
|
+
* @param ctor The class to test.
|
|
4
|
+
* @param targetCtor The target class to match against.
|
|
5
|
+
* @returns True if ctor is the same as or extends targetCtor, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isSameConstructor(ctor: Function, targetCtor: Function): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSameConstructor = isSameConstructor;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the given class (ctor) is the same as or extends the target class (targetCtor).
|
|
6
|
+
* @param ctor The class to test.
|
|
7
|
+
* @param targetCtor The target class to match against.
|
|
8
|
+
* @returns True if ctor is the same as or extends targetCtor, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
function isSameConstructor(ctor, targetCtor) {
|
|
11
|
+
if (ctor === targetCtor)
|
|
12
|
+
return true;
|
|
13
|
+
let proto = Object.getPrototypeOf(ctor);
|
|
14
|
+
while (proto && proto !== Function.prototype) {
|
|
15
|
+
if (proto === targetCtor)
|
|
16
|
+
return true;
|
|
17
|
+
proto = Object.getPrototypeOf(proto);
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|