@openocean.finance/wallet 0.3.8 → 0.4.2

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.
Files changed (70) hide show
  1. package/lib/.DS_Store +0 -0
  2. package/lib/Chains/BaseChain.js +8 -0
  3. package/lib/Chains/EthChain.js +41 -0
  4. package/lib/Chains/index.js +1 -0
  5. package/lib/WalletManager.js +117 -0
  6. package/lib/Wallets/BaseWallet.js +8 -0
  7. package/lib/Wallets/BraveWallet.js +129 -0
  8. package/lib/Wallets/BscWallet.js +112 -0
  9. package/lib/Wallets/CloverWallet.js +136 -0
  10. package/lib/Wallets/Coin98.js +139 -0
  11. package/lib/Wallets/CoinbaseWallet.js +111 -0
  12. package/lib/Wallets/CryptoCom.d.ts +16 -0
  13. package/lib/Wallets/CryptoCom.js +111 -0
  14. package/lib/Wallets/Cyano.js +108 -0
  15. package/lib/Wallets/ImTokenWallet.js +111 -0
  16. package/lib/Wallets/KeplrWallet.js +121 -0
  17. package/lib/Wallets/MathWallet.js +111 -0
  18. package/lib/Wallets/MetaMask.js +130 -0
  19. package/lib/Wallets/MetaXWallet.js +112 -0
  20. package/lib/Wallets/OKExWallet.js +112 -0
  21. package/lib/Wallets/OntoMobile.js +111 -0
  22. package/lib/Wallets/OntoWallet.js +112 -0
  23. package/lib/Wallets/Phantom.js +65 -0
  24. package/lib/Wallets/SafePalWallet.js +126 -0
  25. package/lib/Wallets/SlopeWallet.js +110 -0
  26. package/lib/Wallets/SolflareWallet.js +106 -0
  27. package/lib/Wallets/Sollet.js +67 -0
  28. package/lib/Wallets/SolletIo.js +64 -0
  29. package/lib/Wallets/TerraStation.js +64 -0
  30. package/lib/Wallets/TokenPocket.js +111 -0
  31. package/lib/Wallets/TronLink.js +101 -0
  32. package/lib/Wallets/TrustWallet.js +163 -0
  33. package/lib/Wallets/WalletConnect.js +163 -0
  34. package/lib/Wallets/{XDEFIWallet.d.ts → XDeFiWallet.d.ts} +0 -0
  35. package/lib/Wallets/XDeFiWallet.js +138 -0
  36. package/lib/assets/.DS_Store +0 -0
  37. package/lib/assets/approveErc20Abi.json +23 -0
  38. package/lib/assets/brave.svg +24 -0
  39. package/lib/assets/bscwallet.svg +23 -0
  40. package/lib/assets/clover.svg +11 -0
  41. package/lib/assets/coin98.svg +18 -0
  42. package/lib/assets/coinbase.svg +17 -0
  43. package/lib/assets/cryptoCom.svg +14 -0
  44. package/lib/assets/cyano.svg +7 -0
  45. package/lib/assets/erc20Abi.json +222 -0
  46. package/lib/assets/imtoken.svg +12 -0
  47. package/lib/assets/keplr.png +0 -0
  48. package/lib/assets/math.svg +1 -0
  49. package/lib/assets/metamask.svg +1 -0
  50. package/lib/assets/metax.svg +10 -0
  51. package/lib/assets/okex.svg +21 -0
  52. package/lib/assets/onto.svg +1 -0
  53. package/lib/assets/phantom.svg +22 -0
  54. package/lib/assets/safepal.svg +1 -0
  55. package/lib/assets/slope.svg +25 -0
  56. package/lib/assets/solflare.svg +23 -0
  57. package/lib/assets/sollet.svg +7 -0
  58. package/lib/assets/terra.svg +17 -0
  59. package/lib/assets/tokenpocket.svg +1 -0
  60. package/lib/assets/tronlink.svg +25 -0
  61. package/lib/assets/trust.svg +10 -0
  62. package/lib/assets/walletconnect.svg +1 -0
  63. package/lib/assets/xdefi.svg +15 -0
  64. package/lib/index.d.ts +3 -2
  65. package/lib/index.js +72 -2
  66. package/lib/types.d.ts +4 -2
  67. package/lib/types.js +101 -0
  68. package/package.json +28 -10
  69. package/README.md +0 -6
  70. package/lib/index.js.LICENSE.txt +0 -216
package/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var BaseChain = /** @class */ (function () {
4
+ function BaseChain() {
5
+ }
6
+ return BaseChain;
7
+ }());
8
+ exports.default = BaseChain;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ /**
22
+ * @name EthChain
23
+ * @author openocean
24
+ * @date 2021/4/21
25
+ * @desc
26
+ */
27
+ var types_1 = require("../types");
28
+ var BaseChain_1 = __importDefault(require("./BaseChain"));
29
+ var EthChain = /** @class */ (function (_super) {
30
+ __extends(EthChain, _super);
31
+ function EthChain() {
32
+ var _this = _super !== null && _super.apply(this, arguments) || this;
33
+ _this.chain = types_1.EnumChains.ETH;
34
+ return _this;
35
+ }
36
+ EthChain.prototype.approveAndSwap = function () {
37
+ throw new Error('todo');
38
+ };
39
+ return EthChain;
40
+ }(BaseChain_1.default));
41
+ exports.default = EthChain;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,117 @@
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;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var BaseWallet = /** @class */ (function () {
4
+ function BaseWallet() {
5
+ }
6
+ return BaseWallet;
7
+ }());
8
+ exports.default = BaseWallet;
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ 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;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ /**
58
+ * @name BraveWallet
59
+ * @author openocean
60
+ * @date 2021/4/21
61
+ * @desc
62
+ */
63
+ // @ts-ignore
64
+ var brave_svg_1 = __importDefault(require("../assets/brave.svg"));
65
+ var types_1 = require("../types");
66
+ var BaseWallet_1 = __importDefault(require("./BaseWallet"));
67
+ var web3_1 = __importDefault(require("web3"));
68
+ var BraveWallet = /** @class */ (function (_super) {
69
+ __extends(BraveWallet, _super);
70
+ function BraveWallet() {
71
+ var _this = _super !== null && _super.apply(this, arguments) || this;
72
+ _this.name = types_1.EnumWalletName.BraveWallet;
73
+ _this.icon = brave_svg_1.default;
74
+ _this.supportChains = [
75
+ types_1.EnumChains.ETH,
76
+ types_1.EnumChains.ROPSTEN,
77
+ types_1.EnumChains.BSC,
78
+ types_1.EnumChains.BSCTEST,
79
+ types_1.EnumChains.Polygon,
80
+ types_1.EnumChains.OKEX,
81
+ types_1.EnumChains.XDai,
82
+ types_1.EnumChains.HECO,
83
+ types_1.EnumChains.Fantom,
84
+ types_1.EnumChains.Avalanche,
85
+ types_1.EnumChains.Arbitrum,
86
+ types_1.EnumChains.Optimism,
87
+ types_1.EnumChains.Boba,
88
+ types_1.EnumChains.Moonriver,
89
+ types_1.EnumChains.Aurora,
90
+ types_1.EnumChains.Cronos,
91
+ types_1.EnumChains.Harmony
92
+ ];
93
+ _this.type = types_1.EnumWalletType.Extension;
94
+ _this.sdk = null;
95
+ return _this;
96
+ }
97
+ /**
98
+ * connect metamask and get wallet address
99
+ * @param chainId specific chainId,throw error when not match
100
+ */
101
+ BraveWallet.prototype.requestConnect = function (chainId) {
102
+ return __awaiter(this, void 0, void 0, function () {
103
+ var address, currentChainId;
104
+ return __generator(this, function (_a) {
105
+ switch (_a.label) {
106
+ case 0:
107
+ if (!(window.ethereum && window.ethereum.isBraveWallet)) {
108
+ throw new Error(types_1.EnumErrors.NoBrave);
109
+ }
110
+ this.sdk = new web3_1.default(window.ethereum);
111
+ return [4 /*yield*/, this.sdk.eth.requestAccounts()];
112
+ case 1:
113
+ address = (_a.sent())[0];
114
+ return [4 /*yield*/, this.sdk.eth.getChainId()];
115
+ case 2:
116
+ currentChainId = _a.sent();
117
+ if (chainId && currentChainId !== chainId) {
118
+ throw new Error(types_1.EnumErrors.ChainIdNotMath);
119
+ }
120
+ this.address = address;
121
+ this.chainId = currentChainId;
122
+ return [2 /*return*/, address];
123
+ }
124
+ });
125
+ });
126
+ };
127
+ return BraveWallet;
128
+ }(BaseWallet_1.default));
129
+ exports.default = BraveWallet;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ 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;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ /**
58
+ * @name BscWallet
59
+ * @author openocean
60
+ * @date 2021/4/21
61
+ * @desc
62
+ */
63
+ // @ts-ignore
64
+ var bscwallet_svg_1 = __importDefault(require("../assets/bscwallet.svg"));
65
+ var types_1 = require("../types");
66
+ var BaseWallet_1 = __importDefault(require("./BaseWallet"));
67
+ var web3_1 = __importDefault(require("web3"));
68
+ var BscWallet = /** @class */ (function (_super) {
69
+ __extends(BscWallet, _super);
70
+ function BscWallet() {
71
+ var _this = _super !== null && _super.apply(this, arguments) || this;
72
+ _this.name = types_1.EnumWalletName.BscWallet;
73
+ _this.icon = bscwallet_svg_1.default;
74
+ _this.supportChains = [types_1.EnumChains.BSC];
75
+ _this.type = types_1.EnumWalletType.Extension;
76
+ _this.sdk = null;
77
+ return _this;
78
+ }
79
+ /**
80
+ * connect metamask and get wallet address
81
+ * @param chainId specific chainId,throw error when not match
82
+ */
83
+ BscWallet.prototype.requestConnect = function (chainId) {
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ var account, currentChainId;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0:
89
+ if (!window.BinanceChain) {
90
+ // go2 download page
91
+ throw new Error(types_1.EnumErrors.NotBinance);
92
+ }
93
+ this.sdk = new web3_1.default(window.BinanceChain);
94
+ return [4 /*yield*/, this.sdk.eth.requestAccounts()];
95
+ case 1:
96
+ account = (_a.sent())[0];
97
+ return [4 /*yield*/, this.sdk.eth.getChainId()];
98
+ case 2:
99
+ currentChainId = _a.sent();
100
+ if (chainId && currentChainId !== chainId) {
101
+ throw new Error(types_1.EnumErrors.ChainIdNotMath);
102
+ }
103
+ this.address = account;
104
+ this.chainId = chainId;
105
+ return [2 /*return*/, account];
106
+ }
107
+ });
108
+ });
109
+ };
110
+ return BscWallet;
111
+ }(BaseWallet_1.default));
112
+ exports.default = BscWallet;
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ 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;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ /**
58
+ * @name CloverWallet
59
+ * @author openocean
60
+ * @date 2021/4/21
61
+ * @desc
62
+ */
63
+ // @ts-ignore
64
+ var clover_svg_1 = __importDefault(require("../assets/clover.svg"));
65
+ var types_1 = require("../types");
66
+ var BaseWallet_1 = __importDefault(require("./BaseWallet"));
67
+ var web3_1 = __importDefault(require("web3"));
68
+ var CloverWallet = /** @class */ (function (_super) {
69
+ __extends(CloverWallet, _super);
70
+ function CloverWallet() {
71
+ var _this = _super !== null && _super.apply(this, arguments) || this;
72
+ _this.name = types_1.EnumWalletName.CloverWallet;
73
+ _this.icon = clover_svg_1.default;
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, types_1.EnumChains.Arbitrum, types_1.EnumChains.Optimism, types_1.EnumChains.Boba, types_1.EnumChains.Solana];
75
+ _this.type = types_1.EnumWalletType.Extension;
76
+ _this.sdk = null;
77
+ return _this;
78
+ }
79
+ /**
80
+ * connect Clover and get wallet address
81
+ * @param chainId specific chainId,throw error when not match
82
+ */
83
+ CloverWallet.prototype.requestConnect = function (chainId) {
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ var address, currentChainId;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0:
89
+ if (!window.clover) {
90
+ throw new Error(types_1.EnumErrors.NoClover);
91
+ }
92
+ this.sdk = new web3_1.default(window.clover);
93
+ return [4 /*yield*/, this.sdk.eth.requestAccounts()];
94
+ case 1:
95
+ address = (_a.sent())[0];
96
+ return [4 /*yield*/, this.sdk.eth.getChainId()];
97
+ case 2:
98
+ currentChainId = _a.sent();
99
+ if (chainId && currentChainId !== chainId) {
100
+ throw new Error(types_1.EnumErrors.ChainIdNotMath);
101
+ }
102
+ this.address = address;
103
+ this.chainId = currentChainId;
104
+ return [2 /*return*/, address];
105
+ }
106
+ });
107
+ });
108
+ };
109
+ /**
110
+ * connect metamask and get wallet address
111
+ * @param chainId specific chainId,throw error when not match
112
+ */
113
+ CloverWallet.prototype.requestSolanaConnect = function () {
114
+ return __awaiter(this, void 0, void 0, function () {
115
+ var wallet, address;
116
+ return __generator(this, function (_a) {
117
+ switch (_a.label) {
118
+ case 0:
119
+ if (!window.clover_solana) {
120
+ throw new Error(types_1.EnumErrors.NoClover);
121
+ }
122
+ wallet = window.clover_solana;
123
+ this.sdk = wallet;
124
+ return [4 /*yield*/, wallet.getAccount()];
125
+ case 1:
126
+ address = _a.sent();
127
+ this.address = address;
128
+ this.chainId = '';
129
+ return [2 /*return*/, address];
130
+ }
131
+ });
132
+ });
133
+ };
134
+ return CloverWallet;
135
+ }(BaseWallet_1.default));
136
+ exports.default = CloverWallet;