@openocean.finance/wallet 0.4.15 → 0.4.16
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,18 +1,20 @@
|
|
|
1
1
|
import { EnumChains, EnumWalletName, EnumWalletType } from "../types";
|
|
2
2
|
import BaseWallet from "./BaseWallet";
|
|
3
|
-
import
|
|
3
|
+
import WalletConnectProvider from "@walletconnect/web3-provider";
|
|
4
4
|
declare class WalletConnect extends BaseWallet {
|
|
5
5
|
name: EnumWalletName;
|
|
6
6
|
icon: any;
|
|
7
7
|
supportChains: EnumChains[];
|
|
8
8
|
type: EnumWalletType;
|
|
9
|
-
sdk:
|
|
9
|
+
sdk: any;
|
|
10
10
|
infuraId?: string;
|
|
11
|
+
provider: WalletConnectProvider;
|
|
12
|
+
disconnect(): Promise<boolean>;
|
|
11
13
|
/**
|
|
12
14
|
* connect metamask and get wallet address
|
|
13
15
|
* @param chainId specific chainId,throw error when not match
|
|
14
16
|
* @param config
|
|
15
17
|
*/
|
|
16
|
-
requestConnect(chainId?: number, config?: any): Promise<
|
|
18
|
+
requestConnect(chainId?: number, config?: any): Promise<any>;
|
|
17
19
|
}
|
|
18
20
|
export default WalletConnect;
|
|
@@ -102,8 +102,42 @@ var WalletConnect = /** @class */ (function (_super) {
|
|
|
102
102
|
];
|
|
103
103
|
_this.type = types_1.EnumWalletType.WalletConnect;
|
|
104
104
|
_this.sdk = null;
|
|
105
|
+
_this.provider = new web3_provider_1.default({
|
|
106
|
+
chainId: 1,
|
|
107
|
+
rpc: {
|
|
108
|
+
69: "https://kovan.optimism.io",
|
|
109
|
+
420: "https://goerli.optimism.io",
|
|
110
|
+
10: "https://rpc.ankr.com/optimism",
|
|
111
|
+
25: "https://evm.cronos.org",
|
|
112
|
+
56: "https://bsc-dataseed1.binance.org",
|
|
113
|
+
66: "https://exchainrpc.okex.org",
|
|
114
|
+
100: "https://rpc.xdaichain.com",
|
|
115
|
+
128: "https://http-mainnet.hecochain.com",
|
|
116
|
+
137: "https://rpc-mainnet.maticvigil.com",
|
|
117
|
+
250: "https://rpcapi.fantom.network",
|
|
118
|
+
288: "https://mainnet.boba.network",
|
|
119
|
+
1285: "https://rpc.moonriver.moonbeam.network",
|
|
120
|
+
42161: "https://arb1.arbitrum.io/rpc",
|
|
121
|
+
421611: "https://rinkeby.arbitrum.io/rpc",
|
|
122
|
+
43114: "https://api.avax.network/ext/bc/C/rpc",
|
|
123
|
+
1313161554: "https://mainnet.aurora.dev",
|
|
124
|
+
1666600000: "https://api.s0.t.hmny.io",
|
|
125
|
+
}
|
|
126
|
+
});
|
|
105
127
|
return _this;
|
|
106
128
|
}
|
|
129
|
+
WalletConnect.prototype.disconnect = function () {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
+
return __generator(this, function (_a) {
|
|
132
|
+
switch (_a.label) {
|
|
133
|
+
case 0: return [4 /*yield*/, this.provider.disconnect()];
|
|
134
|
+
case 1:
|
|
135
|
+
_a.sent();
|
|
136
|
+
return [2 /*return*/, true];
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
};
|
|
107
141
|
/**
|
|
108
142
|
* connect metamask and get wallet address
|
|
109
143
|
* @param chainId specific chainId,throw error when not match
|
|
@@ -112,44 +146,40 @@ var WalletConnect = /** @class */ (function (_super) {
|
|
|
112
146
|
WalletConnect.prototype.requestConnect = function (chainId, config) {
|
|
113
147
|
if (chainId === void 0) { chainId = 1; }
|
|
114
148
|
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
-
var
|
|
149
|
+
var currentChainId, address;
|
|
116
150
|
return __generator(this, function (_a) {
|
|
117
151
|
switch (_a.label) {
|
|
118
152
|
case 0:
|
|
119
153
|
if (!this.infuraId) {
|
|
120
154
|
throw new Error("infuraId not set");
|
|
121
155
|
}
|
|
122
|
-
provider =
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
10: "https://rpc.ankr.com/optimism",
|
|
126
|
-
25: "https://evm.cronos.org",
|
|
127
|
-
56: "https://bsc-dataseed1.binance.org",
|
|
128
|
-
66: "https://exchainrpc.okex.org",
|
|
129
|
-
100: "https://rpc.xdaichain.com",
|
|
130
|
-
128: "https://http-mainnet.hecochain.com",
|
|
131
|
-
137: "https://rpc-mainnet.maticvigil.com",
|
|
132
|
-
250: "https://rpcapi.fantom.network",
|
|
133
|
-
288: "https://mainnet.boba.network",
|
|
134
|
-
1285: "https://rpc.moonriver.moonbeam.network",
|
|
135
|
-
42161: "https://arb1.arbitrum.io/rpc",
|
|
136
|
-
421611: "https://rinkeby.arbitrum.io/rpc",
|
|
137
|
-
43114: "https://api.avax.network/ext/bc/C/rpc",
|
|
138
|
-
1313161554: "https://mainnet.aurora.dev",
|
|
139
|
-
1666600000: "https://api.s0.t.hmny.io",
|
|
140
|
-
} }, config));
|
|
141
|
-
return [4 /*yield*/, provider.enable()];
|
|
156
|
+
this.provider.infuraId = this.infuraId;
|
|
157
|
+
this.provider.updateRpcUrl(chainId);
|
|
158
|
+
return [4 /*yield*/, this.provider.enable()];
|
|
142
159
|
case 1:
|
|
143
160
|
_a.sent();
|
|
144
|
-
this.sdk = new web3_1.default(provider);
|
|
161
|
+
this.sdk = new web3_1.default(this.provider);
|
|
145
162
|
return [4 /*yield*/, this.sdk.eth.getChainId()];
|
|
146
163
|
case 2:
|
|
147
164
|
currentChainId = _a.sent();
|
|
165
|
+
if (!(chainId && currentChainId != chainId && (this.sdk.currentProvider.walletMeta && this.sdk.currentProvider.walletMeta.name != "MetaMask"))) return [3 /*break*/, 6];
|
|
166
|
+
if (!(config || !config.isTow)) return [3 /*break*/, 6];
|
|
167
|
+
return [4 /*yield*/, this.provider.disconnect()];
|
|
168
|
+
case 3:
|
|
169
|
+
_a.sent();
|
|
170
|
+
return [4 /*yield*/, new Promise(function (r) {
|
|
171
|
+
setTimeout(r, 1000);
|
|
172
|
+
})];
|
|
173
|
+
case 4:
|
|
174
|
+
_a.sent();
|
|
175
|
+
return [4 /*yield*/, this.requestConnect(chainId, __assign({ isTow: true }, config))];
|
|
176
|
+
case 5: return [2 /*return*/, _a.sent()];
|
|
177
|
+
case 6:
|
|
148
178
|
if (chainId && currentChainId != chainId) {
|
|
149
179
|
throw new Error(types_1.EnumErrors.ChainIdNotMath);
|
|
150
180
|
}
|
|
151
181
|
return [4 /*yield*/, this.sdk.eth.getAccounts()];
|
|
152
|
-
case
|
|
182
|
+
case 7:
|
|
153
183
|
address = (_a.sent())[0];
|
|
154
184
|
this.address = address;
|
|
155
185
|
this.chainId = currentChainId;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openocean.finance/wallet",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.16",
|
|
4
4
|
"description": "A multi-chain wallets manager",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
"@solana/web3.js": "1.31.0",
|
|
48
48
|
"@terra-money/terra.js": "3.0.8",
|
|
49
49
|
"@walletconnect/web3-provider": "^1.7.8",
|
|
50
|
-
"web3": "^1.7.4",
|
|
51
50
|
"buffer": "^6.0.3",
|
|
52
51
|
"fs": "^0.0.1-security",
|
|
52
|
+
"near-api-js": "^0.44.2",
|
|
53
53
|
"path-browserify": "^1.0.1",
|
|
54
|
-
"
|
|
54
|
+
"web3": "^1.7.4"
|
|
55
55
|
},
|
|
56
56
|
"eslintConfig": {
|
|
57
57
|
"root": true,
|
|
@@ -71,4 +71,4 @@
|
|
|
71
71
|
"no-unused-vars": "off"
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
}
|
|
74
|
+
}
|