@ape.swap/bonds-sdk 1.0.542 → 1.0.544

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.
@@ -64,43 +64,61 @@ import { getPendingVesting } from '../../hooks/usePendingVesting';
64
64
  import axios from 'axios';
65
65
  import { fetchUserOwnedBillsDataAsync } from './fetchBillsUser';
66
66
  import { Input } from '../../components/uikit-sdk/Input';
67
- import useClaimBill from '../../hooks/useClaimBill';
68
67
  import { YourBondsModal } from "../../index";
68
+ import { adjustDecimals } from '../../utils/convertToTokenValue';
69
+ import BOND_ABI from '../../config/abi/bond.json';
69
70
  var YourBonds = function (_a) {
70
71
  //const toastError = useToastError()
71
72
  // const { onClaimBill } = useClaimBill(billAddress, billIds)
72
73
  var account = _a.account, accountChainId = _a.accountChainId, isActive = _a.isActive;
73
- var _b = useState(false), pendingTrx = _b[0], setPendingTrx = _b[1];
74
- var handleClaim = function (billAddress, billIds, chainId, event) { return __awaiter(void 0, void 0, void 0, function () {
75
- var onClaimBill;
74
+ // const [pendingTrx, setPendingTrx] = useState(false)
75
+ // const handleClaim = async (billAddress: string, billIds: string[], chainId: number, event: any) => {
76
+ // event?.stopPropagation();
77
+ // console.log('CLAIM CLICKED');
78
+ // console.log(account);
79
+ // if (!account) return;
80
+ // const { onClaimBill } = useClaimBill(billAddress, billIds, chainId);
81
+ // setPendingTrx(true);
82
+ // await onClaimBill().catch((e) => {
83
+ // console.error(e);
84
+ // //toastError(e);
85
+ // setPendingTrx(false);
86
+ // });
87
+ // setPendingTrx(false);
88
+ // };
89
+ var handleClaim = function () { return __awaiter(void 0, void 0, void 0, function () {
90
+ var tokenAddress, tx, error_1;
76
91
  return __generator(this, function (_a) {
77
92
  switch (_a.label) {
78
93
  case 0:
79
- event === null || event === void 0 ? void 0 : event.stopPropagation();
80
- console.log('CLAIM CLICKED');
81
- console.log(account);
82
- if (!account)
83
- return [2 /*return*/];
84
- onClaimBill = useClaimBill(billAddress, billIds, chainId).onClaimBill;
85
- setPendingTrx(true);
86
- return [4 /*yield*/, onClaimBill().catch(function (e) {
87
- console.error(e);
88
- //toastError(e);
89
- setPendingTrx(false);
90
- })];
94
+ tokenAddress = bondData[0].billAddress;
95
+ _a.label = 1;
91
96
  case 1:
92
- _a.sent();
93
- setPendingTrx(false);
94
- return [2 /*return*/];
97
+ _a.trys.push([1, 3, , 4]);
98
+ return [4 /*yield*/, writeContract({
99
+ address: tokenAddress,
100
+ abi: BOND_ABI,
101
+ functionName: 'redeem',
102
+ args: [account, adjustDecimals(inputValue)],
103
+ })];
104
+ case 2:
105
+ tx = _a.sent();
106
+ console.log('Transaction:', tx);
107
+ return [3 /*break*/, 4];
108
+ case 3:
109
+ error_1 = _a.sent();
110
+ console.error('Approval failed:', error_1);
111
+ return [3 /*break*/, 4];
112
+ case 4: return [2 /*return*/];
95
113
  }
96
114
  });
97
115
  }); };
98
116
  // const { account, isActive } = useWeb3React();
99
- var _c = useSearchParams(), searchParams = _c[0], setSearchParams = _c[1];
117
+ var _b = useSearchParams(), searchParams = _b[0], setSearchParams = _b[1];
100
118
  var navigate = useNavigate();
101
119
  // Fetch data
102
- var _d = useState([]), bondData = _d[0], setBondData = _d[1];
103
- var _e = useState([]), mappedUserBills = _e[0], setMappedUserBills = _e[1];
120
+ var _c = useState([]), bondData = _c[0], setBondData = _c[1];
121
+ var _d = useState([]), mappedUserBills = _d[0], setMappedUserBills = _d[1];
104
122
  useEffect(function () {
105
123
  axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
106
124
  var bonds = response.data.bonds;
@@ -109,7 +127,7 @@ var YourBonds = function (_a) {
109
127
  }, []);
110
128
  useEffect(function () {
111
129
  var fetchData = function () { return __awaiter(void 0, void 0, void 0, function () {
112
- var results, mappedBills, error_1;
130
+ var results, mappedBills, error_2;
113
131
  return __generator(this, function (_a) {
114
132
  switch (_a.label) {
115
133
  case 0:
@@ -125,8 +143,8 @@ var YourBonds = function (_a) {
125
143
  console.log('User owned bills data:', mappedBills);
126
144
  return [3 /*break*/, 4];
127
145
  case 3:
128
- error_1 = _a.sent();
129
- console.error('Error fetching user owned bills data:', error_1);
146
+ error_2 = _a.sent();
147
+ console.error('Error fetching user owned bills data:', error_2);
130
148
  return [3 /*break*/, 4];
131
149
  case 4: return [2 /*return*/];
132
150
  }
@@ -134,8 +152,8 @@ var YourBonds = function (_a) {
134
152
  }); };
135
153
  fetchData();
136
154
  }, [account, bondData]);
137
- var _f = useState(null), sortConfig = _f[0], setSortConfig = _f[1];
138
- var _g = useState(mappedUserBills), sortedBonds = _g[0], setSortedBonds = _g[1];
155
+ var _e = useState(null), sortConfig = _e[0], setSortConfig = _e[1];
156
+ var _f = useState(mappedUserBills), sortedBonds = _f[0], setSortedBonds = _f[1];
139
157
  var handleSort = function (key) {
140
158
  var direction = 'asc';
141
159
  if ((sortConfig === null || sortConfig === void 0 ? void 0 : sortConfig.key) === key && (sortConfig === null || sortConfig === void 0 ? void 0 : sortConfig.direction) === 'asc') {
@@ -216,8 +234,8 @@ var YourBonds = function (_a) {
216
234
  return getFirstNonZeroDigits(parseFloat((_a = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _a !== void 0 ? _a : '0'));
217
235
  };
218
236
  // Modal
219
- var _h = useState(false), isModalOpen = _h[0], setIsModalOpen = _h[1];
220
- var _j = useState(undefined), selectedBill = _j[0], setSelectedBill = _j[1];
237
+ var _g = useState(false), isModalOpen = _g[0], setIsModalOpen = _g[1];
238
+ var _h = useState(undefined), selectedBill = _h[0], setSelectedBill = _h[1];
221
239
  var rowClick = function (bill) {
222
240
  console.log(bill);
223
241
  setSelectedBill(bill);
@@ -225,8 +243,8 @@ var YourBonds = function (_a) {
225
243
  // navigate(`/yourBonds/?bondAddress=${bill.address}&bondChain=${bill.bond.chainId}`, { replace: true });
226
244
  };
227
245
  // Search logic
228
- var _k = useState(''), inputValue = _k[0], setInputValue = _k[1];
229
- var _l = useState(sortedBonds), filteredBonds = _l[0], setFilteredBonds = _l[1];
246
+ var _j = useState(''), inputValue = _j[0], setInputValue = _j[1];
247
+ var _k = useState(sortedBonds), filteredBonds = _k[0], setFilteredBonds = _k[1];
230
248
  useEffect(function () {
231
249
  if (inputValue === '') {
232
250
  setFilteredBonds(sortedBonds);
@@ -241,7 +259,7 @@ var YourBonds = function (_a) {
241
259
  setInputValue(event.target.value);
242
260
  };
243
261
  // Page render logic
244
- var _m = useState(false), bondsRendered = _m[0], setBondsRendered = _m[1];
262
+ var _l = useState(false), bondsRendered = _l[0], setBondsRendered = _l[1];
245
263
  useEffect(function () {
246
264
  if (filteredBonds.length > 0) {
247
265
  setBondsRendered(true);
@@ -254,9 +272,9 @@ var YourBonds = function (_a) {
254
272
  _jsx(YourBondsModal, { isOpen: true, onClose: closeModal, userBill: selectedBill }), bondsRendered && (_jsxs(Flex, { className: "container table-container", children: [_jsxs(Flex, { className: "container header-container", children: [_jsx(Flex, { className: "column column-tokens", children: _jsx(Flex, { className: "column column-search", sx: { width: '100%', maxWidth: ['200px', '200px', '200px', '340px'] }, children: _jsx(Input, { value: inputValue, onChange: handleInputChange, variant: "search", sx: { fontWeight: 400, background: 'white2', height: '30px', fontSize: '14px', color: 'white' }, width: '100%', placeholder: 'Search...' }) }) }), _jsxs(Flex, { className: "column column-bondinfo", children: [_jsxs(Flex, { className: "column header-claimable", children: [_jsx(Text, { sx: { fontSize: '11px', color: 'textDisabledButton' }, children: "CLAIMABLE" }), _jsx(Flex, { className: "column header-icon", onClick: function () { return handleSort('claimable'); }, children: _jsx(Svg, { icon: "sort", width: "12px", color: "textDisabledButton" }) })] }), _jsxs(Flex, { className: "column header-pending", children: [_jsx(Text, { sx: { fontSize: '11px', color: 'textDisabledButton' }, children: "PENDING" }), _jsx(Flex, { className: "column header-icon", onClick: function () { return handleSort('pending'); }, children: _jsx(Svg, { icon: "sort", width: "12px", color: "textDisabledButton" }) })] }), _jsxs(Flex, { className: "column header-terms", children: [_jsx(Text, { sx: { fontSize: '11px', color: 'textDisabledButton' }, children: "TERMS" }), _jsx(Flex, { className: "column header-icon", onClick: function () { return handleSort('terms'); }, children: _jsx(Svg, { icon: "sort", width: "12px", color: "textDisabledButton" }) })] }), _jsx(Flex, { className: "column header-claimall" })] })] }), filteredBonds.map(function (bill) {
255
273
  var _a, _b;
256
274
  return (_jsxs(Flex, { className: "container bondrow-container", onClick: function () { return rowClick(bill); }, children: [_jsx(Flex, { className: "column column-tokens", children: _jsx(Flex, { className: "column column-tokeninfoname", children: _jsx(TokenInfoAndName, { bill: bill.bond, vestEnds: "Ends in ".concat(getPendingVesting(bill.lastBlockTimestamp, bill.vesting)) }) }) }), _jsxs(Flex, { className: "column column-bondinfo", children: [_jsxs(Flex, { className: "column column-claimable", children: [formatNumberSI(parseFloat(claimable(bill).toFixed(3)), 0), _jsx(Text, { sx: { opacity: '0.6', fontSize: '12px', paddingLeft: '5px' }, children: "($".concat((claimable(bill) * ((_a = parseFloat(earnTokenPrice(bill.bond))) !== null && _a !== void 0 ? _a : 0)).toFixed(2), ")") })] }), _jsxs(Flex, { className: "column column-pending", children: [formatNumberSI(parseFloat(totalPending(bill).toFixed(0)), 0), _jsx(Text, { sx: { opacity: '0.6', fontSize: '12px', paddingLeft: '5px' }, children: "($".concat((totalPending(bill) * ((_b = parseFloat(earnTokenPrice(bill.bond))) !== null && _b !== void 0 ? _b : 0)).toFixed(2), ")") })] }), _jsx(Flex, { className: "column column-terms", children: "".concat(vestingTimeRemaining(bill).days, "d, ").concat(vestingTimeRemaining(bill).hours, "h, ").concat(vestingTimeRemaining(bill).minutes, "m") }), _jsx(Flex, { className: "column column-claimall", children: _jsx(Button, { disabled: !account && (claimableNumber(bill) === 0), onClick: function (event) {
257
- // event.stopPropagation();
275
+ event.stopPropagation();
258
276
  // Add your claim logic here
259
- handleClaim(bill.bond.billAddress, [bill.id], bill.bond.chainId, event);
277
+ handleClaim;
260
278
  }, sx: {
261
279
  height: ['36px', '36px', '36px', '26px'],
262
280
  lineHeight: '12px',
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.542",
6
+ "version": "1.0.544",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.es.js",
9
9
  "types": "dist/index.d.ts",