@ape.swap/bonds-sdk 1.0.310 → 1.0.313
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.
|
@@ -72,6 +72,10 @@ var BondModal = function (_a) {
|
|
|
72
72
|
var _b = useWeb3React(), account = _b.account, isActive = _b.isActive;
|
|
73
73
|
var vestingTime = function (vestingTerm) { return getTimePeriods(vestingTerm !== null && vestingTerm !== void 0 ? vestingTerm : 0, true); };
|
|
74
74
|
var _c = useState([]), bondData = _c[0], setBondData = _c[1];
|
|
75
|
+
var _d = useState(false), approvalStatus = _d[0], setApprovalStatus = _d[1];
|
|
76
|
+
//This is a temp solution, but we will force approval each time, and then once set we will set status here and allow
|
|
77
|
+
//user to buy
|
|
78
|
+
//Check with Fede if this needs to be temp, if we force approval everytime, isn't this fine?
|
|
75
79
|
useEffect(function () {
|
|
76
80
|
axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
|
|
77
81
|
var bond = response.data.bonds.filter(function (x) {
|
|
@@ -101,11 +105,11 @@ var BondModal = function (_a) {
|
|
|
101
105
|
var singlePurchaseLimit = new BigNumber((_c = bond === null || bond === void 0 ? void 0 : bond.maxPayout) !== null && _c !== void 0 ? _c : 0).div(new BigNumber(10).pow((_d = bond === null || bond === void 0 ? void 0 : bond.payoutTokenDecimals) !== null && _d !== void 0 ? _d : 18));
|
|
102
106
|
return !available ? 0 : (singlePurchaseLimit.lt(safeAvailable) ? singlePurchaseLimit : safeAvailable);
|
|
103
107
|
};
|
|
104
|
-
var
|
|
108
|
+
var _e = useState(''), inputValue = _e[0], setInputValue = _e[1];
|
|
105
109
|
var handleInputChange = function (event) {
|
|
106
110
|
setInputValue(event.target.value);
|
|
107
111
|
};
|
|
108
|
-
var
|
|
112
|
+
var _f = useState(null), selectedBond = _f[0], setSelectedBond = _f[1];
|
|
109
113
|
var navigate = useNavigate();
|
|
110
114
|
var projectInfo = function (bond) {
|
|
111
115
|
setSelectedBond(bond);
|
|
@@ -198,6 +202,42 @@ var BondModal = function (_a) {
|
|
|
198
202
|
}
|
|
199
203
|
});
|
|
200
204
|
}); };
|
|
205
|
+
var handleApprove = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
206
|
+
var provider, signer, bondContract, amount, tx, error_2;
|
|
207
|
+
return __generator(this, function (_a) {
|
|
208
|
+
switch (_a.label) {
|
|
209
|
+
case 0:
|
|
210
|
+
console.log('handle approve clicked');
|
|
211
|
+
if (!window.ethereum) {
|
|
212
|
+
console.error('No Ethereum provider found');
|
|
213
|
+
alert('No Ethereum provider found');
|
|
214
|
+
return [2 /*return*/];
|
|
215
|
+
}
|
|
216
|
+
provider = new ethers.providers.Web3Provider(window.ethereum);
|
|
217
|
+
signer = provider.getSigner();
|
|
218
|
+
bondContract = new ethers.Contract(bondAddress !== null && bondAddress !== void 0 ? bondAddress : "", BondAbi, signer);
|
|
219
|
+
_a.label = 1;
|
|
220
|
+
case 1:
|
|
221
|
+
_a.trys.push([1, 4, , 5]);
|
|
222
|
+
amount = adjustDecimals(inputValue);
|
|
223
|
+
return [4 /*yield*/, bondContract.approve(amount, account)];
|
|
224
|
+
case 2:
|
|
225
|
+
tx = _a.sent();
|
|
226
|
+
return [4 /*yield*/, tx.wait()];
|
|
227
|
+
case 3:
|
|
228
|
+
_a.sent();
|
|
229
|
+
setApprovalStatus(true);
|
|
230
|
+
alert('Approve Successful');
|
|
231
|
+
return [3 /*break*/, 5];
|
|
232
|
+
case 4:
|
|
233
|
+
error_2 = _a.sent();
|
|
234
|
+
console.error('Approval error', error_2);
|
|
235
|
+
alert('Approval Failed');
|
|
236
|
+
return [3 /*break*/, 5];
|
|
237
|
+
case 5: return [2 /*return*/];
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}); };
|
|
201
241
|
return (_jsx(ThemeUIProvider, __assign({ theme: defaultTheme }, { children: bondData.map(function (bond) {
|
|
202
242
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
203
243
|
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] })), _jsx(Flex, __assign({ className: "modal modal-header" }, { children: _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 bondicon" }, { children: _jsx(TokenImage, { symbol: (_a = bond.showcaseTokenName) !== null && _a !== void 0 ? _a : bond.payoutTokenName, size: 50 }) })), _jsx(Flex, __assign({ className: "title-container bondname" }, { children: bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName })), _jsxs(Flex, __assign({ className: "title-container price-container" }, { children: [_jsxs(Flex, __assign({ className: "price-container price" }, { children: ["$", earnTokenPrice(bond)] })), _jsxs(Flex, __assign({ className: "price-container discounted" }, { children: ["$", discountEarnTokenPrice(bond)] }))] })), _jsx(Flex, __assign({ className: "title-container tokentags" }, { children: _jsx(ListTag, { text: (_b = bond === null || bond === void 0 ? void 0 : bond.tags) === null || _b === void 0 ? void 0 : _b[0], variant: ((_c = bond === null || bond === void 0 ? void 0 : bond.tags) === null || _c === void 0 ? void 0 : _c[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((_d = bond === null || bond === void 0 ? void 0 : bond.discount) === null || _d === void 0 ? void 0 : _d.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(((((_e = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _e !== void 0 ? _e : 0) * 365) / vestingTime((_f = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _f !== void 0 ? _f : 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((_g = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _g !== void 0 ? _g : 0).days ? "".concat(vestingTime((_h = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _h !== void 0 ? _h : 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" }) })) }))] })), (_j = parseFloat(maxBuy(bond).toFixed(0))) === null || _j === void 0 ? void 0 : _j.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, " = $ ", formatUSDNumber(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" }) })) }))] })), _jsxs(Flex, __assign({ className: "row-container premium-val ".concat(getPremiumColor(bond)) }, { children: ["$ ", premium(bond)] }))] })), _jsxs(Flex, __assign({ className: "text-container row" }, { children: [_jsxs(Flex, __assign({ className: "row-container get" }, { children: ["You get (over ", vestingTime((_k = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _k !== void 0 ? _k : 0).days, " days):"] })), _jsxs(Flex, __assign({ className: "row-container get-val" }, { children: [youGet(bond), " ", bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName, " = $ ", formatUSDNumber(youGetUSD(bond))] }))] }))] })), _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) {
|
|
@@ -214,7 +254,10 @@ var BondModal = function (_a) {
|
|
|
214
254
|
!!v.currentTarget.value && isNumber(v.currentTarget.value) && parseFloat(v.currentTarget.value) >= 0
|
|
215
255
|
? v.currentTarget.value
|
|
216
256
|
: v.currentTarget.value.slice(0, v.currentTarget.value.length - 1);
|
|
217
|
-
} }) })), _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:
|
|
257
|
+
} }) })), _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: approvalStatus === true ?
|
|
258
|
+
_jsxs(Button, __assign({ onClick: handleBuy }, { children: ["Buy ", bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName] }))
|
|
259
|
+
:
|
|
260
|
+
_jsx(Button, __assign({ onClick: handleApprove }, { children: "Approve" })) }))] }))] }))] })) })) }, bond.billAddress));
|
|
218
261
|
}) })));
|
|
219
262
|
};
|
|
220
263
|
export default BondModal;
|
|
@@ -68,6 +68,7 @@ import { getFirstNonZeroDigits } from '../../utils/roundNumber';
|
|
|
68
68
|
import { formatNumberSI } from '../../utils/formatNumber';
|
|
69
69
|
import useCurrentTime from '../../hooks/useTimer';
|
|
70
70
|
import { getPendingVesting } from '../../hooks/usePendingVesting';
|
|
71
|
+
import axios from 'axios';
|
|
71
72
|
var YourBonds = function (_a) {
|
|
72
73
|
var connectionString = _a.connectionString;
|
|
73
74
|
var _b = useWeb3React(), account = _b.account, isActive = _b.isActive;
|
|
@@ -116,12 +117,12 @@ var YourBonds = function (_a) {
|
|
|
116
117
|
// const vestingTime = (vestingTerm: number) => {
|
|
117
118
|
// return getTimePeriods(vestingTerm ?? 0, true);
|
|
118
119
|
// }
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
useEffect(function () {
|
|
121
|
+
axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
|
|
122
|
+
var bonds = response.data.bonds;
|
|
123
|
+
setBondData(bonds);
|
|
124
|
+
});
|
|
125
|
+
}, []);
|
|
125
126
|
// useEffect(() => {
|
|
126
127
|
// axios.get('https://apeswap-strapi.herokuapp.com/hot-bonds').then((response) => {
|
|
127
128
|
// const hotBondAddresses = response.data.map((bond: { BondAddress: string }) =>
|