@ape.swap/bonds-sdk 1.0.237 → 1.0.239

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.
@@ -24,6 +24,7 @@ import { useNavigate } from 'react-router-dom';
24
24
  import { isNumber } from '../../utils/numbers';
25
25
  import { TooltipBubble, Button, Svg, ListTag } from '../uikit-sdk';
26
26
  import { TooltipText } from '../../enum/tooltips';
27
+ import { formatNumberSI } from '../../utils/formatNumber';
27
28
  var BondModal = function (_a) {
28
29
  var isOpen = _a.isOpen, onClose = _a.onClose, bondAddress = _a.bondAddress;
29
30
  if (!isOpen)
@@ -70,37 +71,52 @@ var BondModal = function (_a) {
70
71
  setSelectedBond(bond);
71
72
  navigate("/bondsingle/".concat(bond.billAddress));
72
73
  };
73
- // function formatUSDNumber(input: string): string {
74
- // const number = new BigNumber(input)
75
- // if (number.isNaN()) return '0'
76
- // // If the number is greater than 0 but less than 0.01
77
- // if (number.gt(0) && number.lt(0.01)) {
78
- // return '< 0.01'
79
- // }
80
- // // If the number is greater than 1k, round to no decimals.
81
- // if (number.gt(1000)) {
82
- // return number.toNumber().toLocaleString(undefined, { maximumFractionDigits: 0 })
83
- // }
84
- // // Note: Between 1k and 0.01 show 2 decimals
85
- // return parseFloat(number.toFixed(2)).toLocaleString(undefined)
86
- // }
87
- // const youSpendUSD = (bond: BondsDataResponse) => {
88
- // return formatUSDNumber((parseFloat(inputValue) * parseFloat(earnTokenPrice(bond))).toString())
89
- // }
90
- // const youGetUSD = (bond: BondsDataResponse) => {
91
- // const bigValue = new BigNumber(inputValue).times(new BigNumber(10).pow(18));
92
- // const billValue = bigValue.div(new BigNumber(bond.trueBillPrice ?? 0));
93
- // return formatUSDNumber((billValue.toNumber() * parseFloat(bond.payoutTokenPrice)).toString())
94
- // }
95
- // const premium = (bond: BondsDataResponse) => {
96
- // return formatUSDNumber((parseFloat(youGetUSD(bond)) - parseFloat(inputValue)).toString())
97
- // }
98
- // const getPremiumColor = (premium: string): string => {
99
- // return parseFloat(premium) < 0 ? 'premium-negative' : 'premium-positive';
100
- // };
74
+ function formatNumber(input) {
75
+ var number = new BigNumber(input);
76
+ if (number.isNaN())
77
+ return '0';
78
+ return number.gt(1000000)
79
+ ? formatNumberSI(number.toNumber())
80
+ : number.gt(1000)
81
+ ? number.toNumber().toLocaleString(undefined, { maximumFractionDigits: 0 })
82
+ : number.gt(0.01)
83
+ ? parseFloat(number.toFixed(2)).toLocaleString(undefined)
84
+ : parseFloat(number.toPrecision(5)).toLocaleString(undefined);
85
+ }
86
+ function formatUSDNumber(input) {
87
+ var number = new BigNumber(input);
88
+ if (number.isNaN())
89
+ return '0';
90
+ // If the number is greater than 0 but less than 0.01
91
+ if (number.gt(0) && number.lt(0.01)) {
92
+ return '< 0.01';
93
+ }
94
+ // If the number is greater than 1k, round to no decimals.
95
+ if (number.gt(1000)) {
96
+ return number.toNumber().toLocaleString(undefined, { maximumFractionDigits: 0 });
97
+ }
98
+ // Note: Between 1k and 0.01 show 2 decimals
99
+ return parseFloat(number.toFixed(2)).toLocaleString(undefined);
100
+ }
101
+ var youSpend = formatNumber(inputValue);
102
+ var youSpendUSD = function (bond) {
103
+ return formatUSDNumber((parseFloat(inputValue) * parseFloat(earnTokenPrice(bond))).toString());
104
+ };
105
+ var youGetUSD = function (bond) {
106
+ var _a;
107
+ var bigValue = new BigNumber(inputValue).times(new BigNumber(10).pow(18));
108
+ var billValue = bigValue.div(new BigNumber((_a = bond.trueBillPrice) !== null && _a !== void 0 ? _a : 0));
109
+ return formatUSDNumber((billValue.toNumber() * parseFloat(bond.payoutTokenPrice)).toString());
110
+ };
111
+ var premium = function (bond) {
112
+ return formatUSDNumber((parseFloat(youGetUSD(bond)) - parseFloat(inputValue)).toString());
113
+ };
114
+ var getPremiumColor = function (premium) {
115
+ return parseFloat(premium) < 0 ? 'premium-negative' : 'premium-positive';
116
+ };
101
117
  return (_jsx(ThemeUIProvider, __assign({ theme: defaultTheme }, { children: bondData.map(function (bond) {
102
118
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
103
- 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", onClick: function () { return projectInfo(bond); } }, { children: "NEW" }), bond.billAddress), _jsxs(Flex, __assign({ className: "project-info", onClick: function () { return projectInfo(bond); } }, { children: ["Project Info", _jsx(Flex, __assign({ className: "project-info icon" }, { children: _jsx(Svg, { icon: "expand" }) }))] }), bond.billAddress), _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: "title-container tokentags" }, { children: _jsx(ListTag, { text: (_a = bond === null || bond === void 0 ? void 0 : bond.tags) === null || _a === void 0 ? void 0 : _a[0], variant: ((_b = bond === null || bond === void 0 ? void 0 : bond.tags) === null || _b === void 0 ? void 0 : _b[0]) === 'Cex Fund' ? 'cex_fund' : 'liquidity' }) }))] })), _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(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.Discount }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)" }, { children: _jsx(Flex, __assign({ className: "block-header icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) })) }))] })), "".concat((_c = bond === null || bond === void 0 ? void 0 : bond.discount) === null || _c === void 0 ? void 0 : _c.toFixed(2), "%")] })), _jsxs(Flex, __assign({ className: "modal-block column-arr" }, { children: [_jsxs(Flex, __assign({ className: "block-header header" }, { children: ["ARR", _jsx(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.ARR }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)" }, { children: _jsx(Flex, __assign({ className: "block-header icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) })) }))] })), "".concat(((((_d = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _d !== void 0 ? _d : 0) * 365) / vestingTime((_e = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _e !== void 0 ? _e : 0).days).toFixed(2), "%")] })), _jsxs(Flex, __assign({ className: "modal-block column-term" }, { children: [_jsxs(Flex, __assign({ className: "block-header header" }, { children: ["Terms", _jsx(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.Terms }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)" }, { children: _jsx(Flex, __assign({ className: "block-header icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) })) }))] })), vestingTime((_f = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _f !== void 0 ? _f : 0).days ? "".concat(vestingTime((_g = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _g !== void 0 ? _g : 0).days, " D") : '-'] })), _jsxs(Flex, __assign({ className: "modal-block column-maxbuy" }, { children: [_jsxs(Flex, __assign({ className: "block-header header" }, { children: ["Max Buy", _jsx(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.MaxBuy(bond.payoutTokenName) }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)" }, { children: _jsx(Flex, __assign({ className: "block-header icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) })) }))] })), (_h = parseFloat(maxBuy(bond).toFixed(0))) === null || _h === void 0 ? void 0 : _h.toLocaleString('en-US')] }))] })), _jsxs(Flex, __assign({ className: "modal-container text-container" }, { children: [_jsxs(Flex, __assign({ className: "text-container row" }, { children: [_jsx(Flex, __assign({ className: "row-container spend" }, { children: "You spend:" })), _jsxs(Flex, __assign({ className: "row-container spend-val" }, { children: ["0 ", bond === null || bond === void 0 ? void 0 : bond.principalTokenName, " = $ 0"] }))] })), _jsxs(Flex, __assign({ className: "text-container row" }, { children: [_jsxs(Flex, __assign({ className: "row-container premium" }, { children: ["Premium:", _jsx(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.Premium }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)" }, { children: _jsx(Flex, __assign({ className: "row-container premium-icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) })) }))] })), _jsx(Flex, __assign({ className: "row-container premium-val" }, { children: "$ 0" }))] })), _jsxs(Flex, __assign({ className: "text-container row" }, { children: [_jsxs(Flex, __assign({ className: "row-container get" }, { children: ["You get (over ", vestingTime((_j = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _j !== void 0 ? _j : 0).days, " days):"] })), _jsxs(Flex, __assign({ className: "row-container get-val" }, { 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, { placeholder: "0.0", value: inputValue, pattern: "^[0-9]*[.,]?[0-9]*$", onChange: handleInputChange, onInput: function (v) {
119
+ 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", onClick: function () { return projectInfo(bond); } }, { children: "NEW" }), bond.billAddress), _jsxs(Flex, __assign({ className: "project-info", onClick: function () { return projectInfo(bond); } }, { children: ["Project Info", _jsx(Flex, __assign({ className: "project-info icon" }, { children: _jsx(Svg, { icon: "expand" }) }))] }), bond.billAddress), _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: "title-container tokentags" }, { children: _jsx(ListTag, { text: (_a = bond === null || bond === void 0 ? void 0 : bond.tags) === null || _a === void 0 ? void 0 : _a[0], variant: ((_b = bond === null || bond === void 0 ? void 0 : bond.tags) === null || _b === void 0 ? void 0 : _b[0]) === 'Cex Fund' ? 'cex_fund' : 'liquidity' }) }))] })), _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(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.Discount }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)" }, { children: _jsx(Flex, __assign({ className: "block-header icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) })) }))] })), "".concat((_c = bond === null || bond === void 0 ? void 0 : bond.discount) === null || _c === void 0 ? void 0 : _c.toFixed(2), "%")] })), _jsxs(Flex, __assign({ className: "modal-block column-arr" }, { children: [_jsxs(Flex, __assign({ className: "block-header header" }, { children: ["ARR", _jsx(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.ARR }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)" }, { children: _jsx(Flex, __assign({ className: "block-header icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) })) }))] })), "".concat(((((_d = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _d !== void 0 ? _d : 0) * 365) / vestingTime((_e = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _e !== void 0 ? _e : 0).days).toFixed(2), "%")] })), _jsxs(Flex, __assign({ className: "modal-block column-term" }, { children: [_jsxs(Flex, __assign({ className: "block-header header" }, { children: ["Terms", _jsx(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.Terms }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)" }, { children: _jsx(Flex, __assign({ className: "block-header icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) })) }))] })), vestingTime((_f = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _f !== void 0 ? _f : 0).days ? "".concat(vestingTime((_g = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _g !== void 0 ? _g : 0).days, " D") : '-'] })), _jsxs(Flex, __assign({ className: "modal-block column-maxbuy" }, { children: [_jsxs(Flex, __assign({ className: "block-header header" }, { children: ["Max Buy", _jsx(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.MaxBuy(bond.payoutTokenName) }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)" }, { children: _jsx(Flex, __assign({ className: "block-header icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) })) }))] })), (_h = parseFloat(maxBuy(bond).toFixed(0))) === null || _h === void 0 ? void 0 : _h.toLocaleString('en-US')] }))] })), _jsxs(Flex, __assign({ className: "modal-container text-container" }, { children: [_jsxs(Flex, __assign({ className: "text-container row" }, { children: [_jsx(Flex, __assign({ className: "row-container spend" }, { children: "You spend:" })), _jsxs(Flex, __assign({ className: "row-container spend-val" }, { children: [youSpend, " ", bond.principalTokenName, " = $ ", youSpendUSD(bond)] }))] })), _jsxs(Flex, __assign({ className: "text-container row" }, { children: [_jsxs(Flex, __assign({ className: "row-container premium" }, { children: ["Premium:", _jsx(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.Premium }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)" }, { children: _jsx(Flex, __assign({ className: "row-container premium-icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) })) }))] })), _jsx(Flex, __assign({ className: "row-container premium-val" }, { children: "$ 0" }))] })), _jsxs(Flex, __assign({ className: "text-container row" }, { children: [_jsxs(Flex, __assign({ className: "row-container get" }, { children: ["You get (over ", vestingTime((_j = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _j !== void 0 ? _j : 0).days, " days):"] })), _jsxs(Flex, __assign({ className: "row-container get-val" }, { 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, { placeholder: "0.0", value: inputValue, pattern: "^[0-9]*[.,]?[0-9]*$", onChange: handleInputChange, onInput: function (v) {
104
120
  if (v.currentTarget.value.includes(',')) {
105
121
  v.currentTarget.value = v.currentTarget.value.replace(/,/g, '.');
106
122
  }
@@ -65,9 +65,6 @@ import { TooltipText } from '../../enum/tooltips';
65
65
  import { TooltipBubble, Svg, ListTag } from '../uikit-sdk';
66
66
  import Tooltip from '../Tooltip/Tooltip';
67
67
  import { BLOCK_EXPLORER } from '../../config/constants/chains';
68
- var abc;
69
- abc;
70
- var ad = abc.chainId;
71
68
  var Bonds = function (_a) {
72
69
  var connectionString = _a.connectionString;
73
70
  var _b = useWeb3React(), account = _b.account, isActive = _b.isActive;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Ape Bond SDK",
4
4
  "author": "Ape Bond",
5
5
  "license": "MIT",
6
- "version": "1.0.237",
6
+ "version": "1.0.239",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.es.js",
9
9
  "types": "dist/index.d.ts",