@ape.swap/bonds-sdk 1.0.273 → 1.0.275

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.
@@ -1,5 +1,6 @@
1
1
  /** @jsxImportSource theme-ui */
2
2
  import React from 'react';
3
+ import { BondsDataResponse } from '../../types/bonds';
3
4
  import '../../scss/Bonds.scss';
4
5
  declare global {
5
6
  interface Window {
@@ -20,6 +21,7 @@ export interface UserBill {
20
21
  pendingRewards: string;
21
22
  billNftAddress: string;
22
23
  nftData?: UserBillNft;
24
+ bond: BondsDataResponse;
23
25
  }
24
26
  export interface UserBillNft {
25
27
  image: string;
@@ -66,7 +66,6 @@ import { TooltipBubble, Svg } from '../uikit-sdk';
66
66
  import Tooltip from '../Tooltip/Tooltip';
67
67
  import { BLOCK_EXPLORER, MAINNET_CHAINS } from '../../config/constants/chains';
68
68
  import TokenInfoAndName from '../TokenInfoAndName';
69
- import useRefresh from '../../hooks/useRefresh';
70
69
  import { ACF_TO_ABOND } from '../../config/constants/addresses';
71
70
  import multicall from '../../utils/multicall';
72
71
  import billAbi from '../../config/abi/bond.json';
@@ -114,17 +113,16 @@ var YourBonds = function (_a) {
114
113
  }
115
114
  });
116
115
  }); };
117
- var _d = useState([]), userBondData = _d[0], setUserBondData = _d[1];
116
+ var _d = useState([]), bondData = _d[0], setBondData = _d[1];
118
117
  var _e = useState([]), hotBonds = _e[0], setHotBonds = _e[1];
119
118
  var vestingTime = function (vestingTerm) {
120
119
  return getTimePeriods(vestingTerm !== null && vestingTerm !== void 0 ? vestingTerm : 0, true);
121
120
  };
122
121
  useEffect(function () {
123
122
  axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
124
- var bonds = response.data.bonds;
125
- setUserBondData(bonds);
123
+ var bonds = response.data.bonds.filter(function (bond) { return !isSoldOut(bond); });
124
+ setBondData(bonds);
126
125
  });
127
- usePollUserBills();
128
126
  }, []);
129
127
  useEffect(function () {
130
128
  axios.get('https://apeswap-strapi.herokuapp.com/hot-bonds').then(function (response) {
@@ -147,7 +145,7 @@ var YourBonds = function (_a) {
147
145
  return true;
148
146
  return ((_b = new BigNumber(bond.tokensRemaining)) === null || _b === void 0 ? void 0 : _b.lte(thresholdToHide)) || bond.discount === 100;
149
147
  }, []);
150
- var sortedBonds = userBondData.sort(function (a, b) {
148
+ var sortedBonds = bondData.sort(function (a, b) {
151
149
  var _a, _b;
152
150
  var aIsHot = hotBonds.includes(a.billAddress.toLowerCase()) && ((_a = a.discount) !== null && _a !== void 0 ? _a : 0) > 0;
153
151
  var bIsHot = hotBonds.includes(b.billAddress.toLowerCase()) && ((_b = b.discount) !== null && _b !== void 0 ? _b : 0) > 0;
@@ -192,23 +190,23 @@ var YourBonds = function (_a) {
192
190
  var explorerLink = BLOCK_EXPLORER[selectedChain];
193
191
  return "".concat(explorerLink, "/address/").concat(bond === null || bond === void 0 ? void 0 : bond.billAddress);
194
192
  };
195
- var usePollUserBills = function () {
196
- var slowRefresh = useRefresh().slowRefresh;
197
- // const dispatch = useAppDispatch()
198
- var _a = useWeb3React(), account = _a.account, isActive = _a.isActive;
199
- useEffect(function () {
200
- if (account) {
201
- MAINNET_CHAINS.map(function (chain) { return fetchUserOwnedBillsDataAsync(chain, account); });
202
- }
203
- }, [account, slowRefresh]);
204
- };
193
+ // const usePollUserBills = () => {
194
+ // const { slowRefresh } = useRefresh()
195
+ // // const dispatch = useAppDispatch()
196
+ // const { account, isActive } = useWeb3React();
197
+ // useEffect(() => {
198
+ // if (account) {
199
+ // MAINNET_CHAINS.map((chain) => fetchUserOwnedBillsDataAsync(chain as number, account))
200
+ // }
201
+ // }, [account, slowRefresh])
202
+ // }
205
203
  var fetchUserOwnedBillsDataAsync = function (chainId, account) { return __awaiter(void 0, void 0, void 0, function () {
206
- var bonds, userOwnedBills_1, mapUserOwnedBills_1, userOwnedBillsData, error_2;
204
+ var bonds, userOwnedBills_1, mapUserOwnedBills_1, userOwnedBillsData_1, error_2;
207
205
  return __generator(this, function (_a) {
208
206
  switch (_a.label) {
209
207
  case 0:
210
208
  _a.trys.push([0, 2, , 3]);
211
- bonds = userBondData.filter(function (bond) {
209
+ bonds = bondData.filter(function (bond) {
212
210
  return bond.billVersion !== BillVersion.FixedPrice &&
213
211
  (bond === null || bond === void 0 ? void 0 : bond.chainId) === chainId &&
214
212
  bond.type !== 'migration' &&
@@ -220,13 +218,11 @@ var YourBonds = function (_a) {
220
218
  mapUserOwnedBills_1 = bonds.map(function (bill) {
221
219
  return userOwnedBills_1.filter(function (b) { return b.address.toLowerCase() === bill.billAddress.toLowerCase(); });
222
220
  });
223
- userOwnedBillsData = bonds.map(function (bill, i) { return ({
221
+ userOwnedBillsData_1 = bonds.map(function (bill, i) { return ({
224
222
  index: bill.index,
225
223
  userOwnedBills: mapUserOwnedBills_1[i],
226
224
  }); });
227
- console.log('userOwnedBillsData');
228
- console.log(userOwnedBillsData);
229
- return [2 /*return*/, Promise.resolve(userOwnedBillsData)];
225
+ return [2 /*return*/, Promise.resolve(userOwnedBillsData_1)];
230
226
  case 2:
231
227
  error_2 = _a.sent();
232
228
  console.error('Error fetching user owned bills data:', error_2);
@@ -235,6 +231,33 @@ var YourBonds = function (_a) {
235
231
  }
236
232
  });
237
233
  }); };
234
+ var _h = useState([]), userOwnedBillsData = _h[0], setUserOwnedBillsData = _h[1];
235
+ useEffect(function () {
236
+ var fetchData = function () { return __awaiter(void 0, void 0, void 0, function () {
237
+ var results, error_3;
238
+ return __generator(this, function (_a) {
239
+ switch (_a.label) {
240
+ case 0:
241
+ if (!account) return [3 /*break*/, 4];
242
+ _a.label = 1;
243
+ case 1:
244
+ _a.trys.push([1, 3, , 4]);
245
+ return [4 /*yield*/, Promise.all(MAINNET_CHAINS.map(function (chain) { return fetchUserOwnedBillsDataAsync(chain, account); }))];
246
+ case 2:
247
+ results = _a.sent();
248
+ setUserOwnedBillsData(results);
249
+ console.log('User owned bills data:', results);
250
+ return [3 /*break*/, 4];
251
+ case 3:
252
+ error_3 = _a.sent();
253
+ console.error('Error fetching user owned bills data:', error_3);
254
+ return [3 /*break*/, 4];
255
+ case 4: return [2 /*return*/];
256
+ }
257
+ });
258
+ }); };
259
+ fetchData();
260
+ }, [account]);
238
261
  var fetchUserOwnedBills = function (chainId, account, bonds) { return __awaiter(void 0, void 0, void 0, function () {
239
262
  var billIdCalls, billIds, billsPendingRewardCall, billDataCalls, billVersions, billData, pendingRewardsCall, result, i, billDataPos, data;
240
263
  var _a, _b, _c, _d, _e;
@@ -259,12 +282,14 @@ var YourBonds = function (_a) {
259
282
  address: bonds[index].billAddress,
260
283
  name: bonds[index].billVersion !== BillVersion.V1 ? 'getBillInfo' : 'billInfo',
261
284
  params: [id],
285
+ bond: bonds[index]
262
286
  }),
263
287
  billDataCalls.push({ address: bonds[index].billAddress, name: 'billNft' }),
264
288
  billsPendingRewardCall.push({
265
289
  address: bonds[index].billAddress,
266
290
  name: bonds[index].billVersion !== BillVersion.V1 ? 'claimablePayout' : 'pendingPayoutFor',
267
291
  params: [id],
292
+ bond: bonds[index]
268
293
  }),
269
294
  billVersions.push(bonds[index].billVersion));
270
295
  });
@@ -290,6 +315,7 @@ var YourBonds = function (_a) {
290
315
  lastBlockTimestamp: (_d = billData[billDataPos][0]) === null || _d === void 0 ? void 0 : _d.lastClaimTimestamp.toString(),
291
316
  truePricePaid: (_e = billData[billDataPos][0]) === null || _e === void 0 ? void 0 : _e.truePricePaid.toString(),
292
317
  pendingRewards: pendingRewardsCall[i][0].toString(),
318
+ bond: billsPendingRewardCall[i].bond
293
319
  }
294
320
  : {
295
321
  address: billsPendingRewardCall[i].address,
@@ -300,6 +326,7 @@ var YourBonds = function (_a) {
300
326
  lastBlockTimestamp: billData[billDataPos][2].toString(),
301
327
  truePricePaid: billData[billDataPos][3].toString(),
302
328
  pendingRewards: pendingRewardsCall[i][0].toString(),
329
+ bond: billsPendingRewardCall[i].bond
303
330
  };
304
331
  result.push(data);
305
332
  }
@@ -307,18 +334,20 @@ var YourBonds = function (_a) {
307
334
  }
308
335
  });
309
336
  }); };
310
- return (_jsxs(ThemeUIProvider, __assign({ theme: defaultTheme }, { children: [isActive && account && _jsx("p", { children: account }), isActive && account && _jsx("button", __assign({ onClick: handleApprove }, { children: "Approve USDT" })), _jsxs(Flex, __assign({ className: "container table-container" }, { children: [_jsxs(Flex, __assign({ className: "container header-container" }, { children: [_jsxs(Flex, __assign({ className: "column column-tokens" }, { children: [_jsx(Flex, __assign({ className: "column column-tokenname" }, { children: "Tokens" })), _jsx(Flex, { className: "column column-tokenicons" })] })), _jsxs(Flex, __assign({ className: "column column-bondinfo" }, { children: [_jsx(Flex, __assign({ className: "column column-discount" }, { children: _jsxs(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.Discount }), width: "230px", placement: "bottomLeft", transformTip: "translate(18%, -4%)" }, { children: ["Discount", _jsx(Flex, __assign({ className: "column header-icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) }))] })) })), _jsx(Flex, __assign({ className: "column column-arr" }, { children: _jsxs(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.ARR }), width: "230px", placement: "bottomLeft", transformTip: "translate(8%, -5%)" }, { children: ["ARR", _jsx(Flex, __assign({ className: "column header-icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) }))] })) })), _jsx(Flex, __assign({ className: "column column-term" }, { children: _jsxs(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.Terms }), width: "230px", placement: "bottomRight", transformTip: "translate(11%, -5%)" }, { children: ["Terms", _jsx(Flex, __assign({ className: "column header-icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) }))] })) })), _jsx(Flex, __assign({ className: "column column-tokensremaining" }, { children: _jsxs(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.TokensRemaining }), width: "230px", placement: "bottomRight", transformTip: "translate(12%, -4%)" }, { children: ["Tokens Remaining", _jsx(Flex, __assign({ className: "column header-icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) }))] })) })), _jsx(Flex, { className: "column column-hotbond" })] }))] })), sortedBonds.map(function (bond) {
311
- var _a, _b, _c, _d, _e;
312
- return (_jsxs(Flex, __assign({ className: "container bondrow-container", onClick: function () { return rowClick(bond); } }, { children: [_jsxs(Flex, __assign({ className: "column column-tokens" }, { children: [_jsx(Flex, __assign({ className: "column column-tokeninfoname" }, { children: _jsx(TokenInfoAndName, { bond: bond }) })), _jsx(Flex, __assign({ className: "column column-tokenicons" }, { children: _jsx(TooltipBubble, __assign({ body: _jsx(Tooltip, { tokenContract: (bond === null || bond === void 0 ? void 0 : bond.payoutToken) || '', secondURL: getBillContractURL(bond), secondURLTitle: 'View Bond Contract', thirdURL: "https://dashboard.ape.bond/bond/".concat((_a = bond === null || bond === void 0 ? void 0 : bond.billAddress) === null || _a === void 0 ? void 0 : _a.toLowerCase()), thirdURLTitle: 'View Insights', twitter: bond === null || bond === void 0 ? void 0 : bond.twitter, projectLink: bond === null || bond === void 0 ? void 0 : bond.projectLink, audit: bond === null || bond === void 0 ? void 0 : bond.audit, chain: (_b = bond.chainId) !== null && _b !== void 0 ? _b : ChainId.BSC }), width: "205px", placement: "bottomRight", transformTip: "translate(11%, 0%)" }, { children: _jsx(Svg, { icon: "more", width: "20px" }) })) }))] })), _jsxs(Flex, __assign({ className: "column column-bondinfo" }, { children: [_jsx(Flex, __assign({ className: "column column-discount ".concat(getDiscountColor(bond === null || bond === void 0 ? void 0 : bond.discount)) }, { children: "".concat((_c = bond === null || bond === void 0 ? void 0 : bond.discount) === null || _c === void 0 ? void 0 : _c.toFixed(2), "%") })), _jsx(Flex, __assign({ className: "column column-arr" }, { children: "".concat(((((_d = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _d !== void 0 ? _d : 0) * 365) / vestingTime(bond.vestingTerm).days).toFixed(2), "%") })), _jsx(Flex, __assign({ className: "column column-term" }, { children: vestingTime(bond.vestingTerm).days ? "".concat(vestingTime(bond.vestingTerm).days, " D") : '-' })), _jsx(Flex, __assign({ className: "column column-tokensremaining" }, { children: _jsx(ProgressBarWrapper, { title: '', value: _jsx(ProgressBar, { value: remainingPercentage(bond) }), style: {
313
- width: '127px',
314
- height: '25px',
315
- flexDirection: 'column',
316
- justifyContent: 'center',
317
- display: ['none', 'none', 'none', 'flex'],
318
- }, showTooltip: true, toolTip: "".concat(remainingTokensFormat(bond), " ").concat(bond.payoutTokenName, " (").concat(formatDollar({
319
- num: remainingTokensUsd(bond).toNumber(),
320
- isPrice: true,
321
- }), ")") }) })), _jsx(Flex, __assign({ className: "column column-hotbond" }, { children: _jsx(Flex, __assign({ className: "column column-icon" }, { children: hotBonds.includes(bond.billAddress.toLowerCase()) && ((_e = bond.discount) !== null && _e !== void 0 ? _e : 0) > 0 && (_jsx(Svg, { icon: "hot", width: "20px" })) })) }))] }))] }), bond.billAddress));
337
+ return (_jsxs(ThemeUIProvider, __assign({ theme: defaultTheme }, { children: [isActive && account && _jsx("p", { children: account }), isActive && account && _jsx("button", __assign({ onClick: handleApprove }, { children: "Approve USDT" })), _jsxs(Flex, __assign({ className: "container table-container" }, { children: [_jsxs(Flex, __assign({ className: "container header-container" }, { children: [_jsxs(Flex, __assign({ className: "column column-tokens" }, { children: [_jsx(Flex, __assign({ className: "column column-tokenname" }, { children: "Tokens" })), _jsx(Flex, { className: "column column-tokenicons" })] })), _jsxs(Flex, __assign({ className: "column column-bondinfo" }, { children: [_jsx(Flex, __assign({ className: "column column-discount" }, { children: _jsxs(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.Discount }), width: "230px", placement: "bottomLeft", transformTip: "translate(18%, -4%)" }, { children: ["Discount", _jsx(Flex, __assign({ className: "column header-icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) }))] })) })), _jsx(Flex, __assign({ className: "column column-arr" }, { children: _jsxs(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.ARR }), width: "230px", placement: "bottomLeft", transformTip: "translate(8%, -5%)" }, { children: ["ARR", _jsx(Flex, __assign({ className: "column header-icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) }))] })) })), _jsx(Flex, __assign({ className: "column column-term" }, { children: _jsxs(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.Terms }), width: "230px", placement: "bottomRight", transformTip: "translate(11%, -5%)" }, { children: ["Terms", _jsx(Flex, __assign({ className: "column header-icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) }))] })) })), _jsx(Flex, __assign({ className: "column column-tokensremaining" }, { children: _jsxs(TooltipBubble, __assign({ body: _jsx(Flex, { children: TooltipText.TokensRemaining }), width: "230px", placement: "bottomRight", transformTip: "translate(12%, -4%)" }, { children: ["Tokens Remaining", _jsx(Flex, __assign({ className: "column header-icon" }, { children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) }))] })) })), _jsx(Flex, { className: "column column-hotbond" })] }))] })), userOwnedBillsData.flat().map(function (data) {
338
+ return data.userOwnedBills.map(function (bill) {
339
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
340
+ 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, __assign({ className: "column column-tokenicons" }, { children: _jsx(TooltipBubble, __assign({ body: _jsx(Tooltip, { tokenContract: ((_a = bill.bond) === null || _a === void 0 ? void 0 : _a.payoutToken) || '', secondURL: getBillContractURL(bill.bond), secondURLTitle: 'View Bond Contract', thirdURL: "https://dashboard.ape.bond/bond/".concat((_c = (_b = bill.bond) === null || _b === void 0 ? void 0 : _b.billAddress) === null || _c === void 0 ? void 0 : _c.toLowerCase()), thirdURLTitle: 'View Insights', twitter: (_d = bill.bond) === null || _d === void 0 ? void 0 : _d.twitter, projectLink: (_e = bill.bond) === null || _e === void 0 ? void 0 : _e.projectLink, audit: (_f = bill.bond) === null || _f === void 0 ? void 0 : _f.audit, chain: (_g = bill.bond.chainId) !== null && _g !== void 0 ? _g : ChainId.BSC }), width: "205px", placement: "bottomRight", transformTip: "translate(11%, 0%)" }, { children: _jsx(Svg, { icon: "more", width: "20px" }) })) }))] })), _jsxs(Flex, __assign({ className: "column column-bondinfo" }, { children: [_jsx(Flex, __assign({ className: "column column-discount ".concat(getDiscountColor((_h = bill.bond) === null || _h === void 0 ? void 0 : _h.discount)) }, { children: "".concat((_k = (_j = bill.bond) === null || _j === void 0 ? void 0 : _j.discount) === null || _k === void 0 ? void 0 : _k.toFixed(2), "%") })), _jsx(Flex, __assign({ className: "column column-arr" }, { children: "".concat(((((_m = (_l = bill.bond) === null || _l === void 0 ? void 0 : _l.discount) !== null && _m !== void 0 ? _m : 0) * 365) / vestingTime(bill.bond.vestingTerm).days).toFixed(2), "%") })), _jsx(Flex, __assign({ className: "column column-term" }, { children: vestingTime(bill.bond.vestingTerm).days ? "".concat(vestingTime(bill.bond.vestingTerm).days, " D") : '-' })), _jsx(Flex, __assign({ className: "column column-tokensremaining" }, { children: _jsx(ProgressBarWrapper, { title: '', value: _jsx(ProgressBar, { value: remainingPercentage(bill.bond) }), style: {
341
+ width: '127px',
342
+ height: '25px',
343
+ flexDirection: 'column',
344
+ justifyContent: 'center',
345
+ display: ['none', 'none', 'none', 'flex'],
346
+ }, showTooltip: true, toolTip: "".concat(remainingTokensFormat(bill.bond), " ").concat(bill.bond.payoutTokenName, " (").concat(formatDollar({
347
+ num: remainingTokensUsd(bill.bond).toNumber(),
348
+ isPrice: true,
349
+ }), ")") }) })), _jsx(Flex, __assign({ className: "column column-hotbond" }, { children: _jsx(Flex, __assign({ className: "column column-icon" }, { children: hotBonds.includes(bill.bond.billAddress.toLowerCase()) && ((_o = bill.bond.discount) !== null && _o !== void 0 ? _o : 0) > 0 && (_jsx(Svg, { icon: "hot", width: "20px" })) })) }))] }))] }), bill.bond.billAddress));
350
+ });
322
351
  })] }))] })));
323
352
  };
324
353
  export default YourBonds;
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.273",
6
+ "version": "1.0.275",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.es.js",
9
9
  "types": "dist/index.d.ts",