@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,67 @@
|
|
|
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 Sollet
|
|
23
|
+
* @author openocean
|
|
24
|
+
* @date 2021/4/21
|
|
25
|
+
* @desc
|
|
26
|
+
*/
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
var sollet_svg_1 = __importDefault(require("../assets/sollet.svg"));
|
|
29
|
+
var types_1 = require("../types");
|
|
30
|
+
var BaseWallet_1 = __importDefault(require("./BaseWallet"));
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
var sol_wallet_adapter_1 = __importDefault(require("@project-serum/sol-wallet-adapter"));
|
|
33
|
+
var Sollet = /** @class */ (function (_super) {
|
|
34
|
+
__extends(Sollet, _super);
|
|
35
|
+
function Sollet() {
|
|
36
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
37
|
+
_this.name = types_1.EnumWalletName.Sollet;
|
|
38
|
+
_this.icon = sollet_svg_1.default;
|
|
39
|
+
_this.supportChains = [types_1.EnumChains.Solana];
|
|
40
|
+
_this.type = types_1.EnumWalletType.Extension;
|
|
41
|
+
_this.sdk = null;
|
|
42
|
+
return _this;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* connect metamask and get wallet address
|
|
46
|
+
* @param chainId specific chainId,throw error when not match
|
|
47
|
+
*/
|
|
48
|
+
Sollet.prototype.requestSolanaConnect = function (chainId) {
|
|
49
|
+
var _this = this;
|
|
50
|
+
return new Promise(function (res) {
|
|
51
|
+
if (!window.sollet) {
|
|
52
|
+
throw new Error(types_1.EnumErrors.NoSollet);
|
|
53
|
+
}
|
|
54
|
+
var wallet = new sol_wallet_adapter_1.default(window.sollet);
|
|
55
|
+
_this.sdk = wallet;
|
|
56
|
+
wallet.on('connect', function (publicKey) {
|
|
57
|
+
var address = publicKey.toBase58();
|
|
58
|
+
_this.address = address;
|
|
59
|
+
_this.chainId = ''; // todo sollet chainId
|
|
60
|
+
res(address);
|
|
61
|
+
});
|
|
62
|
+
wallet.connect();
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
return Sollet;
|
|
66
|
+
}(BaseWallet_1.default));
|
|
67
|
+
exports.default = Sollet;
|
|
@@ -0,0 +1,64 @@
|
|
|
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 Sollet
|
|
23
|
+
* @author openocean
|
|
24
|
+
* @date 2021/4/21
|
|
25
|
+
* @desc
|
|
26
|
+
*/
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
var sollet_svg_1 = __importDefault(require("../assets/sollet.svg"));
|
|
29
|
+
var types_1 = require("../types");
|
|
30
|
+
var BaseWallet_1 = __importDefault(require("./BaseWallet"));
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
var sol_wallet_adapter_1 = __importDefault(require("@project-serum/sol-wallet-adapter"));
|
|
33
|
+
var SolletIo = /** @class */ (function (_super) {
|
|
34
|
+
__extends(SolletIo, _super);
|
|
35
|
+
function SolletIo() {
|
|
36
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
37
|
+
_this.name = types_1.EnumWalletName.SolletIo;
|
|
38
|
+
_this.icon = sollet_svg_1.default;
|
|
39
|
+
_this.supportChains = [types_1.EnumChains.Solana];
|
|
40
|
+
_this.type = types_1.EnumWalletType.Web;
|
|
41
|
+
_this.sdk = null;
|
|
42
|
+
return _this;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* connect metamask and get wallet address
|
|
46
|
+
* @param chainId specific chainId,throw error when not match
|
|
47
|
+
*/
|
|
48
|
+
SolletIo.prototype.requestSolanaConnect = function (chainId) {
|
|
49
|
+
var _this = this;
|
|
50
|
+
return new Promise(function (res) {
|
|
51
|
+
var wallet = new sol_wallet_adapter_1.default('https://solflare.com/');
|
|
52
|
+
_this.sdk = wallet;
|
|
53
|
+
wallet.on('connect', function (publicKey) {
|
|
54
|
+
var address = publicKey.toBase58();
|
|
55
|
+
_this.address = address;
|
|
56
|
+
_this.chainId = ''; // todo sollet chainId
|
|
57
|
+
res(address);
|
|
58
|
+
});
|
|
59
|
+
wallet.connect();
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
return SolletIo;
|
|
63
|
+
}(BaseWallet_1.default));
|
|
64
|
+
exports.default = SolletIo;
|
|
@@ -0,0 +1,64 @@
|
|
|
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 TerraStation
|
|
23
|
+
* @author openocean
|
|
24
|
+
* @date 2021/4/21
|
|
25
|
+
* @desc
|
|
26
|
+
*/
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
var terra_svg_1 = __importDefault(require("../assets/terra.svg"));
|
|
29
|
+
var types_1 = require("../types");
|
|
30
|
+
var BaseWallet_1 = __importDefault(require("./BaseWallet"));
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
var terra_js_1 = require("@terra-money/terra.js");
|
|
33
|
+
var TerraStation = /** @class */ (function (_super) {
|
|
34
|
+
__extends(TerraStation, _super);
|
|
35
|
+
function TerraStation() {
|
|
36
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
37
|
+
_this.name = types_1.EnumWalletName.TerraStation;
|
|
38
|
+
_this.icon = terra_svg_1.default;
|
|
39
|
+
_this.supportChains = [types_1.EnumChains.Terra];
|
|
40
|
+
_this.type = types_1.EnumWalletType.Extension;
|
|
41
|
+
_this.sdk = null;
|
|
42
|
+
return _this;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* connect metamask and get wallet address
|
|
46
|
+
* @param chainId specific chainId,throw error when not match
|
|
47
|
+
*/
|
|
48
|
+
TerraStation.prototype.requestTerraConnect = function () {
|
|
49
|
+
var _this = this;
|
|
50
|
+
return new Promise(function (res) {
|
|
51
|
+
var extension = new terra_js_1.Extension('station');
|
|
52
|
+
_this.sdk = extension;
|
|
53
|
+
extension.on("onConnect", function (data) {
|
|
54
|
+
var address = (data || {}).address;
|
|
55
|
+
_this.address = address;
|
|
56
|
+
_this.chainId = ''; // todo sollet chainId
|
|
57
|
+
res(address);
|
|
58
|
+
});
|
|
59
|
+
extension.connect();
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
return TerraStation;
|
|
63
|
+
}(BaseWallet_1.default));
|
|
64
|
+
exports.default = TerraStation;
|
|
@@ -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 TokenPocket
|
|
59
|
+
* @author openocean
|
|
60
|
+
* @date 2021/4/21
|
|
61
|
+
* @desc
|
|
62
|
+
*/
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
var tokenpocket_svg_1 = __importDefault(require("../assets/tokenpocket.svg"));
|
|
65
|
+
var types_1 = require("../types");
|
|
66
|
+
var BaseWallet_1 = __importDefault(require("./BaseWallet"));
|
|
67
|
+
var web3_1 = __importDefault(require("web3"));
|
|
68
|
+
var TokenPocket = /** @class */ (function (_super) {
|
|
69
|
+
__extends(TokenPocket, _super);
|
|
70
|
+
function TokenPocket() {
|
|
71
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
72
|
+
_this.name = types_1.EnumWalletName.TokenPocket;
|
|
73
|
+
_this.icon = tokenpocket_svg_1.default;
|
|
74
|
+
_this.supportChains = [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.Extension;
|
|
76
|
+
_this.sdk = null;
|
|
77
|
+
return _this;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* connect TokenPocket and get wallet address
|
|
81
|
+
* @param chainId specific chainId,throw error when not match
|
|
82
|
+
*/
|
|
83
|
+
TokenPocket.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.isMetaMask)) {
|
|
90
|
+
throw new Error(types_1.EnumErrors.NotMetamask);
|
|
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 TokenPocket;
|
|
110
|
+
}(BaseWallet_1.default));
|
|
111
|
+
exports.default = TokenPocket;
|
|
@@ -0,0 +1,101 @@
|
|
|
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 TronLink
|
|
59
|
+
* @author openocean
|
|
60
|
+
* @date 2021/4/21
|
|
61
|
+
* @desc
|
|
62
|
+
*/
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
var tronlink_svg_1 = __importDefault(require("../assets/tronlink.svg"));
|
|
65
|
+
var types_1 = require("../types");
|
|
66
|
+
var BaseWallet_1 = __importDefault(require("./BaseWallet"));
|
|
67
|
+
var TronLink = /** @class */ (function (_super) {
|
|
68
|
+
__extends(TronLink, _super);
|
|
69
|
+
function TronLink() {
|
|
70
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
71
|
+
_this.name = types_1.EnumWalletName.TronLink;
|
|
72
|
+
_this.icon = tronlink_svg_1.default;
|
|
73
|
+
_this.supportChains = [types_1.EnumChains.TRON];
|
|
74
|
+
_this.type = types_1.EnumWalletType.Extension;
|
|
75
|
+
_this.sdk = null;
|
|
76
|
+
return _this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* connect metamask and get wallet address
|
|
80
|
+
*/
|
|
81
|
+
TronLink.prototype.requestConnect = function () {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
+
var account;
|
|
84
|
+
return __generator(this, function (_a) {
|
|
85
|
+
if (!window.tronWeb) {
|
|
86
|
+
throw new Error(types_1.EnumErrors.NoTronLink);
|
|
87
|
+
}
|
|
88
|
+
account = window.tronWeb.defaultAddress.base58;
|
|
89
|
+
if (!account) {
|
|
90
|
+
throw new Error(types_1.EnumErrors.NoTronLinkAccount);
|
|
91
|
+
}
|
|
92
|
+
this.sdk = window.tronWeb;
|
|
93
|
+
this.address = account;
|
|
94
|
+
this.chainId = ''; // todo tron chainId
|
|
95
|
+
return [2 /*return*/, account];
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
return TronLink;
|
|
100
|
+
}(BaseWallet_1.default));
|
|
101
|
+
exports.default = TronLink;
|
|
@@ -0,0 +1,163 @@
|
|
|
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 __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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
+
function step(op) {
|
|
42
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
+
while (_) try {
|
|
44
|
+
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;
|
|
45
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
+
switch (op[0]) {
|
|
47
|
+
case 0: case 1: t = op; break;
|
|
48
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
+
default:
|
|
52
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
+
if (t[2]) _.ops.pop();
|
|
57
|
+
_.trys.pop(); continue;
|
|
58
|
+
}
|
|
59
|
+
op = body.call(thisArg, _);
|
|
60
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
65
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
66
|
+
};
|
|
67
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
|
+
/**
|
|
69
|
+
* @name TrustWallet
|
|
70
|
+
* @author openocean
|
|
71
|
+
* @date 2021/4/21
|
|
72
|
+
* @desc
|
|
73
|
+
*/
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
var trust_svg_1 = __importDefault(require("../assets/trust.svg"));
|
|
76
|
+
var types_1 = require("../types");
|
|
77
|
+
var BaseWallet_1 = __importDefault(require("./BaseWallet"));
|
|
78
|
+
var web3_1 = __importDefault(require("web3"));
|
|
79
|
+
var web3_provider_1 = __importDefault(require("@walletconnect/web3-provider"));
|
|
80
|
+
var TrustWallet = /** @class */ (function (_super) {
|
|
81
|
+
__extends(TrustWallet, _super);
|
|
82
|
+
function TrustWallet() {
|
|
83
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
84
|
+
_this.name = types_1.EnumWalletName.TrustWallet;
|
|
85
|
+
_this.icon = trust_svg_1.default;
|
|
86
|
+
_this.supportChains = [
|
|
87
|
+
types_1.EnumChains.ETH,
|
|
88
|
+
types_1.EnumChains.BSC,
|
|
89
|
+
types_1.EnumChains.Polygon,
|
|
90
|
+
types_1.EnumChains.OKEX,
|
|
91
|
+
types_1.EnumChains.XDai,
|
|
92
|
+
types_1.EnumChains.HECO,
|
|
93
|
+
types_1.EnumChains.Fantom,
|
|
94
|
+
types_1.EnumChains.Avalanche,
|
|
95
|
+
types_1.EnumChains.Arbitrum,
|
|
96
|
+
types_1.EnumChains.Optimism,
|
|
97
|
+
types_1.EnumChains.Boba,
|
|
98
|
+
types_1.EnumChains.Moonriver,
|
|
99
|
+
types_1.EnumChains.Aurora,
|
|
100
|
+
types_1.EnumChains.Cronos,
|
|
101
|
+
types_1.EnumChains.Harmony
|
|
102
|
+
];
|
|
103
|
+
_this.type = types_1.EnumWalletType.WalletConnect;
|
|
104
|
+
_this.sdk = null;
|
|
105
|
+
return _this;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* connect metamask and get wallet address
|
|
109
|
+
* @param chainId specific chainId,throw error when not match
|
|
110
|
+
* @param config
|
|
111
|
+
*/
|
|
112
|
+
TrustWallet.prototype.requestConnect = function (chainId, config) {
|
|
113
|
+
if (chainId === void 0) { chainId = 1; }
|
|
114
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
+
var provider, currentChainId, address;
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
switch (_a.label) {
|
|
118
|
+
case 0:
|
|
119
|
+
if (!this.infuraId) {
|
|
120
|
+
throw new Error("infuraId not set");
|
|
121
|
+
}
|
|
122
|
+
provider = new web3_provider_1.default(__assign({ infuraId: this.infuraId, chainId: chainId, rpc: {
|
|
123
|
+
69: "https://kovan.optimism.io",
|
|
124
|
+
420: "https://goerli.optimism.io",
|
|
125
|
+
10: "https://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()];
|
|
142
|
+
case 1:
|
|
143
|
+
_a.sent();
|
|
144
|
+
this.sdk = new web3_1.default(provider);
|
|
145
|
+
return [4 /*yield*/, this.sdk.eth.getChainId()];
|
|
146
|
+
case 2:
|
|
147
|
+
currentChainId = _a.sent();
|
|
148
|
+
if (chainId && currentChainId !== chainId) {
|
|
149
|
+
throw new Error(types_1.EnumErrors.ChainIdNotMath);
|
|
150
|
+
}
|
|
151
|
+
return [4 /*yield*/, this.sdk.eth.getAccounts()];
|
|
152
|
+
case 3:
|
|
153
|
+
address = (_a.sent())[0];
|
|
154
|
+
this.address = address;
|
|
155
|
+
this.chainId = currentChainId;
|
|
156
|
+
return [2 /*return*/, address];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
return TrustWallet;
|
|
162
|
+
}(BaseWallet_1.default));
|
|
163
|
+
exports.default = TrustWallet;
|