@injectivelabs/wallet-evm 1.16.28 → 1.16.30
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/dist/cjs/utils/index.d.ts +15 -0
- package/dist/cjs/utils/index.js +34 -1
- package/dist/esm/utils/index.d.ts +15 -0
- package/dist/esm/utils/index.js +32 -0
- package/package.json +8 -8
|
@@ -3,3 +3,18 @@ import type { EvmChainId } from '@injectivelabs/ts-types';
|
|
|
3
3
|
import type { BrowserEip1993Provider } from '@injectivelabs/wallet-base';
|
|
4
4
|
export declare const getEvmProvider: (wallet: Wallet) => Promise<BrowserEip1993Provider>;
|
|
5
5
|
export declare const updateEvmNetwork: (wallet: Wallet, chainId: EvmChainId) => Promise<unknown>;
|
|
6
|
+
export declare const addEvmNetworkToWallet: ({ wallet, chainId, params, }: {
|
|
7
|
+
wallet: Wallet;
|
|
8
|
+
chainId: EvmChainId;
|
|
9
|
+
params: {
|
|
10
|
+
rpcUrls: string[];
|
|
11
|
+
chainName: string;
|
|
12
|
+
blockExplorerUrls: string[];
|
|
13
|
+
chainId: string;
|
|
14
|
+
nativeCurrency: {
|
|
15
|
+
name: string;
|
|
16
|
+
symbol: string;
|
|
17
|
+
decimals: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}) => Promise<void>;
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateEvmNetwork = exports.getEvmProvider = void 0;
|
|
3
|
+
exports.addEvmNetworkToWallet = exports.updateEvmNetwork = exports.getEvmProvider = void 0;
|
|
4
4
|
const utils_1 = require("@injectivelabs/utils");
|
|
5
5
|
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
6
6
|
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
@@ -71,3 +71,36 @@ const updateEvmNetwork = async (wallet, chainId) => {
|
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
73
|
exports.updateEvmNetwork = updateEvmNetwork;
|
|
74
|
+
const addEvmNetworkToWallet = async ({ wallet, chainId, params, }) => {
|
|
75
|
+
if (!(0, wallet_base_1.isEvmBrowserWallet)(wallet)) {
|
|
76
|
+
throw new exceptions_1.WalletException(new Error(`Evm Wallet for ${(0, utils_1.capitalize)(wallet)} is not supported.`));
|
|
77
|
+
}
|
|
78
|
+
const provider = (await (0, exports.getEvmProvider)(wallet));
|
|
79
|
+
if (!provider) {
|
|
80
|
+
throw new exceptions_1.WalletException(new Error(`Please install ${(0, utils_1.capitalize)(wallet)} Extension`));
|
|
81
|
+
}
|
|
82
|
+
const chainIdToHex = chainId.toString(16);
|
|
83
|
+
try {
|
|
84
|
+
await Promise.race([
|
|
85
|
+
provider.request({
|
|
86
|
+
method: 'wallet_switchEthereumChain',
|
|
87
|
+
params: [{ chainId: `0x${chainIdToHex}` }],
|
|
88
|
+
}),
|
|
89
|
+
new Promise((resolve) => provider.on('chainChanged', ({ chain }) => {
|
|
90
|
+
if (chain?.id === chainIdToHex) {
|
|
91
|
+
resolve();
|
|
92
|
+
}
|
|
93
|
+
})),
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (error.code === 4902) {
|
|
98
|
+
await provider?.request({
|
|
99
|
+
method: 'wallet_addEthereumChain',
|
|
100
|
+
params: [params],
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
throw new exceptions_1.WalletException(new Error(`Something went wrong while adding ${(0, utils_1.capitalize)(wallet)} network`));
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
exports.addEvmNetworkToWallet = addEvmNetworkToWallet;
|
|
@@ -3,3 +3,18 @@ import type { EvmChainId } from '@injectivelabs/ts-types';
|
|
|
3
3
|
import type { BrowserEip1993Provider } from '@injectivelabs/wallet-base';
|
|
4
4
|
export declare const getEvmProvider: (wallet: Wallet) => Promise<BrowserEip1993Provider>;
|
|
5
5
|
export declare const updateEvmNetwork: (wallet: Wallet, chainId: EvmChainId) => Promise<unknown>;
|
|
6
|
+
export declare const addEvmNetworkToWallet: ({ wallet, chainId, params, }: {
|
|
7
|
+
wallet: Wallet;
|
|
8
|
+
chainId: EvmChainId;
|
|
9
|
+
params: {
|
|
10
|
+
rpcUrls: string[];
|
|
11
|
+
chainName: string;
|
|
12
|
+
blockExplorerUrls: string[];
|
|
13
|
+
chainId: string;
|
|
14
|
+
nativeCurrency: {
|
|
15
|
+
name: string;
|
|
16
|
+
symbol: string;
|
|
17
|
+
decimals: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}) => Promise<void>;
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -66,3 +66,35 @@ export const updateEvmNetwork = async (wallet, chainId) => {
|
|
|
66
66
|
throw new WalletException(new Error(`Please update your ${capitalize(wallet)} network`));
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
|
+
export const addEvmNetworkToWallet = async ({ wallet, chainId, params, }) => {
|
|
70
|
+
if (!isEvmBrowserWallet(wallet)) {
|
|
71
|
+
throw new WalletException(new Error(`Evm Wallet for ${capitalize(wallet)} is not supported.`));
|
|
72
|
+
}
|
|
73
|
+
const provider = (await getEvmProvider(wallet));
|
|
74
|
+
if (!provider) {
|
|
75
|
+
throw new WalletException(new Error(`Please install ${capitalize(wallet)} Extension`));
|
|
76
|
+
}
|
|
77
|
+
const chainIdToHex = chainId.toString(16);
|
|
78
|
+
try {
|
|
79
|
+
await Promise.race([
|
|
80
|
+
provider.request({
|
|
81
|
+
method: 'wallet_switchEthereumChain',
|
|
82
|
+
params: [{ chainId: `0x${chainIdToHex}` }],
|
|
83
|
+
}),
|
|
84
|
+
new Promise((resolve) => provider.on('chainChanged', ({ chain }) => {
|
|
85
|
+
if (chain?.id === chainIdToHex) {
|
|
86
|
+
resolve();
|
|
87
|
+
}
|
|
88
|
+
})),
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (error.code === 4902) {
|
|
93
|
+
await provider?.request({
|
|
94
|
+
method: 'wallet_addEthereumChain',
|
|
95
|
+
params: [params],
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
throw new WalletException(new Error(`Something went wrong while adding ${capitalize(wallet)} network`));
|
|
99
|
+
}
|
|
100
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-evm",
|
|
3
3
|
"description": "EVM wallet strategies for use with @injectivelabs/wallet-core.",
|
|
4
|
-
"version": "1.16.
|
|
4
|
+
"version": "1.16.30",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": {
|
|
@@ -56,17 +56,17 @@
|
|
|
56
56
|
"start": "node dist/index.js"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@injectivelabs/exceptions": "1.16.
|
|
60
|
-
"@injectivelabs/networks": "1.16.
|
|
61
|
-
"@injectivelabs/sdk-ts": "1.16.
|
|
62
|
-
"@injectivelabs/ts-types": "1.16.
|
|
63
|
-
"@injectivelabs/utils": "1.16.
|
|
64
|
-
"@injectivelabs/wallet-base": "1.16.
|
|
59
|
+
"@injectivelabs/exceptions": "1.16.30",
|
|
60
|
+
"@injectivelabs/networks": "1.16.30",
|
|
61
|
+
"@injectivelabs/sdk-ts": "1.16.30",
|
|
62
|
+
"@injectivelabs/ts-types": "1.16.30",
|
|
63
|
+
"@injectivelabs/utils": "1.16.30",
|
|
64
|
+
"@injectivelabs/wallet-base": "1.16.30"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"shx": "^0.3.3"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "5fdc88e012498121c8a15bd9f4d0c4c78e03e929",
|
|
70
70
|
"typedoc": {
|
|
71
71
|
"entryPoint": "./src/index.ts",
|
|
72
72
|
"readmeFile": "./README.md",
|