@ape.swap/bonds-sdk 1.0.293 → 1.0.294
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.
|
@@ -58,9 +58,8 @@ import { defaultTheme } from '../../theme';
|
|
|
58
58
|
import '../../scss/YourBonds.scss';
|
|
59
59
|
import { BigNumber } from 'bignumber.js';
|
|
60
60
|
import { BillVersion, ChainId } from '../../enum/apeswaplists';
|
|
61
|
-
import { formatValue } from '../../utils/formatNumbers';
|
|
62
61
|
import { Text, Button } from '../uikit-sdk';
|
|
63
|
-
import {
|
|
62
|
+
import { MAINNET_CHAINS } from '../../config/constants/chains';
|
|
64
63
|
import TokenInfoAndName from '../TokenInfoAndName';
|
|
65
64
|
import { ACF_TO_ABOND } from '../../config/constants/addresses';
|
|
66
65
|
import multicall from '../../utils/multicall';
|
|
@@ -68,6 +67,7 @@ import billAbi from '../../config/abi/bond.json';
|
|
|
68
67
|
import { getBalanceNumber } from '../../utils/getBalanceNumber';
|
|
69
68
|
import { getFirstNonZeroDigits } from '../../utils/roundNumber';
|
|
70
69
|
import { formatNumberSI } from '../../utils/formatNumber';
|
|
70
|
+
import useCurrentTime from '../../utils/useTimer';
|
|
71
71
|
var YourBonds = function (_a) {
|
|
72
72
|
var connectionString = _a.connectionString;
|
|
73
73
|
var _b = useWeb3React(), account = _b.account, isActive = _b.isActive;
|
|
@@ -117,6 +117,10 @@ var YourBonds = function (_a) {
|
|
|
117
117
|
var vestingTime = function (vestingTerm) {
|
|
118
118
|
return getTimePeriods(vestingTerm !== null && vestingTerm !== void 0 ? vestingTerm : 0, true);
|
|
119
119
|
};
|
|
120
|
+
var currentTime = useCurrentTime() / 1000;
|
|
121
|
+
var vestingTimeRemaining = function (userBill) {
|
|
122
|
+
return getTimePeriods(parseInt(userBill.lastBlockTimestamp) + parseInt(userBill.vesting) - currentTime, true);
|
|
123
|
+
};
|
|
120
124
|
useEffect(function () {
|
|
121
125
|
axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
|
|
122
126
|
var bonds = response.data.bonds.filter(function (bond) { return !isSoldOut(bond); });
|
|
@@ -165,30 +169,6 @@ var YourBonds = function (_a) {
|
|
|
165
169
|
setIsModalOpen(true);
|
|
166
170
|
navigate("/?bondAddress=".concat(bond.billAddress, "&bondChain=").concat(bond.chainId), { replace: true });
|
|
167
171
|
};
|
|
168
|
-
var getDiscountColor = function (discount) {
|
|
169
|
-
return discount < 0 ? 'discount-negative' : 'discount-positive';
|
|
170
|
-
};
|
|
171
|
-
var remainingPercentage = function (bond) {
|
|
172
|
-
var _a, _b;
|
|
173
|
-
var totalMaxPayout = new BigNumber((_a = bond.maxTotalPayout) !== null && _a !== void 0 ? _a : '0').div(new BigNumber(10).pow(bond.payoutTokenDecimals));
|
|
174
|
-
var remainingTokens = new BigNumber((_b = bond.tokensRemaining) !== null && _b !== void 0 ? _b : '0');
|
|
175
|
-
return remainingTokens.div(totalMaxPayout).times(100).toNumber();
|
|
176
|
-
};
|
|
177
|
-
var remainingTokensFormat = function (bond) {
|
|
178
|
-
var _a;
|
|
179
|
-
return formatValue({ num: new BigNumber((_a = bond.tokensRemaining) !== null && _a !== void 0 ? _a : '0') });
|
|
180
|
-
};
|
|
181
|
-
var remainingTokensUsd = function (bond) {
|
|
182
|
-
var _a, _b;
|
|
183
|
-
var tokens = new BigNumber((_a = bond.tokensRemaining) !== null && _a !== void 0 ? _a : '0');
|
|
184
|
-
return tokens.times((_b = bond.payoutTokenPrice) !== null && _b !== void 0 ? _b : 0);
|
|
185
|
-
};
|
|
186
|
-
var getBillContractURL = function (bond) {
|
|
187
|
-
var _a;
|
|
188
|
-
var selectedChain = (_a = bond.chainId) !== null && _a !== void 0 ? _a : ChainId.BSC;
|
|
189
|
-
var explorerLink = BLOCK_EXPLORER[selectedChain];
|
|
190
|
-
return "".concat(explorerLink, "/address/").concat(bond === null || bond === void 0 ? void 0 : bond.billAddress);
|
|
191
|
-
};
|
|
192
172
|
// const usePollUserBills = () => {
|
|
193
173
|
// const { slowRefresh } = useRefresh()
|
|
194
174
|
// // const dispatch = useAppDispatch()
|
|
@@ -334,13 +314,13 @@ var YourBonds = function (_a) {
|
|
|
334
314
|
});
|
|
335
315
|
}); };
|
|
336
316
|
var chainId = useWeb3React().chainId;
|
|
337
|
-
var totalPending = function (
|
|
317
|
+
var totalPending = function (userBill) {
|
|
338
318
|
var _a, _b, _c, _d;
|
|
339
|
-
return getBalanceNumber(new BigNumber((_a =
|
|
319
|
+
return getBalanceNumber(new BigNumber((_a = userBill === null || userBill === void 0 ? void 0 : userBill.totalPayout) !== null && _a !== void 0 ? _a : 0), (_d = (_c = (_b = userBill.bond.earnToken) === null || _b === void 0 ? void 0 : _b.decimals) === null || _c === void 0 ? void 0 : _c[chainId]) !== null && _d !== void 0 ? _d : 18);
|
|
340
320
|
};
|
|
341
|
-
var claimable = function (
|
|
321
|
+
var claimable = function (userBill) {
|
|
342
322
|
var _a, _b, _c;
|
|
343
|
-
return getBalanceNumber(new BigNumber(
|
|
323
|
+
return getBalanceNumber(new BigNumber(userBill.pendingRewards), (_c = (_b = (_a = userBill.bond.earnToken) === null || _a === void 0 ? void 0 : _a.decimals) === null || _b === void 0 ? void 0 : _b[chainId]) !== null && _c !== void 0 ? _c : 18);
|
|
344
324
|
};
|
|
345
325
|
var earnTokenPrice = function (bond) {
|
|
346
326
|
var _a;
|
|
@@ -355,7 +335,7 @@ var YourBonds = function (_a) {
|
|
|
355
335
|
} }, { children: "Claim All" })) }))] }))] })), userOwnedBillsData.flat().map(function (data) {
|
|
356
336
|
return data.userOwnedBills.map(function (bill) {
|
|
357
337
|
var _a, _b;
|
|
358
|
-
return (_jsxs(Flex, __assign({ className: "container bondrow-container", onClick: function () { return rowClick(bill.bond); } }, { children: [_jsxs(Flex, __assign({ className: "column column-tokens" }, { children: [_jsx(Flex, __assign({ className: "column column-tokeninfoname" }, { children: _jsx(TokenInfoAndName, { bond: bill.bond }) })), _jsx(Flex, { className: "column column-tokenicons" })] })), _jsxs(Flex, __assign({ className: "column column-bondinfo" }, { children: [_jsxs(Flex, __assign({ className: "column column-claimable" }, { children: [formatNumberSI(parseFloat(claimable(bill).toFixed(3)), 0), "($".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), "($".concat((totalPending(bill) * ((_b = parseFloat(earnTokenPrice(bill.bond))) !== null && _b !== void 0 ? _b : 0)).toFixed(2), ")")] })), _jsx(Flex, __assign({ className: "column column-term" }, { children: "".concat(
|
|
338
|
+
return (_jsxs(Flex, __assign({ className: "container bondrow-container", onClick: function () { return rowClick(bill.bond); } }, { children: [_jsxs(Flex, __assign({ className: "column column-tokens" }, { children: [_jsx(Flex, __assign({ className: "column column-tokeninfoname" }, { children: _jsx(TokenInfoAndName, { bond: bill.bond }) })), _jsx(Flex, { className: "column column-tokenicons" })] })), _jsxs(Flex, __assign({ className: "column column-bondinfo" }, { children: [_jsxs(Flex, __assign({ className: "column column-claimable" }, { children: [formatNumberSI(parseFloat(claimable(bill).toFixed(3)), 0), "($".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), "($".concat((totalPending(bill) * ((_b = parseFloat(earnTokenPrice(bill.bond))) !== null && _b !== void 0 ? _b : 0)).toFixed(2), ")")] })), _jsx(Flex, __assign({ className: "column column-term" }, { 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(Flex, __assign({ className: "column-claimall button" }, { children: _jsx(Button, __assign({ disabled: !account, sx: {
|
|
359
339
|
height: ['36px', '36px', '36px', '26px'],
|
|
360
340
|
lineHeight: '12px',
|
|
361
341
|
fontSize: '14px',
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
export var useCurrentTime = function () {
|
|
3
|
+
var _a = useState(new Date().getTime()), currentMillis = _a[0], setCurrentMillis = _a[1];
|
|
4
|
+
useEffect(function () {
|
|
5
|
+
var tick = function () {
|
|
6
|
+
setCurrentMillis(function (prevMillis) { return prevMillis + 1000; });
|
|
7
|
+
};
|
|
8
|
+
var timerID = setInterval(function () { return tick(); }, 1000);
|
|
9
|
+
return function () { return clearInterval(timerID); };
|
|
10
|
+
}, []);
|
|
11
|
+
return currentMillis;
|
|
12
|
+
};
|
|
13
|
+
export default useCurrentTime;
|