@ape.swap/bonds-sdk 1.0.470 → 1.0.474
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/dist/components/Modals/BondModal/BondModal.d.ts +6 -2
- package/dist/components/Modals/BondModal/BondModal.js +6 -7
- package/dist/components/YourBondsModal/YourBondsModal.d.ts +6 -2
- package/dist/components/YourBondsModal/YourBondsModal.js +8 -9
- package/dist/config/abi/bondNft.json +424 -0
- package/dist/config/abi/ens-public-resolver.json +816 -0
- package/dist/config/abi/ens-registrar.json +422 -0
- package/dist/config/abi/erc20_bytes32.json +30 -0
- package/dist/config/abi/jungleChef.json +291 -0
- package/dist/config/abi/launchBonds.json +2014 -0
- package/dist/config/abi/lockVeAbond.json +2198 -0
- package/dist/config/abi/migrationBond.json +1639 -0
- package/dist/config/abi/migrationFveAbond.json +160 -0
- package/dist/config/abi/multicallv3.json +92 -0
- package/dist/config/abi/sousChef.json +649 -0
- package/dist/config/abi/types/Banana.d.ts +417 -0
- package/dist/config/abi/types/Banana.js +1 -0
- package/dist/config/abi/types/Bond.d.ts +803 -0
- package/dist/config/abi/types/Bond.js +1 -0
- package/dist/config/abi/types/BondNft.d.ts +603 -0
- package/dist/config/abi/types/BondNft.js +1 -0
- package/dist/config/abi/types/EnsPublicResolver.d.ts +513 -0
- package/dist/config/abi/types/EnsPublicResolver.js +1 -0
- package/dist/config/abi/types/EnsRegistrar.d.ts +274 -0
- package/dist/config/abi/types/EnsRegistrar.js +1 -0
- package/dist/config/abi/types/Erc20.d.ts +168 -0
- package/dist/config/abi/types/Erc20.js +1 -0
- package/dist/config/abi/types/Erc20_bytes32.d.ts +50 -0
- package/dist/config/abi/types/Erc20_bytes32.js +1 -0
- package/dist/config/abi/types/JungleChef.d.ts +260 -0
- package/dist/config/abi/types/JungleChef.js +1 -0
- package/dist/config/abi/types/LaunchBonds.d.ts +1362 -0
- package/dist/config/abi/types/LaunchBonds.js +1 -0
- package/dist/config/abi/types/LensContract.d.ts +295 -0
- package/dist/config/abi/types/LensContract.js +1 -0
- package/dist/config/abi/types/LockVeAbond.d.ts +1279 -0
- package/dist/config/abi/types/LockVeAbond.js +1 -0
- package/dist/config/abi/types/MigrationBond.d.ts +1136 -0
- package/dist/config/abi/types/MigrationBond.js +1 -0
- package/dist/config/abi/types/MigrationFveAbond.d.ts +290 -0
- package/dist/config/abi/types/MigrationFveAbond.js +1 -0
- package/dist/config/abi/types/MiniComplexRewarder.d.ts +469 -0
- package/dist/config/abi/types/MiniComplexRewarder.js +1 -0
- package/dist/config/abi/types/Multicallv2.d.ts +150 -0
- package/dist/config/abi/types/Multicallv2.js +1 -0
- package/dist/config/abi/types/Multicallv3.d.ts +98 -0
- package/dist/config/abi/types/Multicallv3.js +1 -0
- package/dist/config/abi/types/NonFungibleApes.d.ts +532 -0
- package/dist/config/abi/types/NonFungibleApes.js +1 -0
- package/dist/config/abi/types/NonFungibleBananas.d.ts +505 -0
- package/dist/config/abi/types/NonFungibleBananas.js +1 -0
- package/dist/config/abi/types/PriceGetter.d.ts +713 -0
- package/dist/config/abi/types/PriceGetter.js +1 -0
- package/dist/config/abi/types/PriceGetterLinea.d.ts +789 -0
- package/dist/config/abi/types/PriceGetterLinea.js +1 -0
- package/dist/config/abi/types/PriceGetterV2.d.ts +729 -0
- package/dist/config/abi/types/PriceGetterV2.js +1 -0
- package/dist/config/abi/types/SousChef.d.ts +579 -0
- package/dist/config/abi/types/SousChef.js +1 -0
- package/dist/config/abi/types/Treasury.d.ts +277 -0
- package/dist/config/abi/types/Treasury.js +1 -0
- package/dist/config/abi/types/Weth.d.ts +221 -0
- package/dist/config/abi/types/Weth.js +1 -0
- package/dist/config/abi/types/Zap.d.ts +528 -0
- package/dist/config/abi/types/Zap.js +1 -0
- package/dist/config/abi/types/common.d.ts +22 -0
- package/dist/config/abi/types/common.js +1 -0
- package/dist/config/abi/types/factories/Banana__factory.d.ts +475 -0
- package/dist/config/abi/types/factories/Banana__factory.js +628 -0
- package/dist/config/abi/types/factories/BondNft__factory.d.ts +723 -0
- package/dist/config/abi/types/factories/BondNft__factory.js +951 -0
- package/dist/config/abi/types/factories/Bond__factory.d.ts +799 -0
- package/dist/config/abi/types/factories/Bond__factory.js +1042 -0
- package/dist/config/abi/types/factories/EnsPublicResolver__factory.d.ts +649 -0
- package/dist/config/abi/types/factories/EnsPublicResolver__factory.js +833 -0
- package/dist/config/abi/types/factories/EnsRegistrar__factory.d.ts +338 -0
- package/dist/config/abi/types/factories/EnsRegistrar__factory.js +439 -0
- package/dist/config/abi/types/factories/Erc20__factory.d.ts +175 -0
- package/dist/config/abi/types/factories/Erc20__factory.js +239 -0
- package/dist/config/abi/types/factories/Erc20_bytes32__factory.d.ts +30 -0
- package/dist/config/abi/types/factories/Erc20_bytes32__factory.js +47 -0
- package/dist/config/abi/types/factories/JungleChef__factory.d.ts +247 -0
- package/dist/config/abi/types/factories/JungleChef__factory.js +326 -0
- package/dist/config/abi/types/factories/LaunchBonds__factory.d.ts +1560 -0
- package/dist/config/abi/types/factories/LaunchBonds__factory.js +2031 -0
- package/dist/config/abi/types/factories/LensContract__factory.d.ts +254 -0
- package/dist/config/abi/types/factories/LensContract__factory.js +338 -0
- package/dist/config/abi/types/factories/LockVeAbond__factory.d.ts +1698 -0
- package/dist/config/abi/types/factories/LockVeAbond__factory.js +2215 -0
- package/dist/config/abi/types/factories/MigrationBond__factory.d.ts +1268 -0
- package/dist/config/abi/types/factories/MigrationBond__factory.js +1656 -0
- package/dist/config/abi/types/factories/MigrationFveAbond__factory.d.ts +262 -0
- package/dist/config/abi/types/factories/MigrationFveAbond__factory.js +346 -0
- package/dist/config/abi/types/factories/MiniComplexRewarder__factory.d.ts +448 -0
- package/dist/config/abi/types/factories/MiniComplexRewarder__factory.js +586 -0
- package/dist/config/abi/types/factories/Multicallv2__factory.d.ts +115 -0
- package/dist/config/abi/types/factories/Multicallv2__factory.js +160 -0
- package/dist/config/abi/types/factories/Multicallv3__factory.d.ts +76 -0
- package/dist/config/abi/types/factories/Multicallv3__factory.js +109 -0
- package/dist/config/abi/types/factories/NonFungibleApes__factory.d.ts +617 -0
- package/dist/config/abi/types/factories/NonFungibleApes__factory.js +810 -0
- package/dist/config/abi/types/factories/NonFungibleBananas__factory.d.ts +576 -0
- package/dist/config/abi/types/factories/NonFungibleBananas__factory.js +756 -0
- package/dist/config/abi/types/factories/PriceGetterLinea__factory.d.ts +1105 -0
- package/dist/config/abi/types/factories/PriceGetterLinea__factory.js +1465 -0
- package/dist/config/abi/types/factories/PriceGetterV2__factory.d.ts +1027 -0
- package/dist/config/abi/types/factories/PriceGetterV2__factory.js +1364 -0
- package/dist/config/abi/types/factories/PriceGetter__factory.d.ts +999 -0
- package/dist/config/abi/types/factories/PriceGetter__factory.js +1326 -0
- package/dist/config/abi/types/factories/SousChef__factory.d.ts +511 -0
- package/dist/config/abi/types/factories/SousChef__factory.js +666 -0
- package/dist/config/abi/types/factories/Treasury__factory.d.ts +235 -0
- package/dist/config/abi/types/factories/Treasury__factory.js +309 -0
- package/dist/config/abi/types/factories/Weth__factory.d.ts +220 -0
- package/dist/config/abi/types/factories/Weth__factory.js +296 -0
- package/dist/config/abi/types/factories/Zap__factory.d.ts +695 -0
- package/dist/config/abi/types/factories/Zap__factory.js +889 -0
- package/dist/config/abi/types/factories/index.d.ts +25 -0
- package/dist/config/abi/types/factories/index.js +28 -0
- package/dist/config/abi/types/index.d.ts +51 -0
- package/dist/config/abi/types/index.js +26 -0
- package/dist/config/abi/weth.json +279 -0
- package/dist/hooks/useClaimBill.d.ts +4 -0
- package/dist/hooks/useClaimBill.js +59 -0
- package/dist/hooks/useContract.d.ts +25 -0
- package/dist/hooks/useContract.js +107 -0
- package/dist/pages/Bonds/Bonds.d.ts +6 -1
- package/dist/pages/Bonds/Bonds.js +12 -13
- package/dist/pages/YourBonds/YourBonds.js +37 -10
- package/dist/utils/index.d.ts +16 -0
- package/dist/utils/index.js +127 -0
- package/dist/utils/track.d.ts +7 -0
- package/dist/utils/track.js +17 -0
- package/package.json +1 -1
|
@@ -60,7 +60,6 @@ import { useCallback, useEffect, useState } from 'react';
|
|
|
60
60
|
import { Flex, ThemeUIProvider } from 'theme-ui';
|
|
61
61
|
import axios from 'axios';
|
|
62
62
|
import { ethers } from 'ethers';
|
|
63
|
-
import { useWeb3React } from '@web3-react/core';
|
|
64
63
|
import { useSearchParams, useNavigate } from 'react-router-dom';
|
|
65
64
|
import getTimePeriods from '../../utils/getTimePeriods';
|
|
66
65
|
import { defaultTheme } from '../../theme';
|
|
@@ -72,9 +71,9 @@ import '../../scss/Bonds.scss';
|
|
|
72
71
|
import BondRowHeader from '../../components/BondRows/BondRowHeader';
|
|
73
72
|
import BondRowsByChain from '../../components/BondRows/BondRowsByChain';
|
|
74
73
|
var Bonds = function (_a) {
|
|
75
|
-
var
|
|
76
|
-
|
|
77
|
-
var
|
|
74
|
+
var account = _a.account, accountChainId = _a.accountChainId, isActive = _a.isActive;
|
|
75
|
+
//const { account, isActive } = useWeb3React();
|
|
76
|
+
var _b = useSearchParams(), searchParams = _b[0], setSearchParams = _b[1];
|
|
78
77
|
var navigate = useNavigate();
|
|
79
78
|
var USDT_ABI = [
|
|
80
79
|
// The ERC-20 approve function ABI
|
|
@@ -116,8 +115,8 @@ var Bonds = function (_a) {
|
|
|
116
115
|
});
|
|
117
116
|
}); };
|
|
118
117
|
// Fetch data
|
|
119
|
-
var
|
|
120
|
-
var
|
|
118
|
+
var _c = useState([]), bondData = _c[0], setBondData = _c[1];
|
|
119
|
+
var _d = useState([]), hotBonds = _d[0], setHotBonds = _d[1];
|
|
121
120
|
var isSoldOut = useCallback(function (bond) {
|
|
122
121
|
var _a, _b;
|
|
123
122
|
var thresholdToHide = new BigNumber(100).div((_a = bond.payoutTokenPrice) !== null && _a !== void 0 ? _a : 0);
|
|
@@ -160,8 +159,8 @@ var Bonds = function (_a) {
|
|
|
160
159
|
return b.discount - a.discount;
|
|
161
160
|
}
|
|
162
161
|
});
|
|
163
|
-
var
|
|
164
|
-
var
|
|
162
|
+
var _e = useState(null), sortConfig = _e[0], setSortConfig = _e[1];
|
|
163
|
+
var _f = useState(sortedHotBonds), sortedBonds = _f[0], setSortedBonds = _f[1];
|
|
165
164
|
var handleSort = function (key) {
|
|
166
165
|
var direction = 'asc';
|
|
167
166
|
if ((sortConfig === null || sortConfig === void 0 ? void 0 : sortConfig.key) === key && (sortConfig === null || sortConfig === void 0 ? void 0 : sortConfig.direction) === 'asc') {
|
|
@@ -203,8 +202,8 @@ var Bonds = function (_a) {
|
|
|
203
202
|
setSortedBonds(sorted);
|
|
204
203
|
}, [sortConfig, bondData]);
|
|
205
204
|
// Modal
|
|
206
|
-
var
|
|
207
|
-
var
|
|
205
|
+
var _g = useState(false), isModalOpen = _g[0], setIsModalOpen = _g[1];
|
|
206
|
+
var _h = useState(null), selectedBond = _h[0], setSelectedBond = _h[1];
|
|
208
207
|
var rowClick = function (bond) {
|
|
209
208
|
setSelectedBond(bond);
|
|
210
209
|
setIsModalOpen(true);
|
|
@@ -245,8 +244,8 @@ var Bonds = function (_a) {
|
|
|
245
244
|
return parseFloat((((discount * 365) / vestingDays).toFixed(2)));
|
|
246
245
|
};
|
|
247
246
|
// Search logic
|
|
248
|
-
var
|
|
249
|
-
var
|
|
247
|
+
var _j = useState(''), inputValue = _j[0], setInputValue = _j[1];
|
|
248
|
+
var _k = useState(sortedBonds), filteredBonds = _k[0], setFilteredBonds = _k[1];
|
|
250
249
|
useEffect(function () {
|
|
251
250
|
if (inputValue === '') {
|
|
252
251
|
setFilteredBonds(sortedBonds);
|
|
@@ -261,7 +260,7 @@ var Bonds = function (_a) {
|
|
|
261
260
|
setInputValue(event.target.value);
|
|
262
261
|
};
|
|
263
262
|
// Page render logic
|
|
264
|
-
var
|
|
263
|
+
var _l = useState(false), bondsRendered = _l[0], setBondsRendered = _l[1];
|
|
265
264
|
useEffect(function () {
|
|
266
265
|
if (filteredBonds.length > 0) {
|
|
267
266
|
setBondsRendered(true);
|
|
@@ -76,10 +76,36 @@ import { getPendingVesting } from '../../hooks/usePendingVesting';
|
|
|
76
76
|
import axios from 'axios';
|
|
77
77
|
import { fetchUserOwnedBillsDataAsync } from './fetchBillsUser';
|
|
78
78
|
import { Input } from '../../components/uikit-sdk/Input';
|
|
79
|
+
import useClaimBill from '../../hooks/useClaimBill';
|
|
79
80
|
var YourBonds = function (_a) {
|
|
80
81
|
var account = _a.account, accountChainId = _a.accountChainId, isActive = _a.isActive;
|
|
82
|
+
//const toastError = useToastError()
|
|
83
|
+
// const { onClaimBill } = useClaimBill(billAddress, billIds)
|
|
84
|
+
var _b = useState(false), pendingTrx = _b[0], setPendingTrx = _b[1];
|
|
85
|
+
var handleClaim = function (billAddress, billIds, event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
86
|
+
var onClaimBill;
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0:
|
|
90
|
+
event === null || event === void 0 ? void 0 : event.stopPropagation();
|
|
91
|
+
if (!accountChainId || !account)
|
|
92
|
+
return [2 /*return*/];
|
|
93
|
+
onClaimBill = useClaimBill(billAddress, billIds).onClaimBill;
|
|
94
|
+
setPendingTrx(true);
|
|
95
|
+
return [4 /*yield*/, onClaimBill().catch(function (e) {
|
|
96
|
+
console.error(e);
|
|
97
|
+
//toastError(e);
|
|
98
|
+
setPendingTrx(false);
|
|
99
|
+
})];
|
|
100
|
+
case 1:
|
|
101
|
+
_a.sent();
|
|
102
|
+
setPendingTrx(false);
|
|
103
|
+
return [2 /*return*/];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}); };
|
|
81
107
|
// const { account, isActive } = useWeb3React();
|
|
82
|
-
var
|
|
108
|
+
var _c = useSearchParams(), searchParams = _c[0], setSearchParams = _c[1];
|
|
83
109
|
var navigate = useNavigate();
|
|
84
110
|
var USDT_ABI = [
|
|
85
111
|
// The ERC-20 approve function ABI
|
|
@@ -121,8 +147,8 @@ var YourBonds = function (_a) {
|
|
|
121
147
|
});
|
|
122
148
|
}); };
|
|
123
149
|
// Fetch data
|
|
124
|
-
var
|
|
125
|
-
var
|
|
150
|
+
var _d = useState([]), bondData = _d[0], setBondData = _d[1];
|
|
151
|
+
var _e = useState([]), mappedUserBills = _e[0], setMappedUserBills = _e[1];
|
|
126
152
|
useEffect(function () {
|
|
127
153
|
axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
|
|
128
154
|
var bonds = response.data.bonds;
|
|
@@ -158,8 +184,8 @@ var YourBonds = function (_a) {
|
|
|
158
184
|
}); };
|
|
159
185
|
fetchData();
|
|
160
186
|
}, [account]);
|
|
161
|
-
var
|
|
162
|
-
var
|
|
187
|
+
var _f = useState(null), sortConfig = _f[0], setSortConfig = _f[1];
|
|
188
|
+
var _g = useState(mappedUserBills), sortedBonds = _g[0], setSortedBonds = _g[1];
|
|
163
189
|
var handleSort = function (key) {
|
|
164
190
|
var direction = 'asc';
|
|
165
191
|
if ((sortConfig === null || sortConfig === void 0 ? void 0 : sortConfig.key) === key && (sortConfig === null || sortConfig === void 0 ? void 0 : sortConfig.direction) === 'asc') {
|
|
@@ -240,16 +266,16 @@ var YourBonds = function (_a) {
|
|
|
240
266
|
return getFirstNonZeroDigits(parseFloat((_a = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _a !== void 0 ? _a : '0'));
|
|
241
267
|
};
|
|
242
268
|
// Modal
|
|
243
|
-
var
|
|
244
|
-
var
|
|
269
|
+
var _h = useState(false), isModalOpen = _h[0], setIsModalOpen = _h[1];
|
|
270
|
+
var _j = useState(null), selectedBill = _j[0], setSelectedBill = _j[1];
|
|
245
271
|
var rowClick = function (bill) {
|
|
246
272
|
setSelectedBill(bill);
|
|
247
273
|
setIsModalOpen(true);
|
|
248
274
|
navigate("/YourBonds/?bondAddress=".concat(bill.address, "&bondChain=").concat(bill.bond.chainId), { replace: true });
|
|
249
275
|
};
|
|
250
276
|
// Search logic
|
|
251
|
-
var
|
|
252
|
-
var
|
|
277
|
+
var _k = useState(''), inputValue = _k[0], setInputValue = _k[1];
|
|
278
|
+
var _l = useState(sortedBonds), filteredBonds = _l[0], setFilteredBonds = _l[1];
|
|
253
279
|
useEffect(function () {
|
|
254
280
|
if (inputValue === '') {
|
|
255
281
|
setFilteredBonds(sortedBonds);
|
|
@@ -264,7 +290,7 @@ var YourBonds = function (_a) {
|
|
|
264
290
|
setInputValue(event.target.value);
|
|
265
291
|
};
|
|
266
292
|
// Page render logic
|
|
267
|
-
var
|
|
293
|
+
var _m = useState(false), bondsRendered = _m[0], setBondsRendered = _m[1];
|
|
268
294
|
useEffect(function () {
|
|
269
295
|
if (filteredBonds.length > 0) {
|
|
270
296
|
setBondsRendered(true);
|
|
@@ -281,6 +307,7 @@ var YourBonds = function (_a) {
|
|
|
281
307
|
return (_jsxs(Flex, __assign({ className: "container bondrow-container", onClick: function () { return rowClick(bill); } }, { children: [_jsx(Flex, __assign({ className: "column column-tokens" }, { children: _jsx(Flex, __assign({ className: "column column-tokeninfoname" }, { children: _jsx(TokenInfoAndName, { bill: bill.bond, vestEnds: "Ends in ".concat(getPendingVesting(bill.lastBlockTimestamp, bill.vesting)) }) })) })), _jsxs(Flex, __assign({ className: "column column-bondinfo" }, { children: [_jsxs(Flex, __assign({ className: "column column-claimable" }, { children: [formatNumberSI(parseFloat(claimable(bill).toFixed(3)), 0), _jsx(Text, __assign({ sx: { opacity: '0.6', fontSize: '12px', paddingLeft: '5px' } }, { children: "($".concat((claimable(bill) * ((_a = parseFloat(earnTokenPrice(bill.bond))) !== null && _a !== void 0 ? _a : 0)).toFixed(2), ")") }))] })), _jsxs(Flex, __assign({ className: "column column-pending" }, { children: [formatNumberSI(parseFloat(totalPending(bill).toFixed(0)), 0), _jsx(Text, __assign({ sx: { opacity: '0.6', fontSize: '12px', paddingLeft: '5px' } }, { children: "($".concat((totalPending(bill) * ((_b = parseFloat(earnTokenPrice(bill.bond))) !== null && _b !== void 0 ? _b : 0)).toFixed(2), ")") }))] })), _jsx(Flex, __assign({ className: "column column-terms" }, { children: "".concat(vestingTimeRemaining(bill).days, "d, ").concat(vestingTimeRemaining(bill).hours, "h, ").concat(vestingTimeRemaining(bill).minutes, "m") })), _jsx(Flex, __assign({ className: "column column-claimall" }, { children: _jsx(Button, __assign({ disabled: !account && (claimableNumber(bill) === 0), onClick: function (event) {
|
|
282
308
|
event.stopPropagation();
|
|
283
309
|
// Add your claim logic here
|
|
310
|
+
handleClaim(bill.bond.billAddress, [bill.id], event);
|
|
284
311
|
}, sx: {
|
|
285
312
|
height: ['36px', '36px', '36px', '26px'],
|
|
286
313
|
lineHeight: '12px',
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Contract } from '@ethersproject/contracts';
|
|
2
|
+
import type { JsonRpcProvider } from '@ethersproject/providers';
|
|
3
|
+
import { ChainId } from '../config/constants/chains';
|
|
4
|
+
export declare function isAddress(value: any): string | false;
|
|
5
|
+
export declare function getContract(address: string, ABI: any, provider: JsonRpcProvider, account?: string): Contract;
|
|
6
|
+
export declare function isSupportedChain(chainId: number | null | undefined): chainId is ChainId;
|
|
7
|
+
export declare function getEtherscanLink(data: string | number, type: 'transaction' | 'token' | 'address' | 'block' | 'countdown', chainId: ChainId): string;
|
|
8
|
+
/**
|
|
9
|
+
* Prompt the user to add a custom token to metamask
|
|
10
|
+
* @param tokenAddress
|
|
11
|
+
* @param tokenSymbol
|
|
12
|
+
* @param tokenDecimals
|
|
13
|
+
* @param tokenImage
|
|
14
|
+
* @returns {boolean} true if the token has been added, false otherwise
|
|
15
|
+
*/
|
|
16
|
+
export declare const registerToken: (tokenAddress: string, tokenSymbol: string | undefined, tokenDecimals: number, tokenImage: string | undefined) => Promise<any>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
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;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { getAddress } from '@ethersproject/address';
|
|
38
|
+
import { AddressZero } from '@ethersproject/constants';
|
|
39
|
+
import { Contract } from '@ethersproject/contracts';
|
|
40
|
+
import { BLOCK_EXPLORER, ChainId } from '../config/constants/chains';
|
|
41
|
+
// returns the checksummed address if the address is valid, otherwise returns false
|
|
42
|
+
export function isAddress(value) {
|
|
43
|
+
try {
|
|
44
|
+
// Alphabetical letters must be made lowercase for getAddress to work.
|
|
45
|
+
// See documentation here: https://docs.ethers.io/v5/api/utils/address/
|
|
46
|
+
return getAddress(value.toLowerCase());
|
|
47
|
+
}
|
|
48
|
+
catch (_a) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// account is not optional
|
|
53
|
+
function getSigner(provider, account) {
|
|
54
|
+
return provider.getSigner(account).connectUnchecked();
|
|
55
|
+
}
|
|
56
|
+
// account is optional
|
|
57
|
+
function getProviderOrSigner(provider, account) {
|
|
58
|
+
return account ? getSigner(provider, account) : provider;
|
|
59
|
+
}
|
|
60
|
+
// account is optional
|
|
61
|
+
export function getContract(address, ABI, provider, account) {
|
|
62
|
+
if (!isAddress(address) || address === AddressZero) {
|
|
63
|
+
throw Error("Invalid 'address' parameter '".concat(address, "'."));
|
|
64
|
+
}
|
|
65
|
+
return new Contract(address, ABI, getProviderOrSigner(provider, account));
|
|
66
|
+
}
|
|
67
|
+
export function isSupportedChain(chainId) {
|
|
68
|
+
return !!chainId && !!ChainId[chainId];
|
|
69
|
+
}
|
|
70
|
+
export function getEtherscanLink(data, type, chainId) {
|
|
71
|
+
switch (type) {
|
|
72
|
+
case 'transaction': {
|
|
73
|
+
return "".concat(BLOCK_EXPLORER[chainId], "/tx/").concat(data);
|
|
74
|
+
}
|
|
75
|
+
case 'token': {
|
|
76
|
+
return "".concat(BLOCK_EXPLORER[chainId], "/token/").concat(data);
|
|
77
|
+
}
|
|
78
|
+
case 'block': {
|
|
79
|
+
return "".concat(BLOCK_EXPLORER[chainId], "/block/").concat(data);
|
|
80
|
+
}
|
|
81
|
+
case 'countdown': {
|
|
82
|
+
return "".concat(BLOCK_EXPLORER[chainId], "/block/countdown/").concat(data);
|
|
83
|
+
}
|
|
84
|
+
default: {
|
|
85
|
+
return "".concat(BLOCK_EXPLORER[chainId], "/address/").concat(data);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Prompt the user to add a custom token to metamask
|
|
91
|
+
* @param tokenAddress
|
|
92
|
+
* @param tokenSymbol
|
|
93
|
+
* @param tokenDecimals
|
|
94
|
+
* @param tokenImage
|
|
95
|
+
* @returns {boolean} true if the token has been added, false otherwise
|
|
96
|
+
*/
|
|
97
|
+
export var registerToken = function (tokenAddress, tokenSymbol, tokenDecimals, tokenImage) { return __awaiter(void 0, void 0, void 0, function () {
|
|
98
|
+
var tokenAdded, _a;
|
|
99
|
+
var _b;
|
|
100
|
+
return __generator(this, function (_c) {
|
|
101
|
+
switch (_c.label) {
|
|
102
|
+
case 0:
|
|
103
|
+
if (!((_b = window === null || window === void 0 ? void 0 : window.ethereum) === null || _b === void 0 ? void 0 : _b.request)) return [3 /*break*/, 2];
|
|
104
|
+
return [4 /*yield*/, window.ethereum.request({
|
|
105
|
+
method: 'wallet_watchAsset',
|
|
106
|
+
params: {
|
|
107
|
+
type: 'ERC20',
|
|
108
|
+
options: {
|
|
109
|
+
address: tokenAddress,
|
|
110
|
+
symbol: tokenSymbol,
|
|
111
|
+
decimals: tokenDecimals,
|
|
112
|
+
image: tokenImage,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
})];
|
|
116
|
+
case 1:
|
|
117
|
+
_a = _c.sent();
|
|
118
|
+
return [3 /*break*/, 3];
|
|
119
|
+
case 2:
|
|
120
|
+
_a = null;
|
|
121
|
+
_c.label = 3;
|
|
122
|
+
case 3:
|
|
123
|
+
tokenAdded = _a;
|
|
124
|
+
return [2 /*return*/, tokenAdded];
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}); };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
function track(_a) {
|
|
13
|
+
var _b;
|
|
14
|
+
var event = _a.event, chain = _a.chain, data = _a.data, value = _a.value;
|
|
15
|
+
(_b = window.dataLayer) === null || _b === void 0 ? void 0 : _b.push(__assign({ event: event, value: value, chain: chain }, data));
|
|
16
|
+
}
|
|
17
|
+
export default track;
|