@openocean.finance/wallet 0.4.14 → 0.4.17
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,43 @@ 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
|
+
infuraId: '2c7c4d86c2c746c89de722551b606119',
|
|
107
|
+
chainId: 1,
|
|
108
|
+
rpc: {
|
|
109
|
+
69: "https://kovan.optimism.io",
|
|
110
|
+
420: "https://goerli.optimism.io",
|
|
111
|
+
10: "https://rpc.ankr.com/optimism",
|
|
112
|
+
25: "https://evm.cronos.org",
|
|
113
|
+
56: "https://bsc-dataseed1.binance.org",
|
|
114
|
+
66: "https://exchainrpc.okex.org",
|
|
115
|
+
100: "https://rpc.xdaichain.com",
|
|
116
|
+
128: "https://http-mainnet.hecochain.com",
|
|
117
|
+
137: "https://rpc-mainnet.maticvigil.com",
|
|
118
|
+
250: "https://rpcapi.fantom.network",
|
|
119
|
+
288: "https://mainnet.boba.network",
|
|
120
|
+
1285: "https://rpc.moonriver.moonbeam.network",
|
|
121
|
+
42161: "https://arb1.arbitrum.io/rpc",
|
|
122
|
+
421611: "https://rinkeby.arbitrum.io/rpc",
|
|
123
|
+
43114: "https://api.avax.network/ext/bc/C/rpc",
|
|
124
|
+
1313161554: "https://mainnet.aurora.dev",
|
|
125
|
+
1666600000: "https://api.s0.t.hmny.io",
|
|
126
|
+
}
|
|
127
|
+
});
|
|
105
128
|
return _this;
|
|
106
129
|
}
|
|
130
|
+
WalletConnect.prototype.disconnect = function () {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
switch (_a.label) {
|
|
134
|
+
case 0: return [4 /*yield*/, this.provider.disconnect()];
|
|
135
|
+
case 1:
|
|
136
|
+
_a.sent();
|
|
137
|
+
return [2 /*return*/, true];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
|
107
142
|
/**
|
|
108
143
|
* connect metamask and get wallet address
|
|
109
144
|
* @param chainId specific chainId,throw error when not match
|
|
@@ -112,44 +147,47 @@ var WalletConnect = /** @class */ (function (_super) {
|
|
|
112
147
|
WalletConnect.prototype.requestConnect = function (chainId, config) {
|
|
113
148
|
if (chainId === void 0) { chainId = 1; }
|
|
114
149
|
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
-
var
|
|
150
|
+
var currentChainId, address;
|
|
116
151
|
return __generator(this, function (_a) {
|
|
117
152
|
switch (_a.label) {
|
|
118
|
-
case 0:
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
provider = new web3_provider_1.default(__assign({ infuraId: this.infuraId, chainId: chainId, rpc: {
|
|
123
|
-
69: "https://kovan.optimism.io",
|
|
124
|
-
420: "https://goerli.optimism.io",
|
|
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()];
|
|
153
|
+
case 0:
|
|
154
|
+
// this.provider.infuraId = this.infuraId
|
|
155
|
+
return [4 /*yield*/, this.provider.disconnect()];
|
|
142
156
|
case 1:
|
|
157
|
+
// this.provider.infuraId = this.infuraId
|
|
143
158
|
_a.sent();
|
|
144
|
-
|
|
145
|
-
|
|
159
|
+
return [4 /*yield*/, new Promise(function (r) {
|
|
160
|
+
setTimeout(r, 200);
|
|
161
|
+
})];
|
|
146
162
|
case 2:
|
|
163
|
+
_a.sent();
|
|
164
|
+
this.provider.chainId = chainId;
|
|
165
|
+
this.provider.updateRpcUrl(chainId);
|
|
166
|
+
return [4 /*yield*/, this.provider.enable()];
|
|
167
|
+
case 3:
|
|
168
|
+
_a.sent();
|
|
169
|
+
this.sdk = new web3_1.default(this.provider);
|
|
170
|
+
return [4 /*yield*/, this.sdk.eth.getChainId()];
|
|
171
|
+
case 4:
|
|
147
172
|
currentChainId = _a.sent();
|
|
173
|
+
if (!(chainId && currentChainId != chainId && (this.sdk.currentProvider.walletMeta && this.sdk.currentProvider.walletMeta.name != "MetaMask"))) return [3 /*break*/, 8];
|
|
174
|
+
if (!(config || !config.isTow)) return [3 /*break*/, 8];
|
|
175
|
+
return [4 /*yield*/, this.provider.disconnect()];
|
|
176
|
+
case 5:
|
|
177
|
+
_a.sent();
|
|
178
|
+
return [4 /*yield*/, new Promise(function (r) {
|
|
179
|
+
setTimeout(r, 1000);
|
|
180
|
+
})];
|
|
181
|
+
case 6:
|
|
182
|
+
_a.sent();
|
|
183
|
+
return [4 /*yield*/, this.requestConnect(chainId, __assign({ isTow: true }, config))];
|
|
184
|
+
case 7: return [2 /*return*/, _a.sent()];
|
|
185
|
+
case 8:
|
|
148
186
|
if (chainId && currentChainId != chainId) {
|
|
149
187
|
throw new Error(types_1.EnumErrors.ChainIdNotMath);
|
|
150
188
|
}
|
|
151
189
|
return [4 /*yield*/, this.sdk.eth.getAccounts()];
|
|
152
|
-
case
|
|
190
|
+
case 9:
|
|
153
191
|
address = (_a.sent())[0];
|
|
154
192
|
this.address = address;
|
|
155
193
|
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.17",
|
|
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
|
+
}
|