@ape.swap/bonds-sdk 1.0.308 → 1.0.310

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,35 +1,13 @@
1
1
  /** @jsxImportSource theme-ui */
2
2
  import React from 'react';
3
- import { BondsDataResponse } from '../../types/bonds';
4
3
  import '../../scss/YourBonds.scss';
5
4
  declare global {
6
5
  interface Window {
7
6
  ethereum?: any;
8
7
  }
9
8
  }
10
- interface BondsProps {
9
+ interface YourBondsProps {
11
10
  connectionString?: string;
12
11
  }
13
- export interface UserBill {
14
- address: string;
15
- id: string;
16
- vesting: string;
17
- payout: string;
18
- totalPayout?: string;
19
- truePricePaid: string;
20
- lastBlockTimestamp: string;
21
- pendingRewards: string;
22
- billNftAddress: string;
23
- nftData?: UserBillNft;
24
- bond: BondsDataResponse;
25
- }
26
- export interface UserBillNft {
27
- image: string;
28
- tokenId: string;
29
- attributes: {
30
- trait_type: string;
31
- value: string;
32
- }[];
33
- }
34
- declare const YourBonds: React.FC<BondsProps>;
12
+ declare const YourBonds: React.FC<YourBondsProps>;
35
13
  export default YourBonds;
@@ -47,9 +47,8 @@ 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 { useCallback, useEffect, useState } from 'react';
50
+ import { useEffect, useState } from 'react';
51
51
  import { Flex, ThemeUIProvider } from 'theme-ui';
52
- import axios from 'axios';
53
52
  import { ethers } from 'ethers';
54
53
  import { useWeb3React } from '@web3-react/core';
55
54
  import { useSearchParams, useNavigate } from 'react-router-dom';
@@ -57,7 +56,7 @@ import getTimePeriods from '../../utils/getTimePeriods';
57
56
  import { defaultTheme } from '../../theme';
58
57
  import '../../scss/YourBonds.scss';
59
58
  import { BigNumber } from 'bignumber.js';
60
- import { BillVersion, ChainId } from '../../enum/apeswaplists';
59
+ import { BillVersion } from '../../enum/apeswaplists';
61
60
  import { Text, Button } from '../uikit-sdk';
62
61
  import { MAINNET_CHAINS } from '../../config/constants/chains';
63
62
  import TokenInfoAndName from '../TokenInfoAndName';
@@ -113,58 +112,48 @@ var YourBonds = function (_a) {
113
112
  }
114
113
  });
115
114
  }); };
116
- var _d = useState([]), bondData = _d[0], setBondData = _d[1];
117
- var _e = useState([]), hotBonds = _e[0], setHotBonds = _e[1];
118
- var vestingTime = function (vestingTerm) {
119
- return getTimePeriods(vestingTerm !== null && vestingTerm !== void 0 ? vestingTerm : 0, true);
120
- };
121
- var currentTime = useCurrentTime() / 1000;
122
- var vestingTimeRemaining = function (userBill) {
123
- return getTimePeriods(parseInt(userBill.lastBlockTimestamp) + parseInt(userBill.vesting) - currentTime, true);
124
- };
125
- useEffect(function () {
126
- axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
127
- var bonds = response.data.bonds.filter(function (bond) { return !isSoldOut(bond); });
128
- setBondData(bonds);
129
- });
130
- }, []);
131
- useEffect(function () {
132
- axios.get('https://apeswap-strapi.herokuapp.com/hot-bonds').then(function (response) {
133
- var hotBondAddresses = response.data.map(function (bond) {
134
- return bond.BondAddress.toLowerCase();
135
- });
136
- setHotBonds(hotBondAddresses);
137
- });
138
- }, []);
139
- var isSoldOut = useCallback(function (bond) {
140
- var _a, _b;
141
- var thresholdToHide = new BigNumber(100).div((_a = bond.payoutTokenPrice) !== null && _a !== void 0 ? _a : 0);
142
- if (bond.soldOut)
143
- return true;
144
- if (bond.discount == null)
145
- return true;
146
- if (!bond.tokensRemaining)
147
- return false;
148
- if (bond.discount && bond.discount > 25 && bond.chainId === ChainId.BASE /*BASE*/)
149
- return true;
150
- return ((_b = new BigNumber(bond.tokensRemaining)) === null || _b === void 0 ? void 0 : _b.lte(thresholdToHide)) || bond.discount === 100;
151
- }, []);
152
- var sortedBonds = bondData.sort(function (a, b) {
153
- var _a, _b;
154
- var aIsHot = hotBonds.includes(a.billAddress.toLowerCase()) && ((_a = a.discount) !== null && _a !== void 0 ? _a : 0) > 0;
155
- var bIsHot = hotBonds.includes(b.billAddress.toLowerCase()) && ((_b = b.discount) !== null && _b !== void 0 ? _b : 0) > 0;
156
- if (aIsHot && !bIsHot) {
157
- return -1;
158
- }
159
- else if (!aIsHot && bIsHot) {
160
- return 1;
161
- }
162
- else {
163
- return b.discount - a.discount;
164
- }
165
- });
166
- var _f = useState(false), isModalOpen = _f[0], setIsModalOpen = _f[1];
167
- var _g = useState(null), selectedBond = _g[0], setSelectedBond = _g[1];
115
+ // const [hotBonds, setHotBonds] = useState<string[]>([]);
116
+ // const vestingTime = (vestingTerm: number) => {
117
+ // return getTimePeriods(vestingTerm ?? 0, true);
118
+ // }
119
+ // useEffect(() => {
120
+ // axios.get('https://realtime-api.ape.bond/bonds').then((response) => {
121
+ // const bonds = response.data.bonds.filter((bond: BondsDataResponse) => !isSoldOut(bond));
122
+ // setBondData(bonds);
123
+ // })
124
+ // }, []);
125
+ // useEffect(() => {
126
+ // axios.get('https://apeswap-strapi.herokuapp.com/hot-bonds').then((response) => {
127
+ // const hotBondAddresses = response.data.map((bond: { BondAddress: string }) =>
128
+ // bond.BondAddress.toLowerCase(),
129
+ // );
130
+ // setHotBonds(hotBondAddresses);
131
+ // })
132
+ // }, []);
133
+ // const isSoldOut = useCallback((bond: BondsDataResponse) => {
134
+ // const thresholdToHide = new BigNumber(100).div(bond.payoutTokenPrice ?? 0);
135
+ // if (bond.soldOut) return true;
136
+ // if (bond.discount == null) return true;
137
+ // if (!bond.tokensRemaining) return false;
138
+ // if (bond.discount && bond.discount > 25 && bond.chainId === ChainId.BASE /*BASE*/) return true;
139
+ // return new BigNumber(bond.tokensRemaining)?.lte(thresholdToHide) || bond.discount === 100;
140
+ // }, []);
141
+ // const sortedBonds = bondData.sort((a, b) => {
142
+ // const aIsHot = hotBonds.includes(a.billAddress.toLowerCase()) && (a.discount ?? 0) > 0;
143
+ // const bIsHot = hotBonds.includes(b.billAddress.toLowerCase()) && (b.discount ?? 0) > 0;
144
+ // if (aIsHot && !bIsHot) {
145
+ // return -1;
146
+ // }
147
+ // else if (!aIsHot && bIsHot) {
148
+ // return 1;
149
+ // }
150
+ // else {
151
+ // return b.discount - a.discount;
152
+ // }
153
+ // });
154
+ var _d = useState(false), isModalOpen = _d[0], setIsModalOpen = _d[1];
155
+ var _e = useState(null), selectedBond = _e[0], setSelectedBond = _e[1];
156
+ var _f = useState([]), bondData = _f[0], setBondData = _f[1];
168
157
  var rowClick = function (bond) {
169
158
  setSelectedBond(bond);
170
159
  setIsModalOpen(true);
@@ -180,6 +169,10 @@ var YourBonds = function (_a) {
180
169
  // }
181
170
  // }, [account, slowRefresh])
182
171
  // }
172
+ var currentTime = useCurrentTime() / 1000;
173
+ var vestingTimeRemaining = function (userBill) {
174
+ return getTimePeriods(parseInt(userBill.lastBlockTimestamp) + parseInt(userBill.vesting) - currentTime, true);
175
+ };
183
176
  var fetchUserOwnedBillsDataAsync = function (chainId, account) { return __awaiter(void 0, void 0, void 0, function () {
184
177
  var bonds, userOwnedBills_1, mapUserOwnedBills_1, userOwnedBillsData_1, error_2;
185
178
  return __generator(this, function (_a) {
@@ -211,7 +204,7 @@ var YourBonds = function (_a) {
211
204
  }
212
205
  });
213
206
  }); };
214
- var _h = useState([]), userOwnedBillsData = _h[0], setUserOwnedBillsData = _h[1];
207
+ var _g = useState([]), userOwnedBillsData = _g[0], setUserOwnedBillsData = _g[1];
215
208
  useEffect(function () {
216
209
  var fetchData = function () { return __awaiter(void 0, void 0, void 0, function () {
217
210
  var results, error_3;
@@ -226,7 +219,6 @@ var YourBonds = function (_a) {
226
219
  case 2:
227
220
  results = _a.sent();
228
221
  setUserOwnedBillsData(results);
229
- console.log('User owned bills data:', results);
230
222
  return [3 /*break*/, 4];
231
223
  case 3:
232
224
  error_3 = _a.sent();
@@ -316,12 +308,8 @@ var YourBonds = function (_a) {
316
308
  }); };
317
309
  var chainId = useWeb3React().chainId;
318
310
  var totalPending = function (userBill) {
319
- var _a, _b, _c, _d, _e, _f;
320
- console.log(userBill);
321
- console.log('CHAINID)');
322
- console.log((_b = (_a = userBill.bond.earnToken) === null || _a === void 0 ? void 0 : _a.decimals) === null || _b === void 0 ? void 0 : _b[chainId]);
323
- console.log(userBill.payout);
324
- return getBalanceNumber(new BigNumber((_c = userBill === null || userBill === void 0 ? void 0 : userBill.payout) !== null && _c !== void 0 ? _c : 0), (_f = (_e = (_d = userBill.bond.earnToken) === null || _d === void 0 ? void 0 : _d.decimals) === null || _e === void 0 ? void 0 : _e[chainId]) !== null && _f !== void 0 ? _f : 18);
311
+ var _a, _b, _c, _d;
312
+ return getBalanceNumber(new BigNumber((_a = userBill === null || userBill === void 0 ? void 0 : userBill.payout) !== 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);
325
313
  };
326
314
  var claimable = function (userBill) {
327
315
  var _a, _b, _c;
@@ -338,7 +326,14 @@ var YourBonds = function (_a) {
338
326
  fontWeight: 600,
339
327
  width: '100%',
340
328
  } }, { children: "Claim All" })) }))] }))] })), userOwnedBillsData.flat().map(function (data) {
341
- return data.userOwnedBills.map(function (bill) {
329
+ var sortedBills = data.userOwnedBills.sort(function (a, b) {
330
+ var claimableDifference = claimable(b) - claimable(a);
331
+ if (claimableDifference !== 0) {
332
+ return claimableDifference;
333
+ }
334
+ return totalPending(b) - totalPending(a);
335
+ });
336
+ return sortedBills.map(function (bill) {
342
337
  var _a, _b;
343
338
  return (_jsxs(Flex, __assign({ className: "container bondrow-container", onClick: function () { return rowClick(bill.bond); } }, { children: [_jsx(Flex, __assign({ className: "column column-tokens" }, { children: _jsx(Flex, __assign({ className: "column column-tokeninfoname" }, { children: _jsx(TokenInfoAndName, { bill: bill.bond, vestEnds: "Ends in ".concat(getPendingVesting(bill.lastBlockTimestamp, bill.vesting)) }) })) })), _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: {
344
339
  height: ['36px', '36px', '36px', '26px'],
@@ -0,0 +1,26 @@
1
+ import { BondsDataResponse } from "./bonds";
2
+ export interface UserOwnedBillsData {
3
+ index: number;
4
+ userOwnedBills: UserBill[];
5
+ }
6
+ export interface UserBill {
7
+ address: string;
8
+ id: string;
9
+ vesting: string;
10
+ payout: string;
11
+ totalPayout?: string;
12
+ truePricePaid: string;
13
+ lastBlockTimestamp: string;
14
+ pendingRewards: string;
15
+ billNftAddress: string;
16
+ nftData?: UserBillNft;
17
+ bond: BondsDataResponse;
18
+ }
19
+ export interface UserBillNft {
20
+ image: string;
21
+ tokenId: string;
22
+ attributes: {
23
+ trait_type: string;
24
+ value: string;
25
+ }[];
26
+ }
@@ -0,0 +1 @@
1
+ export {};
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.308",
6
+ "version": "1.0.310",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.es.js",
9
9
  "types": "dist/index.d.ts",