@openocean.finance/wallet 0.4.29 → 0.4.31
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/lib/Wallets/BloctoWallet.d.ts +16 -1
- package/lib/Wallets/BloctoWallet.js +100 -2
- package/lib/Wallets/BscWallet.js +0 -5
- package/lib/Wallets/ImTokenWallet.js +3 -3
- package/lib/Wallets/OntoMobile.js +2 -2
- package/lib/Wallets/SafePalWallet.js +3 -3
- package/lib/Wallets/SolflareWallet.js +3 -3
- package/lib/Wallets/TokenPocket.js +2 -2
- package/lib/Wallets/TronLink.d.ts +1 -1
- package/lib/Wallets/TronLink.js +28 -13
- package/lib/Wallets/TrustWallet.d.ts +2 -4
- package/lib/Wallets/TrustWallet.js +9 -46
- package/lib/index.d.ts +1 -3
- package/lib/index.js +1 -4
- package/lib/types.d.ts +6 -1
- package/lib/types.js +6 -1
- package/package.json +1 -1
- package/lib/WalletManager.d.ts +0 -20
- package/lib/WalletManager.js +0 -117
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
import { EnumChains, EnumWalletName, EnumWalletType } from "../types";
|
|
2
2
|
import BaseWallet from "./BaseWallet";
|
|
3
|
+
import Web3 from "web3";
|
|
3
4
|
declare class BloctoWallet extends BaseWallet {
|
|
4
5
|
name: EnumWalletName;
|
|
5
6
|
icon: any;
|
|
6
7
|
supportChains: EnumChains[];
|
|
7
8
|
type: EnumWalletType;
|
|
8
|
-
sdk:
|
|
9
|
+
sdk: Web3 | null;
|
|
9
10
|
/**
|
|
10
11
|
* connect metamask and get wallet address
|
|
11
12
|
* @param chainId specific chainId,throw error when not match
|
|
12
13
|
*/
|
|
13
14
|
requestConnect(chainId?: number): Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* connect metamask and get wallet address
|
|
17
|
+
*/
|
|
18
|
+
requestTronConnect(): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* connect metamask and get wallet address
|
|
21
|
+
* @param chainId specific chainId,throw error when not match
|
|
22
|
+
*/
|
|
23
|
+
requestSolanaConnect(chainId?: number): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* connect metamask and get wallet address
|
|
26
|
+
* @param chainId specific chainId,throw error when not match
|
|
27
|
+
*/
|
|
28
|
+
requestFlowConnect(chainId?: number): Promise<string>;
|
|
14
29
|
}
|
|
15
30
|
export default BloctoWallet;
|
|
@@ -87,6 +87,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
87
87
|
var blocto_svg_1 = __importDefault(require("../assets/blocto.svg"));
|
|
88
88
|
var types_1 = require("../types");
|
|
89
89
|
var BaseWallet_1 = __importDefault(require("./BaseWallet"));
|
|
90
|
+
var web3_1 = __importDefault(require("web3"));
|
|
90
91
|
var fcl = __importStar(require("@onflow/fcl"));
|
|
91
92
|
var BloctoWallet = /** @class */ (function (_super) {
|
|
92
93
|
__extends(BloctoWallet, _super);
|
|
@@ -94,8 +95,15 @@ var BloctoWallet = /** @class */ (function (_super) {
|
|
|
94
95
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
95
96
|
_this.name = types_1.EnumWalletName.BloctoWallet;
|
|
96
97
|
_this.icon = blocto_svg_1.default;
|
|
97
|
-
_this.supportChains = [
|
|
98
|
-
|
|
98
|
+
_this.supportChains = [
|
|
99
|
+
types_1.EnumChains.ETH,
|
|
100
|
+
types_1.EnumChains.BSC,
|
|
101
|
+
types_1.EnumChains.Polygon,
|
|
102
|
+
types_1.EnumChains.Avalanche,
|
|
103
|
+
// EnumChains.TRON,
|
|
104
|
+
types_1.EnumChains.Solana
|
|
105
|
+
];
|
|
106
|
+
_this.type = types_1.EnumWalletType.Mobile;
|
|
99
107
|
_this.sdk = null;
|
|
100
108
|
return _this;
|
|
101
109
|
}
|
|
@@ -104,6 +112,96 @@ var BloctoWallet = /** @class */ (function (_super) {
|
|
|
104
112
|
* @param chainId specific chainId,throw error when not match
|
|
105
113
|
*/
|
|
106
114
|
BloctoWallet.prototype.requestConnect = function (chainId) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
+
var address, currentChainId;
|
|
117
|
+
return __generator(this, function (_a) {
|
|
118
|
+
switch (_a.label) {
|
|
119
|
+
case 0:
|
|
120
|
+
if (!(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
|
|
121
|
+
throw new Error(types_1.EnumErrors.NoBlocto);
|
|
122
|
+
}
|
|
123
|
+
if (!((window.ethereum && window.ethereum.isBlocto) || (web3_1.default && web3_1.default.givenProvider))) {
|
|
124
|
+
throw new Error(types_1.EnumErrors.NoBlocto);
|
|
125
|
+
}
|
|
126
|
+
this.sdk = new web3_1.default(window.ethereum || web3_1.default.givenProvider);
|
|
127
|
+
return [4 /*yield*/, this.sdk.eth.requestAccounts()];
|
|
128
|
+
case 1:
|
|
129
|
+
address = (_a.sent())[0];
|
|
130
|
+
return [4 /*yield*/, this.sdk.eth.getChainId()];
|
|
131
|
+
case 2:
|
|
132
|
+
currentChainId = _a.sent();
|
|
133
|
+
if (chainId && currentChainId !== chainId) {
|
|
134
|
+
throw new Error(types_1.EnumErrors.ChainIdNotMath);
|
|
135
|
+
}
|
|
136
|
+
this.address = address;
|
|
137
|
+
this.chainId = currentChainId;
|
|
138
|
+
return [2 /*return*/, address];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* connect metamask and get wallet address
|
|
145
|
+
*/
|
|
146
|
+
BloctoWallet.prototype.requestTronConnect = function () {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
+
var _this = this;
|
|
149
|
+
return __generator(this, function (_a) {
|
|
150
|
+
return [2 /*return*/, new Promise(function (res) {
|
|
151
|
+
if (!window.tron) {
|
|
152
|
+
throw new Error(types_1.EnumErrors.NoBlocto);
|
|
153
|
+
}
|
|
154
|
+
var account = window.tron.defaultAddress.base58;
|
|
155
|
+
if (!account) {
|
|
156
|
+
setTimeout(function () {
|
|
157
|
+
account = window.tron.defaultAddress.base58;
|
|
158
|
+
if (!account) {
|
|
159
|
+
throw new Error(types_1.EnumErrors.NoBloctoAccount);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
_this.sdk = window.tron;
|
|
163
|
+
_this.address = account;
|
|
164
|
+
_this.chainId = ''; // todo tron chainId
|
|
165
|
+
res(account);
|
|
166
|
+
}
|
|
167
|
+
}, 1000);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
_this.sdk = window.tron;
|
|
171
|
+
_this.address = account;
|
|
172
|
+
_this.chainId = ''; // todo tron chainId
|
|
173
|
+
res(account);
|
|
174
|
+
}
|
|
175
|
+
})];
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* connect metamask and get wallet address
|
|
181
|
+
* @param chainId specific chainId,throw error when not match
|
|
182
|
+
*/
|
|
183
|
+
BloctoWallet.prototype.requestSolanaConnect = function (chainId) {
|
|
184
|
+
var _this = this;
|
|
185
|
+
return new Promise(function (res) {
|
|
186
|
+
if (!((window.solana && window.solana.isBlocto) || (window.parent && window.parent.solana))) {
|
|
187
|
+
throw new Error(types_1.EnumErrors.NoPhantom);
|
|
188
|
+
}
|
|
189
|
+
var wallet = window.parent && window.parent.solana ? window.parent.solana : window.solana;
|
|
190
|
+
_this.sdk = wallet;
|
|
191
|
+
wallet.on('connect', function (publicKey) {
|
|
192
|
+
var address = wallet.publicKey.toString();
|
|
193
|
+
_this.address = address;
|
|
194
|
+
_this.chainId = ''; // todo sollet chainId
|
|
195
|
+
res(address);
|
|
196
|
+
});
|
|
197
|
+
wallet.connect();
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* connect metamask and get wallet address
|
|
202
|
+
* @param chainId specific chainId,throw error when not match
|
|
203
|
+
*/
|
|
204
|
+
BloctoWallet.prototype.requestFlowConnect = function (chainId) {
|
|
107
205
|
return __awaiter(this, void 0, void 0, function () {
|
|
108
206
|
var _this = this;
|
|
109
207
|
return __generator(this, function (_a) {
|
package/lib/Wallets/BscWallet.js
CHANGED
|
@@ -90,15 +90,10 @@ var BscWallet = /** @class */ (function (_super) {
|
|
|
90
90
|
// go2 download page
|
|
91
91
|
throw new Error(types_1.EnumErrors.NotBinance);
|
|
92
92
|
}
|
|
93
|
-
console.log('BinanceChain-1');
|
|
94
|
-
console.log(window.BinanceChain);
|
|
95
93
|
this.sdk = new web3_1.default(window.BinanceChain);
|
|
96
|
-
console.log('BinanceChain-2');
|
|
97
|
-
console.log(this.sdk);
|
|
98
94
|
return [4 /*yield*/, this.sdk.eth.requestAccounts()];
|
|
99
95
|
case 1:
|
|
100
96
|
account = (_a.sent())[0];
|
|
101
|
-
console.log('BinanceChain-3');
|
|
102
97
|
return [4 /*yield*/, this.sdk.eth.getChainId()];
|
|
103
98
|
case 2:
|
|
104
99
|
currentChainId = _a.sent();
|
|
@@ -72,7 +72,7 @@ var ImTokenWallet = /** @class */ (function (_super) {
|
|
|
72
72
|
_this.name = types_1.EnumWalletName.ImTokenWallet;
|
|
73
73
|
_this.icon = imtoken_svg_1.default;
|
|
74
74
|
_this.supportChains = [types_1.EnumChains.ETH, types_1.EnumChains.BSC, types_1.EnumChains.Polygon, types_1.EnumChains.OKEX, types_1.EnumChains.XDai, types_1.EnumChains.HECO, types_1.EnumChains.Fantom, types_1.EnumChains.Avalanche];
|
|
75
|
-
_this.type = types_1.EnumWalletType.
|
|
75
|
+
_this.type = types_1.EnumWalletType.Mobile;
|
|
76
76
|
_this.sdk = null;
|
|
77
77
|
return _this;
|
|
78
78
|
}
|
|
@@ -86,8 +86,8 @@ var ImTokenWallet = /** @class */ (function (_super) {
|
|
|
86
86
|
return __generator(this, function (_a) {
|
|
87
87
|
switch (_a.label) {
|
|
88
88
|
case 0:
|
|
89
|
-
if (!
|
|
90
|
-
throw new Error(types_1.EnumErrors.
|
|
89
|
+
if (!window.ethereum) {
|
|
90
|
+
throw new Error(types_1.EnumErrors.NoImToken);
|
|
91
91
|
}
|
|
92
92
|
this.sdk = new web3_1.default(window.ethereum);
|
|
93
93
|
return [4 /*yield*/, this.sdk.eth.requestAccounts()];
|
|
@@ -86,8 +86,8 @@ var OntoMobile = /** @class */ (function (_super) {
|
|
|
86
86
|
return __generator(this, function (_a) {
|
|
87
87
|
switch (_a.label) {
|
|
88
88
|
case 0:
|
|
89
|
-
if (!(window.ethereum && window.ethereum.
|
|
90
|
-
throw new Error(types_1.EnumErrors.
|
|
89
|
+
if (!(window.ethereum && window.ethereum.isONTO)) {
|
|
90
|
+
throw new Error(types_1.EnumErrors.NoOnto);
|
|
91
91
|
}
|
|
92
92
|
this.sdk = new web3_1.default(window.ethereum);
|
|
93
93
|
return [4 /*yield*/, this.sdk.eth.getChainId()];
|
|
@@ -101,10 +101,10 @@ var SafePalWallet = /** @class */ (function (_super) {
|
|
|
101
101
|
return __generator(this, function (_a) {
|
|
102
102
|
switch (_a.label) {
|
|
103
103
|
case 0:
|
|
104
|
-
if (!
|
|
105
|
-
throw new Error(types_1.EnumErrors.
|
|
104
|
+
if (!window.safepalProvider) {
|
|
105
|
+
throw new Error(types_1.EnumErrors.NoSafePal);
|
|
106
106
|
}
|
|
107
|
-
this.sdk = new web3_1.default(window.
|
|
107
|
+
this.sdk = new web3_1.default(window.safepalProvider);
|
|
108
108
|
return [4 /*yield*/, this.sdk.eth.requestAccounts()];
|
|
109
109
|
case 1:
|
|
110
110
|
address = (_a.sent())[0];
|
|
@@ -84,9 +84,9 @@ var SolflareWallet = /** @class */ (function (_super) {
|
|
|
84
84
|
var _this = this;
|
|
85
85
|
return __generator(this, function (_a) {
|
|
86
86
|
return [2 /*return*/, new Promise(function (res) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
if (!(window.solflare && window.solflare.isSolflare)) {
|
|
88
|
+
throw new Error(types_1.EnumErrors.NoSolflare);
|
|
89
|
+
}
|
|
90
90
|
var wallet = window.parent && window.parent.solflare ? window.parent.solflare : window.solflare;
|
|
91
91
|
// const wallet = window.solflare;
|
|
92
92
|
_this.sdk = wallet;
|
|
@@ -86,8 +86,8 @@ var TokenPocket = /** @class */ (function (_super) {
|
|
|
86
86
|
return __generator(this, function (_a) {
|
|
87
87
|
switch (_a.label) {
|
|
88
88
|
case 0:
|
|
89
|
-
if (!(window.ethereum && window.ethereum.
|
|
90
|
-
throw new Error(types_1.EnumErrors.
|
|
89
|
+
if (!(window.ethereum && window.ethereum.isTokenPocket)) {
|
|
90
|
+
throw new Error(types_1.EnumErrors.NoTokenPocket);
|
|
91
91
|
}
|
|
92
92
|
this.sdk = new web3_1.default(window.ethereum);
|
|
93
93
|
return [4 /*yield*/, this.sdk.eth.requestAccounts()];
|
package/lib/Wallets/TronLink.js
CHANGED
|
@@ -78,21 +78,36 @@ var TronLink = /** @class */ (function (_super) {
|
|
|
78
78
|
/**
|
|
79
79
|
* connect metamask and get wallet address
|
|
80
80
|
*/
|
|
81
|
-
TronLink.prototype.
|
|
81
|
+
TronLink.prototype.requestTronConnect = function () {
|
|
82
82
|
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
-
var
|
|
83
|
+
var _this = this;
|
|
84
84
|
return __generator(this, function (_a) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
85
|
+
return [2 /*return*/, new Promise(function (res) {
|
|
86
|
+
if (!window.tronWeb) {
|
|
87
|
+
throw new Error(types_1.EnumErrors.NoTronLink);
|
|
88
|
+
}
|
|
89
|
+
var account = window.tronWeb.defaultAddress.base58;
|
|
90
|
+
if (!account) {
|
|
91
|
+
setTimeout(function () {
|
|
92
|
+
account = window.tronWeb.defaultAddress.base58;
|
|
93
|
+
if (!account) {
|
|
94
|
+
throw new Error(types_1.EnumErrors.NoTronLinkAccount);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
_this.sdk = window.tronWeb;
|
|
98
|
+
_this.address = account;
|
|
99
|
+
_this.chainId = ''; // todo tron chainId
|
|
100
|
+
res(account);
|
|
101
|
+
}
|
|
102
|
+
}, 1000);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
_this.sdk = window.tronWeb;
|
|
106
|
+
_this.address = account;
|
|
107
|
+
_this.chainId = ''; // todo tron chainId
|
|
108
|
+
res(account);
|
|
109
|
+
}
|
|
110
|
+
})];
|
|
96
111
|
});
|
|
97
112
|
});
|
|
98
113
|
};
|
|
@@ -7,12 +7,10 @@ declare class TrustWallet extends BaseWallet {
|
|
|
7
7
|
supportChains: EnumChains[];
|
|
8
8
|
type: EnumWalletType;
|
|
9
9
|
sdk: Web3 | null;
|
|
10
|
-
infuraId?: string;
|
|
11
10
|
/**
|
|
12
|
-
* connect
|
|
11
|
+
* connect TrustWallet and get wallet address
|
|
13
12
|
* @param chainId specific chainId,throw error when not match
|
|
14
|
-
* @param config
|
|
15
13
|
*/
|
|
16
|
-
requestConnect(chainId?: number
|
|
14
|
+
requestConnect(chainId?: number): Promise<string>;
|
|
17
15
|
}
|
|
18
16
|
export default TrustWallet;
|
|
@@ -14,17 +14,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
17
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
18
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
19
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -76,7 +65,6 @@ var trust_svg_1 = __importDefault(require("../assets/trust.svg"));
|
|
|
76
65
|
var types_1 = require("../types");
|
|
77
66
|
var BaseWallet_1 = __importDefault(require("./BaseWallet"));
|
|
78
67
|
var web3_1 = __importDefault(require("web3"));
|
|
79
|
-
var web3_provider_1 = __importDefault(require("@walletconnect/web3-provider"));
|
|
80
68
|
var TrustWallet = /** @class */ (function (_super) {
|
|
81
69
|
__extends(TrustWallet, _super);
|
|
82
70
|
function TrustWallet() {
|
|
@@ -96,61 +84,36 @@ var TrustWallet = /** @class */ (function (_super) {
|
|
|
96
84
|
types_1.EnumChains.Optimism,
|
|
97
85
|
types_1.EnumChains.Boba,
|
|
98
86
|
types_1.EnumChains.Moonriver,
|
|
99
|
-
types_1.EnumChains.Aurora,
|
|
100
87
|
types_1.EnumChains.Cronos,
|
|
101
88
|
types_1.EnumChains.Harmony
|
|
102
89
|
];
|
|
103
|
-
_this.type = types_1.EnumWalletType.
|
|
90
|
+
_this.type = types_1.EnumWalletType.Extension;
|
|
104
91
|
_this.sdk = null;
|
|
105
92
|
return _this;
|
|
106
93
|
}
|
|
107
94
|
/**
|
|
108
|
-
* connect
|
|
95
|
+
* connect TrustWallet and get wallet address
|
|
109
96
|
* @param chainId specific chainId,throw error when not match
|
|
110
|
-
* @param config
|
|
111
97
|
*/
|
|
112
|
-
TrustWallet.prototype.requestConnect = function (chainId
|
|
113
|
-
if (chainId === void 0) { chainId = 1; }
|
|
98
|
+
TrustWallet.prototype.requestConnect = function (chainId) {
|
|
114
99
|
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
-
var
|
|
100
|
+
var address, currentChainId;
|
|
116
101
|
return __generator(this, function (_a) {
|
|
117
102
|
switch (_a.label) {
|
|
118
103
|
case 0:
|
|
119
|
-
if (!
|
|
120
|
-
throw new Error(
|
|
104
|
+
if (!window.trustwallet) {
|
|
105
|
+
throw new Error(types_1.EnumErrors.NoTrustWallet);
|
|
121
106
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
420: "https://goerli.optimism.io",
|
|
125
|
-
10: "https://mainnet.optimism.io",
|
|
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.harmony.one",
|
|
140
|
-
} }, config));
|
|
141
|
-
return [4 /*yield*/, provider.enable()];
|
|
107
|
+
this.sdk = new web3_1.default(window.trustwallet);
|
|
108
|
+
return [4 /*yield*/, this.sdk.eth.requestAccounts()];
|
|
142
109
|
case 1:
|
|
143
|
-
_a.sent();
|
|
144
|
-
this.sdk = new web3_1.default(provider);
|
|
110
|
+
address = (_a.sent())[0];
|
|
145
111
|
return [4 /*yield*/, this.sdk.eth.getChainId()];
|
|
146
112
|
case 2:
|
|
147
113
|
currentChainId = _a.sent();
|
|
148
114
|
if (chainId && currentChainId !== chainId) {
|
|
149
115
|
throw new Error(types_1.EnumErrors.ChainIdNotMath);
|
|
150
116
|
}
|
|
151
|
-
return [4 /*yield*/, this.sdk.eth.getAccounts()];
|
|
152
|
-
case 3:
|
|
153
|
-
address = (_a.sent())[0];
|
|
154
117
|
this.address = address;
|
|
155
118
|
this.chainId = currentChainId;
|
|
156
119
|
return [2 /*return*/, address];
|
package/lib/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* @date 2021/4/20
|
|
5
5
|
* @desc
|
|
6
6
|
*/
|
|
7
|
-
import WalletManager from "./WalletManager";
|
|
8
7
|
import MetaMask from "./Wallets/MetaMask";
|
|
9
8
|
import BscWallet from "./Wallets/BscWallet";
|
|
10
9
|
import Cyano from "./Wallets/Cyano";
|
|
@@ -37,5 +36,4 @@ import BitKeepWallet from './Wallets/BitKeepWallet';
|
|
|
37
36
|
import GnosisSafeWallet from './Wallets/GnosisSafeWallet';
|
|
38
37
|
import BloctoWallet from './Wallets/BloctoWallet';
|
|
39
38
|
import { EnumChains } from "./types";
|
|
40
|
-
export
|
|
41
|
-
export { WalletManager, MetaMask, BscWallet, Cyano, TronLink, EnumChains, Sollet, SolletIo, OntoMobile, WalletConnect, MathWallet, OntoWallet, SafePalWallet, ImTokenWallet, TokenPocket, TrustWallet, Coin98, Phantom, OKExWallet, TerraStation, CoinbaseWallet, CloverWallet, XDEFIWallet, SlopeWallet, SolflareWallet, MetaXWallet, KeplrWallet, BraveWallet, CryptoCom, NearWallet, BitKeepWallet, GnosisSafeWallet, BloctoWallet };
|
|
39
|
+
export { MetaMask, BscWallet, Cyano, TronLink, EnumChains, Sollet, SolletIo, OntoMobile, WalletConnect, MathWallet, OntoWallet, SafePalWallet, ImTokenWallet, TokenPocket, TrustWallet, Coin98, Phantom, OKExWallet, TerraStation, CoinbaseWallet, CloverWallet, XDEFIWallet, SlopeWallet, SolflareWallet, MetaXWallet, KeplrWallet, BraveWallet, CryptoCom, NearWallet, BitKeepWallet, GnosisSafeWallet, BloctoWallet };
|
package/lib/index.js
CHANGED
|
@@ -3,15 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.BloctoWallet = exports.GnosisSafeWallet = exports.BitKeepWallet = exports.NearWallet = exports.CryptoCom = exports.BraveWallet = exports.KeplrWallet = exports.MetaXWallet = exports.SolflareWallet = exports.SlopeWallet = exports.XDEFIWallet = exports.CloverWallet = exports.CoinbaseWallet = exports.TerraStation = exports.OKExWallet = exports.Phantom = exports.Coin98 = exports.TrustWallet = exports.TokenPocket = exports.ImTokenWallet = exports.SafePalWallet = exports.OntoWallet = exports.MathWallet = exports.WalletConnect = exports.OntoMobile = exports.SolletIo = exports.Sollet = exports.EnumChains = exports.TronLink = exports.Cyano = exports.BscWallet = exports.MetaMask =
|
|
6
|
+
exports.BloctoWallet = exports.GnosisSafeWallet = exports.BitKeepWallet = exports.NearWallet = exports.CryptoCom = exports.BraveWallet = exports.KeplrWallet = exports.MetaXWallet = exports.SolflareWallet = exports.SlopeWallet = exports.XDEFIWallet = exports.CloverWallet = exports.CoinbaseWallet = exports.TerraStation = exports.OKExWallet = exports.Phantom = exports.Coin98 = exports.TrustWallet = exports.TokenPocket = exports.ImTokenWallet = exports.SafePalWallet = exports.OntoWallet = exports.MathWallet = exports.WalletConnect = exports.OntoMobile = exports.SolletIo = exports.Sollet = exports.EnumChains = exports.TronLink = exports.Cyano = exports.BscWallet = exports.MetaMask = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* wallets-manager entry
|
|
9
9
|
* @author openocean
|
|
10
10
|
* @date 2021/4/20
|
|
11
11
|
* @desc
|
|
12
12
|
*/
|
|
13
|
-
var WalletManager_1 = __importDefault(require("./WalletManager"));
|
|
14
|
-
exports.WalletManager = WalletManager_1.default;
|
|
15
13
|
var MetaMask_1 = __importDefault(require("./Wallets/MetaMask"));
|
|
16
14
|
exports.MetaMask = MetaMask_1.default;
|
|
17
15
|
var BscWallet_1 = __importDefault(require("./Wallets/BscWallet"));
|
|
@@ -77,4 +75,3 @@ exports.BloctoWallet = BloctoWallet_1.default;
|
|
|
77
75
|
var types_1 = require("./types");
|
|
78
76
|
Object.defineProperty(exports, "EnumChains", { enumerable: true, get: function () { return types_1.EnumChains; } });
|
|
79
77
|
var process = {};
|
|
80
|
-
exports.default = WalletManager_1.default;
|
package/lib/types.d.ts
CHANGED
|
@@ -103,7 +103,12 @@ export declare enum EnumErrors {
|
|
|
103
103
|
NoBrave = "40025",
|
|
104
104
|
NoCryptoCom = "40026",
|
|
105
105
|
NoBitKeep = "40027",
|
|
106
|
-
|
|
106
|
+
NoSafePal = "40028",
|
|
107
|
+
NoTrustWallet = "40029",
|
|
108
|
+
NoTokenPocket = "40030",
|
|
109
|
+
NoImToken = "40031",
|
|
110
|
+
NoBlocto = "40032",
|
|
111
|
+
NoBloctoAccount = "40033"
|
|
107
112
|
}
|
|
108
113
|
export interface ConnectResult {
|
|
109
114
|
chain: EnumChains;
|
package/lib/types.js
CHANGED
|
@@ -106,5 +106,10 @@ var EnumErrors;
|
|
|
106
106
|
EnumErrors["NoBrave"] = "40025";
|
|
107
107
|
EnumErrors["NoCryptoCom"] = "40026";
|
|
108
108
|
EnumErrors["NoBitKeep"] = "40027";
|
|
109
|
-
EnumErrors["
|
|
109
|
+
EnumErrors["NoSafePal"] = "40028";
|
|
110
|
+
EnumErrors["NoTrustWallet"] = "40029";
|
|
111
|
+
EnumErrors["NoTokenPocket"] = "40030";
|
|
112
|
+
EnumErrors["NoImToken"] = "40031";
|
|
113
|
+
EnumErrors["NoBlocto"] = "40032";
|
|
114
|
+
EnumErrors["NoBloctoAccount"] = "40033";
|
|
110
115
|
})(EnumErrors = exports.EnumErrors || (exports.EnumErrors = {}));
|
package/package.json
CHANGED
package/lib/WalletManager.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import EthChain from "./Chains/EthChain";
|
|
2
|
-
import { EnumChains, SelectConnect } from "./types";
|
|
3
|
-
interface Props {
|
|
4
|
-
selectConnect: SelectConnect;
|
|
5
|
-
}
|
|
6
|
-
declare class WalletManager {
|
|
7
|
-
supportChains: EnumChains[];
|
|
8
|
-
eth: EthChain;
|
|
9
|
-
selectConnect: SelectConnect;
|
|
10
|
-
constructor({ selectConnect }: Props);
|
|
11
|
-
/**
|
|
12
|
-
* show connect modal and connect
|
|
13
|
-
*/
|
|
14
|
-
connect(): Promise<any>;
|
|
15
|
-
/**
|
|
16
|
-
* todo set up with local connection state
|
|
17
|
-
*/
|
|
18
|
-
useCache(): void;
|
|
19
|
-
}
|
|
20
|
-
export default WalletManager;
|
package/lib/WalletManager.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
/**
|
|
43
|
-
* @name WalletManager
|
|
44
|
-
* @author openocean
|
|
45
|
-
* @date 2021/4/20
|
|
46
|
-
* @desc
|
|
47
|
-
*/
|
|
48
|
-
var BscWallet_1 = __importDefault(require("./Wallets/BscWallet"));
|
|
49
|
-
var Cyano_1 = __importDefault(require("./Wallets/Cyano"));
|
|
50
|
-
var MetaMask_1 = __importDefault(require("./Wallets/MetaMask"));
|
|
51
|
-
var TronLink_1 = __importDefault(require("./Wallets/TronLink"));
|
|
52
|
-
var EthChain_1 = __importDefault(require("./Chains/EthChain"));
|
|
53
|
-
var types_1 = require("./types");
|
|
54
|
-
var WalletManager = /** @class */ (function () {
|
|
55
|
-
function WalletManager(_a) {
|
|
56
|
-
var selectConnect = _a.selectConnect;
|
|
57
|
-
this.supportChains = [types_1.EnumChains.ETH, types_1.EnumChains.BSC, types_1.EnumChains.ONT, types_1.EnumChains.TRON];
|
|
58
|
-
this.eth = new EthChain_1.default();
|
|
59
|
-
this.selectConnect = selectConnect;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* show connect modal and connect
|
|
63
|
-
*/
|
|
64
|
-
WalletManager.prototype.connect = function () {
|
|
65
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
-
var _a, chain, walletName, onSuccess, onError, walletMap, Wallet, chainIns, result, e_1;
|
|
67
|
-
var _b;
|
|
68
|
-
return __generator(this, function (_c) {
|
|
69
|
-
switch (_c.label) {
|
|
70
|
-
case 0: return [4 /*yield*/, this.selectConnect()];
|
|
71
|
-
case 1:
|
|
72
|
-
_a = _c.sent(), chain = _a.chain, walletName = _a.walletName, onSuccess = _a.onSuccess, onError = _a.onError;
|
|
73
|
-
walletMap = (_b = {},
|
|
74
|
-
_b[types_1.EnumWalletName.MetaMask] = MetaMask_1.default,
|
|
75
|
-
_b[types_1.EnumWalletName.BscWallet] = BscWallet_1.default,
|
|
76
|
-
_b[types_1.EnumWalletName.Cyano] = Cyano_1.default,
|
|
77
|
-
_b[types_1.EnumWalletName.TronLink] = TronLink_1.default,
|
|
78
|
-
_b);
|
|
79
|
-
Wallet = walletMap[walletName];
|
|
80
|
-
if (!Wallet) {
|
|
81
|
-
throw new Error('Unsupported wallet');
|
|
82
|
-
}
|
|
83
|
-
if (!this.supportChains.includes(chain)) {
|
|
84
|
-
throw new Error('Unsupported chain');
|
|
85
|
-
}
|
|
86
|
-
_c.label = 2;
|
|
87
|
-
case 2:
|
|
88
|
-
_c.trys.push([2, 4, , 5]);
|
|
89
|
-
chainIns = this[chain];
|
|
90
|
-
chainIns.wallet = new Wallet();
|
|
91
|
-
chainIns.wallet.chain = chain;
|
|
92
|
-
return [4 /*yield*/, chainIns.wallet.requestConnect()];
|
|
93
|
-
case 3:
|
|
94
|
-
result = _c.sent();
|
|
95
|
-
if (onSuccess) {
|
|
96
|
-
onSuccess();
|
|
97
|
-
}
|
|
98
|
-
return [2 /*return*/, result];
|
|
99
|
-
case 4:
|
|
100
|
-
e_1 = _c.sent();
|
|
101
|
-
if (onError) {
|
|
102
|
-
onError(e_1);
|
|
103
|
-
}
|
|
104
|
-
throw new Error(e_1);
|
|
105
|
-
case 5: return [2 /*return*/];
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* todo set up with local connection state
|
|
112
|
-
*/
|
|
113
|
-
WalletManager.prototype.useCache = function () {
|
|
114
|
-
};
|
|
115
|
-
return WalletManager;
|
|
116
|
-
}());
|
|
117
|
-
exports.default = WalletManager;
|