@ape.swap/bonds-sdk 1.0.109 → 1.0.111
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.
|
@@ -21,6 +21,7 @@ import { Button } from '../uikit/Button';
|
|
|
21
21
|
import Svg from '../uikit/Svg';
|
|
22
22
|
import axios from 'axios';
|
|
23
23
|
import { BigNumber } from 'bignumber.js';
|
|
24
|
+
import { getFirstNonZeroDigits } from '../../utils/roundNumber';
|
|
24
25
|
var BondModal = function (_a) {
|
|
25
26
|
var isOpen = _a.isOpen, onClose = _a.onClose, bondAddress = _a.bondAddress;
|
|
26
27
|
if (!isOpen)
|
|
@@ -42,7 +43,11 @@ var BondModal = function (_a) {
|
|
|
42
43
|
var discountEarnTokenPrice = function (bond) {
|
|
43
44
|
var _a, _b;
|
|
44
45
|
var earnTokenPrice = parseFloat((_a = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _a !== void 0 ? _a : '0');
|
|
45
|
-
return earnTokenPrice - earnTokenPrice * (((_b = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _b !== void 0 ? _b : 0) / 100);
|
|
46
|
+
return getFirstNonZeroDigits(earnTokenPrice - earnTokenPrice * (((_b = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _b !== void 0 ? _b : 0) / 100));
|
|
47
|
+
};
|
|
48
|
+
var earnTokenPrice = function (bond) {
|
|
49
|
+
var _a;
|
|
50
|
+
return getFirstNonZeroDigits(parseFloat((_a = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _a !== void 0 ? _a : '0'));
|
|
46
51
|
};
|
|
47
52
|
var maxBuy = function (bond) {
|
|
48
53
|
var _a, _b, _c, _d;
|
|
@@ -54,8 +59,8 @@ var BondModal = function (_a) {
|
|
|
54
59
|
return !available ? 0 : (singlePurchaseLimit.lt(safeAvailable) ? singlePurchaseLimit : safeAvailable);
|
|
55
60
|
};
|
|
56
61
|
return (_jsx(ThemeUIProvider, __assign({ theme: defaultTheme }, { children: bondData.map(function (bond) {
|
|
57
|
-
var _a, _b, _c, _d, _e, _f
|
|
58
|
-
return (_jsx(React.Fragment, { children: _jsx(Flex, __assign({ className: "modal modal-backdrop" }, { children: _jsxs(Flex, __assign({ className: "modal modal-content" }, { children: [isActive && account && (_jsxs("p", { children: ["Wallet Address: ", account] })), _jsxs(Flex, __assign({ className: "modal modal-header" }, { children: [_jsx(Flex, __assign({ className: "new" }, { children: "NEW" })), _jsxs(Flex, __assign({ className: "project-info" }, { children: ["Project Info", _jsx(Flex, __assign({ className: "project-info icon" }, { children: _jsx(Svg, { icon: "expand" }) }))] })), _jsx(Flex, __assign({ className: "svg-close", onClick: onClose }, { children: _jsx(Svg, { icon: "close" }) }))] })), _jsxs(Flex, __assign({ className: "modal-container table-container" }, { children: [_jsxs(Flex, __assign({ className: "modal-container title-container" }, { children: [_jsx(Flex, __assign({ className: "title-container bond" }, { children: bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName })), _jsxs(Flex, __assign({ className: "title-container bond-price" }, { children: [_jsxs(Flex, __assign({ className: "bond-price price" }, { children: ["$", (
|
|
62
|
+
var _a, _b, _c, _d, _e, _f;
|
|
63
|
+
return (_jsx(React.Fragment, { children: _jsx(Flex, __assign({ className: "modal modal-backdrop" }, { children: _jsxs(Flex, __assign({ className: "modal modal-content" }, { children: [isActive && account && (_jsxs("p", { children: ["Wallet Address: ", account] })), _jsxs(Flex, __assign({ className: "modal modal-header" }, { children: [_jsx(Flex, __assign({ className: "new" }, { children: "NEW" })), _jsxs(Flex, __assign({ className: "project-info" }, { children: ["Project Info", _jsx(Flex, __assign({ className: "project-info icon" }, { children: _jsx(Svg, { icon: "expand" }) }))] })), _jsx(Flex, __assign({ className: "svg-close", onClick: onClose }, { children: _jsx(Svg, { icon: "close" }) }))] })), _jsxs(Flex, __assign({ className: "modal-container table-container" }, { children: [_jsxs(Flex, __assign({ className: "modal-container title-container" }, { children: [_jsx(Flex, __assign({ className: "title-container bond" }, { children: bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName })), _jsxs(Flex, __assign({ className: "title-container bond-price" }, { children: [_jsxs(Flex, __assign({ className: "bond-price price" }, { children: ["$", earnTokenPrice(bond)] })), _jsxs(Flex, __assign({ className: "bond-price discounted" }, { children: ["$", discountEarnTokenPrice(bond)] }))] }))] })), _jsx(Flex, __assign({ className: "modal-container description-container" }, { children: bond === null || bond === void 0 ? void 0 : bond.shortDescription })), _jsxs(Flex, __assign({ className: "modal-container blocks-container" }, { children: [_jsxs(Flex, __assign({ className: "modal-block column-discount ".concat(getDiscountColor(bond === null || bond === void 0 ? void 0 : bond.discount)) }, { children: [_jsxs(Flex, __assign({ className: "block-header header" }, { children: ["Discount", _jsx(Flex, __assign({ className: "block-header icon" }, { children: _jsx(Svg, { icon: "questionFill", width: "15px" }) }))] })), "".concat((_a = bond === null || bond === void 0 ? void 0 : bond.discount) === null || _a === void 0 ? void 0 : _a.toFixed(2), "%")] })), _jsxs(Flex, __assign({ className: "modal-block column-arr" }, { children: [_jsxs(Flex, __assign({ className: "block-header header" }, { children: ["ARR", _jsx(Flex, __assign({ className: "block-header icon" }, { children: _jsx(Svg, { icon: "questionFill", width: "15px" }) }))] })), "".concat(((((_b = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _b !== void 0 ? _b : 0) * 365) / vestingTime((_c = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _c !== void 0 ? _c : 0).days).toFixed(2), "%")] })), _jsxs(Flex, __assign({ className: "modal-block column-term" }, { children: [_jsxs(Flex, __assign({ className: "block-header header" }, { children: ["Terms", _jsx(Flex, __assign({ className: "block-header icon" }, { children: _jsx(Svg, { icon: "questionFill", width: "15px" }) }))] })), vestingTime((_d = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _d !== void 0 ? _d : 0).days ? "".concat(vestingTime((_e = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _e !== void 0 ? _e : 0).days, " D") : '-'] })), _jsxs(Flex, __assign({ className: "modal-block column-maxbuy" }, { children: [_jsxs(Flex, __assign({ className: "block-header header" }, { children: ["Max Buy", _jsx(Flex, __assign({ className: "block-header icon" }, { children: _jsx(Svg, { icon: "questionFill", width: "15px" }) }))] })), (_f = parseFloat(maxBuy(bond).toFixed(0))) === null || _f === void 0 ? void 0 : _f.toLocaleString('en-US')] }))] })), _jsxs(Flex, __assign({ className: "modal-container text-container" }, { children: [_jsxs(Flex, __assign({ className: "text-container row" }, { children: [_jsx("div", { children: "You spend:" }), _jsxs("div", { children: ["0 ", bond === null || bond === void 0 ? void 0 : bond.principalTokenName, " = $ 0"] })] })), _jsxs(Flex, __assign({ className: "text-container row" }, { children: [_jsxs("div", { children: ["Premium: ", _jsx(Svg, { icon: "questionFill", width: "15px" })] }), _jsx("div", { children: "$ 0" })] })), _jsxs(Flex, __assign({ className: "text-container row" }, { children: [_jsx("div", { children: "You get (over 90 days):" }), _jsxs("div", { children: ["0 ", bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName, " = $ 0"] })] }))] })), _jsxs(Flex, __assign({ className: "modal-container input-container" }, { children: [_jsx(Flex, __assign({ className: "input-container input" }, { children: _jsx(Input, { type: "number", className: "number-input", placeholder: "0.0" }) })), _jsx(Flex, __assign({ className: "input-container token" }, { children: bond === null || bond === void 0 ? void 0 : bond.principalTokenName }))] })), _jsxs(Flex, __assign({ className: "modal-container button-container" }, { children: [_jsx(Flex, __assign({ className: "button-container get" }, { children: _jsxs(Button, { children: ["Get ", bond === null || bond === void 0 ? void 0 : bond.principalTokenName] }) })), _jsx(Flex, __assign({ className: "button-container buy" }, { children: _jsxs(Button, { children: ["Buy ", bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName] }) }))] }))] }))] })) })) }, bond.billAddress));
|
|
59
64
|
}) })));
|
|
60
65
|
};
|
|
61
66
|
export default BondModal;
|
|
@@ -47,7 +47,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
};
|
|
48
48
|
import { jsx as _jsx, jsxs as _jsxs } from "theme-ui/jsx-runtime";
|
|
49
49
|
/** @jsxImportSource theme-ui */
|
|
50
|
-
import { useEffect, useState } from 'react';
|
|
50
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
51
51
|
import { Flex, ThemeUIProvider } from 'theme-ui';
|
|
52
52
|
import axios from 'axios';
|
|
53
53
|
import { ethers } from 'ethers';
|
|
@@ -57,6 +57,8 @@ import getTimePeriods from '../../utils/getTimePeriods';
|
|
|
57
57
|
import { defaultTheme } from '../../theme';
|
|
58
58
|
import Svg from '../uikit/Svg';
|
|
59
59
|
import '../../scss/bonds.scss';
|
|
60
|
+
import { BigNumber } from 'bignumber.js';
|
|
61
|
+
import { ChainId } from '@ape.swap/apeswap-lists';
|
|
60
62
|
var Bonds = function (_a) {
|
|
61
63
|
var connectionString = _a.connectionString;
|
|
62
64
|
var _b = useWeb3React(), account = _b.account, isActive = _b.isActive;
|
|
@@ -108,7 +110,7 @@ var Bonds = function (_a) {
|
|
|
108
110
|
};
|
|
109
111
|
useEffect(function () {
|
|
110
112
|
axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
|
|
111
|
-
var bonds = response.data.bonds.filter(function (x) { return x.soldOut !== true && x.inactive !== true &&
|
|
113
|
+
var bonds = response.data.bonds.filter(function (x) { return x.soldOut !== true && x.inactive !== true && !isSoldOut; });
|
|
112
114
|
setBondData(bonds);
|
|
113
115
|
});
|
|
114
116
|
}, []);
|
|
@@ -134,6 +136,18 @@ var Bonds = function (_a) {
|
|
|
134
136
|
return b.discount - a.discount;
|
|
135
137
|
}
|
|
136
138
|
});
|
|
139
|
+
var isSoldOut = useCallback(function (bond) {
|
|
140
|
+
var _a;
|
|
141
|
+
var tokensRemaining = bond.tokensRemaining, discount = bond.discount, payoutTokenPrice = bond.payoutTokenPrice;
|
|
142
|
+
if (bond.soldOut)
|
|
143
|
+
return true;
|
|
144
|
+
if (!tokensRemaining)
|
|
145
|
+
return false;
|
|
146
|
+
var thresholdToHide = new BigNumber(100).div(payoutTokenPrice !== null && payoutTokenPrice !== void 0 ? payoutTokenPrice : 0);
|
|
147
|
+
if (discount && discount > 25 && bond.chainId === ChainId.BASE)
|
|
148
|
+
return true;
|
|
149
|
+
return ((_a = new BigNumber(tokensRemaining)) === null || _a === void 0 ? void 0 : _a.lte(thresholdToHide)) || discount === 100;
|
|
150
|
+
}, []);
|
|
137
151
|
var _f = useState(false), isModalOpen = _f[0], setIsModalOpen = _f[1];
|
|
138
152
|
var _g = useState(null), selectedBond = _g[0], setSelectedBond = _g[1];
|
|
139
153
|
var rowClick = function (bond) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rounds a number to precision amount of signifant numbers
|
|
3
|
+
* @param n the number
|
|
4
|
+
* @param precision how many significant numbers to show
|
|
5
|
+
* @returns @number
|
|
6
|
+
*/
|
|
7
|
+
export declare const getFirstNonZeroDigits: (numberToParse: number, precision?: number) => string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rounds a number to precision amount of signifant numbers
|
|
3
|
+
* @param n the number
|
|
4
|
+
* @param precision how many significant numbers to show
|
|
5
|
+
* @returns @number
|
|
6
|
+
*/
|
|
7
|
+
export var getFirstNonZeroDigits = function (numberToParse, precision) {
|
|
8
|
+
if (precision === void 0) { precision = 3; }
|
|
9
|
+
var n = parseFloat(numberToParse.toFixed(18));
|
|
10
|
+
var amountToShow = precision - 1;
|
|
11
|
+
if (n !== 0)
|
|
12
|
+
amountToShow -= Math.floor(Math.log(n) / Math.log(10));
|
|
13
|
+
return n.toFixed(amountToShow < 0 ? 0 : amountToShow);
|
|
14
|
+
};
|