@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.
- package/lib/.DS_Store +0 -0
- package/lib/Chains/BaseChain.js +8 -0
- package/lib/Chains/EthChain.js +41 -0
- package/lib/Chains/index.js +1 -0
- package/lib/WalletManager.js +117 -0
- package/lib/Wallets/BaseWallet.js +8 -0
- package/lib/Wallets/BraveWallet.js +129 -0
- package/lib/Wallets/BscWallet.js +112 -0
- package/lib/Wallets/CloverWallet.js +136 -0
- package/lib/Wallets/Coin98.js +139 -0
- package/lib/Wallets/CoinbaseWallet.js +111 -0
- package/lib/Wallets/CryptoCom.d.ts +16 -0
- package/lib/Wallets/CryptoCom.js +111 -0
- package/lib/Wallets/Cyano.js +108 -0
- package/lib/Wallets/ImTokenWallet.js +111 -0
- package/lib/Wallets/KeplrWallet.js +121 -0
- package/lib/Wallets/MathWallet.js +111 -0
- package/lib/Wallets/MetaMask.js +130 -0
- package/lib/Wallets/MetaXWallet.js +112 -0
- package/lib/Wallets/OKExWallet.js +112 -0
- package/lib/Wallets/OntoMobile.js +111 -0
- package/lib/Wallets/OntoWallet.js +112 -0
- package/lib/Wallets/Phantom.js +65 -0
- package/lib/Wallets/SafePalWallet.js +126 -0
- package/lib/Wallets/SlopeWallet.js +110 -0
- package/lib/Wallets/SolflareWallet.js +106 -0
- package/lib/Wallets/Sollet.js +67 -0
- package/lib/Wallets/SolletIo.js +64 -0
- package/lib/Wallets/TerraStation.js +64 -0
- package/lib/Wallets/TokenPocket.js +111 -0
- package/lib/Wallets/TronLink.js +101 -0
- package/lib/Wallets/TrustWallet.js +163 -0
- package/lib/Wallets/WalletConnect.js +163 -0
- package/lib/Wallets/{XDEFIWallet.d.ts → XDeFiWallet.d.ts} +0 -0
- package/lib/Wallets/XDeFiWallet.js +138 -0
- package/lib/assets/.DS_Store +0 -0
- package/lib/assets/approveErc20Abi.json +23 -0
- package/lib/assets/brave.svg +24 -0
- package/lib/assets/bscwallet.svg +23 -0
- package/lib/assets/clover.svg +11 -0
- package/lib/assets/coin98.svg +18 -0
- package/lib/assets/coinbase.svg +17 -0
- package/lib/assets/cryptoCom.svg +14 -0
- package/lib/assets/cyano.svg +7 -0
- package/lib/assets/erc20Abi.json +222 -0
- package/lib/assets/imtoken.svg +12 -0
- package/lib/assets/keplr.png +0 -0
- package/lib/assets/math.svg +1 -0
- package/lib/assets/metamask.svg +1 -0
- package/lib/assets/metax.svg +10 -0
- package/lib/assets/okex.svg +21 -0
- package/lib/assets/onto.svg +1 -0
- package/lib/assets/phantom.svg +22 -0
- package/lib/assets/safepal.svg +1 -0
- package/lib/assets/slope.svg +25 -0
- package/lib/assets/solflare.svg +23 -0
- package/lib/assets/sollet.svg +7 -0
- package/lib/assets/terra.svg +17 -0
- package/lib/assets/tokenpocket.svg +1 -0
- package/lib/assets/tronlink.svg +25 -0
- package/lib/assets/trust.svg +10 -0
- package/lib/assets/walletconnect.svg +1 -0
- package/lib/assets/xdefi.svg +15 -0
- package/lib/index.d.ts +3 -2
- package/lib/index.js +72 -2
- package/lib/types.d.ts +4 -2
- package/lib/types.js +101 -0
- package/package.json +28 -10
- package/README.md +0 -6
- package/lib/index.js.LICENSE.txt +0 -216
|
@@ -0,0 +1,121 @@
|
|
|
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 Sollet
|
|
59
|
+
* @author openocean
|
|
60
|
+
* @date 2021/4/21
|
|
61
|
+
* @desc
|
|
62
|
+
*/
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
var keplr_png_1 = __importDefault(require("../assets/keplr.png"));
|
|
65
|
+
var types_1 = require("../types");
|
|
66
|
+
var BaseWallet_1 = __importDefault(require("./BaseWallet"));
|
|
67
|
+
var launchpad_1 = require("@cosmjs/launchpad");
|
|
68
|
+
var stargate_1 = require("@cosmjs/stargate");
|
|
69
|
+
var KeplrWallet = /** @class */ (function (_super) {
|
|
70
|
+
__extends(KeplrWallet, _super);
|
|
71
|
+
function KeplrWallet() {
|
|
72
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
73
|
+
_this.name = types_1.EnumWalletName.keplrWallet;
|
|
74
|
+
_this.icon = keplr_png_1.default;
|
|
75
|
+
_this.supportChains = [types_1.EnumChains.Osmosis, types_1.EnumChains.Sifchain];
|
|
76
|
+
_this.type = types_1.EnumWalletType.Web;
|
|
77
|
+
_this.sdk = null;
|
|
78
|
+
return _this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* connect metamask and get wallet address
|
|
82
|
+
* @param chainId specific chainId,throw error when not match
|
|
83
|
+
*/
|
|
84
|
+
KeplrWallet.prototype.requestCosmosConnect = function (customRegistry, customAminoTypes, endpoint, apiUrl, chainId) {
|
|
85
|
+
var _this = this;
|
|
86
|
+
return new Promise(function (res) { return __awaiter(_this, void 0, void 0, function () {
|
|
87
|
+
var wallet, offlineSigner, accounts, address, _a;
|
|
88
|
+
return __generator(this, function (_b) {
|
|
89
|
+
switch (_b.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
if (!window.keplr) {
|
|
92
|
+
throw new Error(types_1.EnumErrors.NoKeplr);
|
|
93
|
+
}
|
|
94
|
+
wallet = window.keplr;
|
|
95
|
+
return [4 /*yield*/, wallet.enable(chainId)];
|
|
96
|
+
case 1:
|
|
97
|
+
_b.sent();
|
|
98
|
+
offlineSigner = wallet.getOfflineSigner(chainId);
|
|
99
|
+
return [4 /*yield*/, offlineSigner.getAccounts()];
|
|
100
|
+
case 2:
|
|
101
|
+
accounts = _b.sent();
|
|
102
|
+
address = accounts[0].address;
|
|
103
|
+
_a = this;
|
|
104
|
+
return [4 /*yield*/, stargate_1.SigningStargateClient.connectWithSigner(endpoint, offlineSigner, {
|
|
105
|
+
registry: customRegistry,
|
|
106
|
+
aminoTypes: customAminoTypes,
|
|
107
|
+
})];
|
|
108
|
+
case 3:
|
|
109
|
+
_a.sdk = _b.sent();
|
|
110
|
+
this.sdk.lcdClient = launchpad_1.LcdClient.withExtensions({ apiUrl: apiUrl }, launchpad_1.setupAuthExtension, launchpad_1.setupBankExtension, launchpad_1.setupDistributionExtension, launchpad_1.setupGovExtension, launchpad_1.setupMintExtension, launchpad_1.setupSlashingExtension, launchpad_1.setupStakingExtension, launchpad_1.setupSupplyExtension);
|
|
111
|
+
this.address = address;
|
|
112
|
+
this.chainId = chainId;
|
|
113
|
+
res(address);
|
|
114
|
+
return [2 /*return*/];
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}); });
|
|
118
|
+
};
|
|
119
|
+
return KeplrWallet;
|
|
120
|
+
}(BaseWallet_1.default));
|
|
121
|
+
exports.default = KeplrWallet;
|
|
@@ -0,0 +1,111 @@
|
|
|
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 MathWallet
|
|
59
|
+
* @author openocean
|
|
60
|
+
* @date 2021/4/21
|
|
61
|
+
* @desc
|
|
62
|
+
*/
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
var math_svg_1 = __importDefault(require("../assets/math.svg"));
|
|
65
|
+
var types_1 = require("../types");
|
|
66
|
+
var BaseWallet_1 = __importDefault(require("./BaseWallet"));
|
|
67
|
+
var web3_1 = __importDefault(require("web3"));
|
|
68
|
+
var MathWallet = /** @class */ (function (_super) {
|
|
69
|
+
__extends(MathWallet, _super);
|
|
70
|
+
function MathWallet() {
|
|
71
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
72
|
+
_this.name = types_1.EnumWalletName.MathWallet;
|
|
73
|
+
_this.icon = math_svg_1.default;
|
|
74
|
+
_this.supportChains = [types_1.EnumChains.ETH, types_1.EnumChains.BSC, types_1.EnumChains.HECO, types_1.EnumChains.Fantom, types_1.EnumChains.OKEX, types_1.EnumChains.XDai, types_1.EnumChains.Arbitrum, types_1.EnumChains.Optimism];
|
|
75
|
+
_this.type = types_1.EnumWalletType.Extension;
|
|
76
|
+
_this.sdk = null;
|
|
77
|
+
return _this;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* connect MathWallet and get wallet address
|
|
81
|
+
* @param chainId specific chainId,throw error when not match
|
|
82
|
+
*/
|
|
83
|
+
MathWallet.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.ethereum && window.ethereum.isMathWallet)) {
|
|
90
|
+
throw new Error(types_1.EnumErrors.NoMath);
|
|
91
|
+
}
|
|
92
|
+
this.sdk = new web3_1.default(window.ethereum);
|
|
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
|
+
return MathWallet;
|
|
110
|
+
}(BaseWallet_1.default));
|
|
111
|
+
exports.default = MathWallet;
|
|
@@ -0,0 +1,130 @@
|
|
|
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 MetaMask
|
|
59
|
+
* @author openocean
|
|
60
|
+
* @date 2021/4/21
|
|
61
|
+
* @desc
|
|
62
|
+
*/
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
var metamask_svg_1 = __importDefault(require("../assets/metamask.svg"));
|
|
65
|
+
var types_1 = require("../types");
|
|
66
|
+
var BaseWallet_1 = __importDefault(require("./BaseWallet"));
|
|
67
|
+
var web3_1 = __importDefault(require("web3"));
|
|
68
|
+
var MetaMask = /** @class */ (function (_super) {
|
|
69
|
+
__extends(MetaMask, _super);
|
|
70
|
+
function MetaMask() {
|
|
71
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
72
|
+
_this.name = types_1.EnumWalletName.MetaMask;
|
|
73
|
+
_this.icon = metamask_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
|
+
// web3 = new Web3(Web3.givenProvider || window.safepal_wallet_app);
|
|
98
|
+
/**
|
|
99
|
+
* connect metamask and get wallet address
|
|
100
|
+
* @param chainId specific chainId,throw error when not match
|
|
101
|
+
*/
|
|
102
|
+
MetaMask.prototype.requestConnect = function (chainId) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
+
var address, currentChainId;
|
|
105
|
+
return __generator(this, function (_a) {
|
|
106
|
+
switch (_a.label) {
|
|
107
|
+
case 0:
|
|
108
|
+
if (!((window.ethereum && window.ethereum.isMetaMask) || (web3_1.default && web3_1.default.givenProvider) || window.safepal_wallet_app)) {
|
|
109
|
+
throw new Error(types_1.EnumErrors.NotMetamask);
|
|
110
|
+
}
|
|
111
|
+
this.sdk = new web3_1.default(window.ethereum || web3_1.default.givenProvider || window.safepal_wallet_app);
|
|
112
|
+
return [4 /*yield*/, this.sdk.eth.requestAccounts()];
|
|
113
|
+
case 1:
|
|
114
|
+
address = (_a.sent())[0];
|
|
115
|
+
return [4 /*yield*/, this.sdk.eth.getChainId()];
|
|
116
|
+
case 2:
|
|
117
|
+
currentChainId = _a.sent();
|
|
118
|
+
if (chainId && currentChainId !== chainId) {
|
|
119
|
+
throw new Error(types_1.EnumErrors.ChainIdNotMath);
|
|
120
|
+
}
|
|
121
|
+
this.address = address;
|
|
122
|
+
this.chainId = currentChainId;
|
|
123
|
+
return [2 /*return*/, address];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
return MetaMask;
|
|
129
|
+
}(BaseWallet_1.default));
|
|
130
|
+
exports.default = MetaMask;
|
|
@@ -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 OKExWallet
|
|
59
|
+
* @author openocean
|
|
60
|
+
* @date 2021/4/21
|
|
61
|
+
* @desc
|
|
62
|
+
*/
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
var metax_svg_1 = __importDefault(require("../assets/metax.svg"));
|
|
65
|
+
var types_1 = require("../types");
|
|
66
|
+
var BaseWallet_1 = __importDefault(require("./BaseWallet"));
|
|
67
|
+
var web3_1 = __importDefault(require("web3"));
|
|
68
|
+
var MetaXWallet = /** @class */ (function (_super) {
|
|
69
|
+
__extends(MetaXWallet, _super);
|
|
70
|
+
function MetaXWallet() {
|
|
71
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
72
|
+
_this.name = types_1.EnumWalletName.MetaXWallet;
|
|
73
|
+
_this.icon = metax_svg_1.default;
|
|
74
|
+
_this.supportChains = [types_1.EnumChains.ETH, types_1.EnumChains.BSC, types_1.EnumChains.OKEX];
|
|
75
|
+
_this.type = types_1.EnumWalletType.Extension;
|
|
76
|
+
_this.sdk = null;
|
|
77
|
+
return _this;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* connect TrustWallet and get wallet address
|
|
81
|
+
* @param chainId specific chainId,throw error when not match
|
|
82
|
+
*/
|
|
83
|
+
MetaXWallet.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.okexchain) {
|
|
90
|
+
// go2 download page
|
|
91
|
+
throw new Error(types_1.EnumErrors.NoMetaX);
|
|
92
|
+
}
|
|
93
|
+
this.sdk = new web3_1.default(window.okexchain);
|
|
94
|
+
return [4 /*yield*/, this.sdk.eth.requestAccounts()];
|
|
95
|
+
case 1:
|
|
96
|
+
address = (_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 = address;
|
|
104
|
+
this.chainId = currentChainId;
|
|
105
|
+
return [2 /*return*/, address];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
return MetaXWallet;
|
|
111
|
+
}(BaseWallet_1.default));
|
|
112
|
+
exports.default = MetaXWallet;
|
|
@@ -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 OKExWallet
|
|
59
|
+
* @author openocean
|
|
60
|
+
* @date 2021/4/21
|
|
61
|
+
* @desc
|
|
62
|
+
*/
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
var okex_svg_1 = __importDefault(require("../assets/okex.svg"));
|
|
65
|
+
var types_1 = require("../types");
|
|
66
|
+
var BaseWallet_1 = __importDefault(require("./BaseWallet"));
|
|
67
|
+
var web3_1 = __importDefault(require("web3"));
|
|
68
|
+
var OKExWallet = /** @class */ (function (_super) {
|
|
69
|
+
__extends(OKExWallet, _super);
|
|
70
|
+
function OKExWallet() {
|
|
71
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
72
|
+
_this.name = types_1.EnumWalletName.OKExWallet;
|
|
73
|
+
_this.icon = okex_svg_1.default;
|
|
74
|
+
_this.supportChains = [types_1.EnumChains.ETH, types_1.EnumChains.BSC, types_1.EnumChains.OKEX];
|
|
75
|
+
_this.type = types_1.EnumWalletType.Extension;
|
|
76
|
+
_this.sdk = null;
|
|
77
|
+
return _this;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* connect TrustWallet and get wallet address
|
|
81
|
+
* @param chainId specific chainId,throw error when not match
|
|
82
|
+
*/
|
|
83
|
+
OKExWallet.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.okexchain) {
|
|
90
|
+
// go2 download page
|
|
91
|
+
throw new Error(types_1.EnumErrors.NoOKExWallet);
|
|
92
|
+
}
|
|
93
|
+
this.sdk = new web3_1.default(window.okexchain);
|
|
94
|
+
return [4 /*yield*/, this.sdk.eth.requestAccounts()];
|
|
95
|
+
case 1:
|
|
96
|
+
address = (_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 = address;
|
|
104
|
+
this.chainId = currentChainId;
|
|
105
|
+
return [2 /*return*/, address];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
return OKExWallet;
|
|
111
|
+
}(BaseWallet_1.default));
|
|
112
|
+
exports.default = OKExWallet;
|