@openocean.finance/wallet 0.4.18 → 0.4.21
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,6 +1,5 @@
|
|
|
1
1
|
import { EnumChains, EnumWalletName, EnumWalletType } from "../types";
|
|
2
2
|
import BaseWallet from "./BaseWallet";
|
|
3
|
-
import WalletConnectProvider from "@walletconnect/web3-provider";
|
|
4
3
|
declare class WalletConnect extends BaseWallet {
|
|
5
4
|
name: EnumWalletName;
|
|
6
5
|
icon: any;
|
|
@@ -8,8 +7,6 @@ declare class WalletConnect extends BaseWallet {
|
|
|
8
7
|
type: EnumWalletType;
|
|
9
8
|
sdk: any;
|
|
10
9
|
infuraId?: string;
|
|
11
|
-
provider: WalletConnectProvider;
|
|
12
|
-
disconnect(): Promise<boolean>;
|
|
13
10
|
/**
|
|
14
11
|
* connect metamask and get wallet address
|
|
15
12
|
* @param chainId specific chainId,throw error when not match
|
|
@@ -102,43 +102,8 @@ 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
|
-
});
|
|
128
105
|
return _this;
|
|
129
106
|
}
|
|
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
|
-
};
|
|
142
107
|
/**
|
|
143
108
|
* connect metamask and get wallet address
|
|
144
109
|
* @param chainId specific chainId,throw error when not match
|
|
@@ -147,47 +112,57 @@ var WalletConnect = /** @class */ (function (_super) {
|
|
|
147
112
|
WalletConnect.prototype.requestConnect = function (chainId, config) {
|
|
148
113
|
if (chainId === void 0) { chainId = 1; }
|
|
149
114
|
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
-
var currentChainId, address;
|
|
115
|
+
var provider, currentChainId, address;
|
|
151
116
|
return __generator(this, function (_a) {
|
|
152
117
|
switch (_a.label) {
|
|
153
|
-
case 0:
|
|
154
|
-
|
|
155
|
-
|
|
118
|
+
case 0:
|
|
119
|
+
if (!this.infuraId) {
|
|
120
|
+
throw new Error("infuraId not set");
|
|
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()];
|
|
156
142
|
case 1:
|
|
157
|
-
// this.provider.infuraId = this.infuraId
|
|
158
143
|
_a.sent();
|
|
159
|
-
|
|
160
|
-
setTimeout(r, 200);
|
|
161
|
-
})];
|
|
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);
|
|
144
|
+
this.sdk = new web3_1.default(provider);
|
|
170
145
|
return [4 /*yield*/, this.sdk.eth.getChainId()];
|
|
171
|
-
case
|
|
146
|
+
case 2:
|
|
172
147
|
currentChainId = _a.sent();
|
|
173
|
-
if (!(chainId && currentChainId != chainId
|
|
174
|
-
if (!(config || !config.
|
|
175
|
-
return [4 /*yield*/,
|
|
176
|
-
case
|
|
148
|
+
if (!(chainId && currentChainId != chainId)) return [3 /*break*/, 6];
|
|
149
|
+
if (!(!config || !config.isSecond)) return [3 /*break*/, 6];
|
|
150
|
+
return [4 /*yield*/, provider.disconnect()];
|
|
151
|
+
case 3:
|
|
177
152
|
_a.sent();
|
|
178
153
|
return [4 /*yield*/, new Promise(function (r) {
|
|
179
|
-
setTimeout(r,
|
|
154
|
+
setTimeout(r, 500);
|
|
180
155
|
})];
|
|
181
|
-
case
|
|
156
|
+
case 4:
|
|
182
157
|
_a.sent();
|
|
183
|
-
return [4 /*yield*/, this.requestConnect(chainId, __assign({
|
|
184
|
-
case
|
|
185
|
-
case
|
|
158
|
+
return [4 /*yield*/, this.requestConnect(chainId, __assign({ isSecond: true }, config))];
|
|
159
|
+
case 5: return [2 /*return*/, _a.sent()];
|
|
160
|
+
case 6:
|
|
186
161
|
if (chainId && currentChainId != chainId) {
|
|
187
162
|
throw new Error(types_1.EnumErrors.ChainIdNotMath);
|
|
188
163
|
}
|
|
189
164
|
return [4 /*yield*/, this.sdk.eth.getAccounts()];
|
|
190
|
-
case
|
|
165
|
+
case 7:
|
|
191
166
|
address = (_a.sent())[0];
|
|
192
167
|
this.address = address;
|
|
193
168
|
this.chainId = currentChainId;
|