@ape.swap/bonds-sdk 1.0.343 → 1.0.345

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.
@@ -45,6 +45,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
+ if (ar || !(i in from)) {
51
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
+ ar[i] = from[i];
53
+ }
54
+ }
55
+ return to.concat(ar || Array.prototype.slice.call(from));
56
+ };
48
57
  import { jsx as _jsx, jsxs as _jsxs } from "theme-ui/jsx-runtime";
49
58
  /** @jsxImportSource theme-ui */
50
59
  import { useEffect, useState } from 'react';
@@ -69,7 +78,7 @@ import { formatNumberSI } from '../../utils/formatNumber';
69
78
  import useCurrentTime from '../../hooks/useTimer';
70
79
  import { getPendingVesting } from '../../hooks/usePendingVesting';
71
80
  import axios from 'axios';
72
- import { usePollUserBills } from '../../state/bills/hooks';
81
+ import { fetchUserOwnedBillNftData } from './fetchBillsUser';
73
82
  var YourBonds = function (_a) {
74
83
  var connectionString = _a.connectionString;
75
84
  var _b = useWeb3React(), account = _b.account, isActive = _b.isActive;
@@ -176,33 +185,56 @@ var YourBonds = function (_a) {
176
185
  return getTimePeriods(parseInt(userBill.lastBlockTimestamp) + parseInt(userBill.vesting) - currentTime, true);
177
186
  };
178
187
  var fetchUserOwnedBillsDataAsync = function (chainId, account) { return __awaiter(void 0, void 0, void 0, function () {
179
- var bonds, userOwnedBills_1, mapUserOwnedBills_1, userOwnedBillsData_1, error_2;
188
+ var bonds_1, userOwnedBills_1, mapUserOwnedBills_1, userOwnedBillsData_1, ownedBillsData, userBillNftData_1, ownedBillsWithNftData, error_2;
180
189
  return __generator(this, function (_a) {
181
190
  switch (_a.label) {
182
191
  case 0:
183
- _a.trys.push([0, 2, , 3]);
184
- bonds = bondData.filter(function (bond) {
192
+ _a.trys.push([0, 3, , 4]);
193
+ bonds_1 = bondData.filter(function (bond) {
185
194
  return bond.billVersion !== BillVersion.FixedPrice &&
186
195
  (bond === null || bond === void 0 ? void 0 : bond.chainId) === chainId &&
187
196
  bond.type !== 'migration' &&
188
197
  bond.billAddress.toLowerCase() !== ACF_TO_ABOND.toLowerCase();
189
198
  });
190
- return [4 /*yield*/, fetchUserOwnedBills(chainId, account, bonds)];
199
+ return [4 /*yield*/, fetchUserOwnedBills(chainId, account, bonds_1)];
191
200
  case 1:
192
201
  userOwnedBills_1 = _a.sent();
193
- mapUserOwnedBills_1 = bonds.map(function (bill) {
202
+ mapUserOwnedBills_1 = bonds_1.map(function (bill) {
194
203
  return userOwnedBills_1.filter(function (b) { return b.address.toLowerCase() === bill.billAddress.toLowerCase(); });
195
204
  });
196
- userOwnedBillsData_1 = bonds.map(function (bill, i) { return ({
205
+ userOwnedBillsData_1 = bonds_1.map(function (bill, i) { return ({
197
206
  index: bill.index,
198
207
  userOwnedBills: mapUserOwnedBills_1[i],
199
208
  }); });
200
- return [2 /*return*/, Promise.resolve(userOwnedBillsData_1)];
209
+ ownedBillsData = mapUserOwnedBills_1.flatMap(function (bs) {
210
+ return bs.map(function (b) {
211
+ return { id: b.id, billNftAddress: b.billNftAddress, contractAddress: b.address };
212
+ });
213
+ });
214
+ return [4 /*yield*/, fetchUserOwnedBillNftData(ownedBillsData, chainId, bonds_1)];
201
215
  case 2:
216
+ userBillNftData_1 = _a.sent();
217
+ ownedBillsWithNftData = mapUserOwnedBills_1.map(function (bs, index) {
218
+ return {
219
+ index: bonds_1[index].index,
220
+ userOwnedBillsNfts: __spreadArray([], bs.map(function (b) {
221
+ var _a;
222
+ return (_a = userBillNftData_1.find(function (nftB) { return parseInt(nftB.id) === b.data.billNftId; })) === null || _a === void 0 ? void 0 : _a.data;
223
+ }), true),
224
+ };
225
+ });
226
+ console.log("ownedBillsWithNftData");
227
+ console.log(ownedBillsWithNftData);
228
+ console.log("ownedBillsWithNftData");
229
+ console.log("userOwnedBillsData");
230
+ console.log(userOwnedBillsData_1);
231
+ console.log("userOwnedBillsData");
232
+ return [2 /*return*/, Promise.resolve(userOwnedBillsData_1)];
233
+ case 3:
202
234
  error_2 = _a.sent();
203
235
  console.error('Error fetching user owned bills data:', error_2);
204
236
  return [2 /*return*/, Promise.reject(error_2)];
205
- case 3: return [2 /*return*/];
237
+ case 4: return [2 /*return*/];
206
238
  }
207
239
  });
208
240
  }); };
@@ -321,10 +353,6 @@ var YourBonds = function (_a) {
321
353
  var _a;
322
354
  return getFirstNonZeroDigits(parseFloat((_a = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _a !== void 0 ? _a : '0'));
323
355
  };
324
- var bills = usePollUserBills();
325
- console.log("USERBILLS");
326
- console.log(bills);
327
- console.log("USERBILLS");
328
356
  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: [_jsx(Flex, __assign({ className: "column column-tokens" }, { children: _jsx(Flex, { className: "column column-tokeninfoname" }) })), _jsxs(Flex, __assign({ className: "column column-bondinfo" }, { children: [_jsx(Flex, __assign({ className: "column column-claimable" }, { children: _jsx(Text, { children: "Claimable" }) })), _jsx(Flex, __assign({ className: "column column-pending" }, { children: _jsx(Text, { children: "Pending" }) })), _jsx(Flex, __assign({ className: "column column-term" }, { children: _jsx(Text, { children: "Terms" }) })), _jsx(Flex, __assign({ className: "column column-claimall" }, { children: _jsx(Button, __assign({ disabled: !account, sx: {
329
357
  height: ['36px', '36px', '36px', '26px'],
330
358
  lineHeight: '12px',
@@ -1,4 +1,4 @@
1
- import { Bills, CleanedBondsState, UserBill } from '../../types/bonds';
1
+ import { BondsDataResponse, CleanedBondsState, UserBill } from '../../types/bonds';
2
2
  import { ChainId } from '../../enum/apeswaplists';
3
3
  /**
4
4
  * Fetches user-owned bill NFT data for a given set of owned bills data, chain ID, and bills.
@@ -11,5 +11,5 @@ export declare const fetchUserOwnedBillNftData: (ownedBillsData: {
11
11
  id: string;
12
12
  billNftAddress: string;
13
13
  contractAddress: string;
14
- }[], chainId: ChainId, bills: (CleanedBondsState | Bills)[]) => Promise<any[]>;
14
+ }[], chainId: ChainId, bills: BondsDataResponse[]) => Promise<any[]>;
15
15
  export declare const fetchUserOwnedBills: (chainId: ChainId, account: string, bills: CleanedBondsState[]) => Promise<UserBill[]>;
@@ -55,10 +55,10 @@ export var fetchUserOwnedBillNftData = function (ownedBillsData, chainId, bills)
55
55
  billsFetched = [];
56
56
  // Loop through each owned bill and check if it exists in the bills array
57
57
  ownedBillsData === null || ownedBillsData === void 0 ? void 0 : ownedBillsData.forEach(function (_a) {
58
- var _b, _c;
59
58
  var id = _a.id, billNftAddress = _a.billNftAddress, contractAddress = _a.contractAddress;
60
- var bill = (_c = (_b = bills
61
- .find(function (b) { return b.contractAddress[chainId] === contractAddress; })) === null || _b === void 0 ? void 0 : _b.userOwnedBillsNftData) === null || _c === void 0 ? void 0 : _c.find(function (u) { return +u.tokenId === +id; });
59
+ var bill = bills
60
+ .find(function (b) { return b.billAddress[chainId] === contractAddress; });
61
+ // ?.userOwnedBillsNftData?.find((u) => +u.tokenId === +id)
62
62
  // If the bill exists in the bills array, add it to the billsFetched array
63
63
  if (bill) {
64
64
  billsFetched.push({ id: id, data: bill });
@@ -46,6 +46,65 @@ export interface UserBillNft {
46
46
  value: string;
47
47
  }[];
48
48
  }
49
+ export interface UserBillNftData {
50
+ name: string;
51
+ description: string;
52
+ tokenId: number;
53
+ image: string;
54
+ attributes: {
55
+ trait_type: string;
56
+ value: string;
57
+ }[];
58
+ data: {
59
+ billContract: string;
60
+ billNftAddress: string;
61
+ payout: number;
62
+ deposit: number;
63
+ createTransactionHash: string;
64
+ billNftId: number;
65
+ expires: number;
66
+ vestingPeriodSeconds: number;
67
+ payoutToken: string;
68
+ principalToken: string;
69
+ type: string;
70
+ pairName: string;
71
+ payoutTokenData: {
72
+ address: string;
73
+ name: string;
74
+ symbol: string;
75
+ decimals: {
76
+ [chainId: number]: number;
77
+ };
78
+ };
79
+ token0: {
80
+ address: string;
81
+ symbol: string;
82
+ name: string;
83
+ decimals: {
84
+ [chainId: number]: number;
85
+ };
86
+ };
87
+ token1: {
88
+ address: string;
89
+ symbol: string;
90
+ name: string;
91
+ decimals: {
92
+ [chainId: number]: number;
93
+ };
94
+ };
95
+ dollarValue: number;
96
+ chainId: ChainId;
97
+ blockNumber: number;
98
+ bondArtCollection: string;
99
+ bondPartner: string;
100
+ bondVersion: string;
101
+ createdAddressOwner: string;
102
+ createdAt: number;
103
+ payoutTokenPrice: string;
104
+ };
105
+ contractAddress: string;
106
+ chainId: ChainId;
107
+ }
49
108
  export interface UserBill {
50
109
  address: string;
51
110
  id: string;
@@ -3,6 +3,10 @@ export interface UserOwnedBillsData {
3
3
  index: number;
4
4
  userOwnedBills: UserBill[];
5
5
  }
6
+ export interface ownedBillsWithNftData {
7
+ index: number;
8
+ userOwnedBillsNfts: any[];
9
+ }
6
10
  export interface UserBill {
7
11
  address: string;
8
12
  id: string;
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.343",
6
+ "version": "1.0.345",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.es.js",
9
9
  "types": "dist/index.d.ts",