@ape.swap/bonds-sdk 4.1.0-test.12 → 4.1.0-test.14

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.
package/dist/main.js CHANGED
@@ -65215,10 +65215,7 @@ function useTokenPrices() {
65215
65215
  const apiv2 = (_b = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.urls) === null || _b === void 0 ? void 0 : _b.apiV2;
65216
65216
  return useQuery({
65217
65217
  queryKey: [QUERY_KEYS.TOKEN_PRICES],
65218
- queryFn: () => __awaiter$9(this, void 0, void 0, function* () {
65219
- const prices = yield getTokenPrices(priceApi, apiv2);
65220
- return prices;
65221
- }),
65218
+ queryFn: () => getTokenPrices(priceApi, apiv2),
65222
65219
  refetchInterval: 30000, // 30 sec
65223
65220
  refetchOnMount: false,
65224
65221
  refetchOnWindowFocus: false,
@@ -65482,7 +65479,6 @@ function fetchUserOwnedSolanaBonds(user, bondData, tokenPrices) {
65482
65479
  if (!user)
65483
65480
  return [];
65484
65481
  try {
65485
- console.log('fetch-SOL-bonds');
65486
65482
  console.time('fetch-SOL-bonds');
65487
65483
  const results = [];
65488
65484
  const userBase58 = new PublicKey(user).toBase58();
@@ -65634,29 +65630,29 @@ const useSOLAccount = () => {
65634
65630
  };
65635
65631
 
65636
65632
  function useUserBonds(dontFetch) {
65637
- var _a, _b, _c;
65633
+ var _a, _b;
65638
65634
  // First fetch the full list of bonds
65639
65635
  const { data: bondList } = useBondsList();
65640
65636
  const { address } = useEVMAccount();
65641
65637
  const { publicKey } = useSOLAccount();
65642
65638
  const solanaAccount = publicKey === null || publicKey === void 0 ? void 0 : publicKey.toBase58();
65643
- const SDKConfig = useSDKConfig();
65644
65639
  const { data: tokenPrices } = useTokenPrices();
65645
- const chains = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.chains;
65646
- const apiUrl = (_a = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.urls) === null || _a === void 0 ? void 0 : _a.apiV2;
65647
- // Once the full list is fetched, fetch user's purchased bonds
65640
+ const queryClient = useQueryClient();
65648
65641
  return useQuery({
65649
- queryKey: [QUERY_KEYS.USER_BONDS, address, publicKey, (_c = (_b = Object.keys(tokenPrices !== null && tokenPrices !== void 0 ? tokenPrices : {})) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : null],
65650
- queryFn: () => getUserBonds(address, solanaAccount, bondList, chains, tokenPrices, apiUrl),
65651
- refetchInterval: 120000, // TODO rollback this
65652
- enabled: !!bondList && !!(address || solanaAccount) && !!tokenPrices && !dontFetch,
65642
+ queryKey: [QUERY_KEYS.USER_BONDS, address, publicKey, (_b = (_a = Object.keys(tokenPrices !== null && tokenPrices !== void 0 ? tokenPrices : {})) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : null],
65643
+ queryFn: () => getUserBonds(address, solanaAccount, bondList, queryClient),
65644
+ refetchInterval: 20000, // TODO rollback this
65645
+ enabled: !!bondList && !!(address || solanaAccount) && !!tokenPrices && true,
65653
65646
  refetchOnWindowFocus: false,
65654
65647
  refetchOnMount: false,
65655
65648
  refetchOnReconnect: false,
65656
65649
  retry: 1,
65657
65650
  });
65658
65651
  }
65659
- const getUserBonds = (account, solanaAccount, bondList, chains, tokenPrices, apiUrl) => __awaiter$9(void 0, void 0, void 0, function* () {
65652
+ const getUserBonds = (account, solanaAccount, bondList, queryClient) => __awaiter$9(void 0, void 0, void 0, function* () {
65653
+ const { chains, urls } = queryClient === null || queryClient === void 0 ? void 0 : queryClient.getQueryData([QUERY_KEYS.SDK_CONFIG]);
65654
+ const apiUrl = urls['apiV2'];
65655
+ const tokenPrices = queryClient === null || queryClient === void 0 ? void 0 : queryClient.getQueryData([QUERY_KEYS.TOKEN_PRICES]);
65660
65656
  try {
65661
65657
  console.time('getUserBonds');
65662
65658
  const bondsByChain = bondList.reduce((acc, bond) => {
@@ -65709,7 +65705,7 @@ const getUserBonds = (account, solanaAccount, bondList, chains, tokenPrices, api
65709
65705
  }, {}));
65710
65706
  let response;
65711
65707
  try {
65712
- response = yield axios.post(`${apiUrl}/bills/multi-batch`, body);
65708
+ response = yield axios.post(`${apiUrl}/bills/multi-batch`, body, { timeout: 40000 });
65713
65709
  }
65714
65710
  catch (e) {
65715
65711
  console.error(e);
@@ -74918,10 +74914,9 @@ const SafeHTMLComponent = ({ html }) => {
74918
74914
  return jsx$2("div", { dangerouslySetInnerHTML: { __html: sanitizedHTML } });
74919
74915
  };
74920
74916
 
74921
- const YourBondsModal = ({ billId, onDismiss }) => {
74917
+ const YourBondsModal = ({ userBill, onDismiss }) => {
74922
74918
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12;
74923
- const { data: userBonds, refetch: refetchUserBonds } = useUserBonds();
74924
- const userBill = userBonds === null || userBonds === void 0 ? void 0 : userBonds.find((bill) => bill.id === billId);
74919
+ const { refetch: refetchUserBonds } = useUserBonds();
74925
74920
  // Hooks
74926
74921
  const SDKConfig = useSDKConfig();
74927
74922
  const chainId = useChainId();
@@ -75189,7 +75184,7 @@ const UserBondRow = ({ bill }) => {
75189
75184
  const { writeContractAsync } = useWriteContract();
75190
75185
  const { addToastError } = usePopups();
75191
75186
  const { refetch: refetchUserBonds } = useUserBonds();
75192
- const [onOpenPurchasedBond] = useModal(jsx$2(YourBondsModal, { billId: bill.id }));
75187
+ const [onOpenPurchasedBond] = useModal(jsx$2(YourBondsModal, { userBill: bill }));
75193
75188
  // State
75194
75189
  const [claimTxHash, setClaimTxHash] = useState(null);
75195
75190
  const { isLoading: isConfirming, isSuccess: isConfirmed } = useMonitorTx(claimTxHash, (_a = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _a === void 0 ? void 0 : _a.chainId);
@@ -75272,20 +75267,19 @@ const UserBondRow = ({ bill }) => {
75272
75267
  : 'Claim' })) })] })] }));
75273
75268
  };
75274
75269
 
75275
- const YourBondsModalSolana = ({ billId, onDismiss }) => {
75270
+ const YourBondsModalSolana = ({ userBill, onDismiss }) => {
75276
75271
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10;
75277
75272
  // Hooks
75278
75273
  const SDKConfig = useSDKConfig();
75279
75274
  const { publicKey: accountSolana, signTransaction } = useSOLAccount();
75280
75275
  const { setVisible } = useWalletModal();
75281
75276
  const { addToastError, addToastSuccess } = usePopups();
75282
- const { data: userBonds, refetch } = useUserBonds();
75277
+ const { refetch } = useUserBonds();
75283
75278
  const connection = new Connection(getRPC(types$1.ChainId.SOL), 'confirmed');
75284
75279
  // State
75285
75280
  const [imgLoaded, setImgLoaded] = useState(false);
75286
75281
  const [loadingTx, setLoadingTx] = useState(false);
75287
75282
  // Static Data
75288
- const userBill = userBonds === null || userBonds === void 0 ? void 0 : userBonds.find((bill) => bill.asset === billId);
75289
75283
  const bondNFTData = userBill === null || userBill === void 0 ? void 0 : userBill.nftData;
75290
75284
  // Cliff display info:
75291
75285
  const vestingCliff = (_a = userBill === null || userBill === void 0 ? void 0 : userBill.bond) === null || _a === void 0 ? void 0 : _a.vestingCliff;
@@ -75460,7 +75454,7 @@ const UserBondRowSolana = ({ bill }) => {
75460
75454
  const lastBlockTimestamp = parseInt((_d = bill === null || bill === void 0 ? void 0 : bill.lastBlockTimestamp) !== null && _d !== void 0 ? _d : '0');
75461
75455
  const isPendingCliff = vestingCliff ? currentTime - lastBlockTimestamp < vestingCliff : false;
75462
75456
  const cliffCountdown = getTimePeriods(lastBlockTimestamp + (vestingCliff !== null && vestingCliff !== void 0 ? vestingCliff : 0) - currentTime, true);
75463
- const [onOpenPurchasedBond] = useModal(jsx$2(YourBondsModalSolana, { billId: bill.asset }));
75457
+ const [onOpenPurchasedBond] = useModal(jsx$2(YourBondsModalSolana, { userBill: bill }));
75464
75458
  const ensureUserPayoutAtaExists = (_a) => __awaiter$9(void 0, [_a], void 0, function* ({ connection, payer, payoutMint, user, }) {
75465
75459
  const userPayoutAta = yield getAssociatedTokenAddress(payoutMint, user);
75466
75460
  try {
@@ -75569,10 +75563,7 @@ const UserBondRowSolana = ({ bill }) => {
75569
75563
  setLoadingTx(false);
75570
75564
  }
75571
75565
  });
75572
- return (jsxs("div", { className: "your-bonds", onClick: () => {
75573
- if (bill.asset)
75574
- onOpenPurchasedBond();
75575
- }, children: [jsxs("div", { className: "token-info-container", children: [jsx$2(TokenInfoAndName, { tokenSymbol: (_e = bill.bond) === null || _e === void 0 ? void 0 : _e.earnToken.symbol, chain: (_f = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _f === void 0 ? void 0 : _f.chainId, vestEnds: getTimeLeftForFullyVested(bill) > 0 ? `Ends in ${getPendingVestingString(bill)}` : `Fully Vested`, isHotBond: true }), jsx$2("div", { className: "tooltip-column", children: jsx$2(TooltipBubble, { className: "tooltip-bubble", body: jsx$2(BondInfoTooltip, { earnTokenContract: ((_g = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _g === void 0 ? void 0 : _g.earnToken.address[bill === null || bill === void 0 ? void 0 : bill.bond.chainId]) || '', earnTokenSymbol: ((_h = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _h === void 0 ? void 0 : _h.earnToken.symbol) || '', bondContract: (_j = bill === null || bill === void 0 ? void 0 : bill.address) !== null && _j !== void 0 ? _j : '', projectLink: (_k = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _k === void 0 ? void 0 : _k.projectLink, twitter: (_l = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _l === void 0 ? void 0 : _l.twitter, audit: (_m = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _m === void 0 ? void 0 : _m.audit, chain: (_o = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _o === void 0 ? void 0 : _o.chainId }), width: "205px", placement: "bottomRight", transformTip: "translate(5%, 0%)", children: jsx$2(Flex, { sx: {
75566
+ return (jsxs("div", { className: "your-bonds", onClick: () => onOpenPurchasedBond(), children: [jsxs("div", { className: "token-info-container", children: [jsx$2(TokenInfoAndName, { tokenSymbol: (_e = bill.bond) === null || _e === void 0 ? void 0 : _e.earnToken.symbol, chain: (_f = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _f === void 0 ? void 0 : _f.chainId, vestEnds: getTimeLeftForFullyVested(bill) > 0 ? `Ends in ${getPendingVestingString(bill)}` : `Fully Vested`, isHotBond: true }), jsx$2("div", { className: "tooltip-column", children: jsx$2(TooltipBubble, { className: "tooltip-bubble", body: jsx$2(BondInfoTooltip, { earnTokenContract: ((_g = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _g === void 0 ? void 0 : _g.earnToken.address[bill === null || bill === void 0 ? void 0 : bill.bond.chainId]) || '', earnTokenSymbol: ((_h = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _h === void 0 ? void 0 : _h.earnToken.symbol) || '', bondContract: (_j = bill === null || bill === void 0 ? void 0 : bill.address) !== null && _j !== void 0 ? _j : '', projectLink: (_k = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _k === void 0 ? void 0 : _k.projectLink, twitter: (_l = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _l === void 0 ? void 0 : _l.twitter, audit: (_m = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _m === void 0 ? void 0 : _m.audit, chain: (_o = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _o === void 0 ? void 0 : _o.chainId }), width: "205px", placement: "bottomRight", transformTip: "translate(5%, 0%)", children: jsx$2(Flex, { sx: {
75576
75567
  opacity: 0.8,
75577
75568
  }, children: jsx$2(Svg, { icon: "more", width: "25px" }) }) }) })] }), jsxs("div", { className: "your-bonds-columns-container", children: [jsx$2(ProfitCard, { userBond: bill }), jsxs("div", { className: "your-bonds-content", children: [jsx$2("div", { className: "your-bonds-content-title", children: "Claimable" }), jsxs("div", { className: "your-bonds-content-tokens-amount", children: [formatNumberSI(claimable(bill), 4), jsx$2("div", { className: "your-bonds-content-tokens-usd-amount", children: `($${(claimable(bill) * earnTokenPrice).toFixed(2)})` })] })] }), jsxs("div", { className: "your-bonds-content", children: [jsx$2("div", { className: "your-bonds-content-title", children: "Pending" }), jsxs("div", { className: "your-bonds-content-tokens-amount", children: [formatNumberSI(pending(bill), 4), jsx$2("div", { className: "your-bonds-content-tokens-usd-amount", children: `($${(pending(bill) * earnTokenPrice).toFixed(2)})` })] })] }), jsx$2("div", { className: "your-bonds-content hide-mobile", children: jsx$2(ProgressBarWrapper$1, { title: '', value: jsx$2(ProgressBar, { value: getPercentageVested(bill) }), style: {
75578
75569
  width: '127px',
@@ -85220,13 +85211,6 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
85220
85211
  lastValidBlockHeight,
85221
85212
  }, 'confirmed');
85222
85213
  console.log('tx confirmed');
85223
- // axios
85224
- // .post(`${SDKConfig?.urls?.apiV2}/bills/solana/ingest`, {
85225
- // signature: txId,
85226
- // })
85227
- // .catch((e) => {
85228
- // console.error(e)
85229
- // })
85230
85214
  track({
85231
85215
  event: 'bond',
85232
85216
  chain: bondChain,
@@ -85240,9 +85224,9 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
85240
85224
  usdAmount: parseFloat(inputValue) * ((_h = inputTokenPrice === null || inputTokenPrice === void 0 ? void 0 : inputTokenPrice.price) !== null && _h !== void 0 ? _h : 0),
85241
85225
  },
85242
85226
  });
85243
- // waits 3 seconds before triggering after-purchase flow
85244
- yield new Promise((resolve) => setTimeout(resolve, 3000));
85245
- console.timeEnd('3 seconds elapsed. trigger bonds refetch');
85227
+ // waits 2 seconds before triggering after-purchase flow
85228
+ yield new Promise((resolve) => setTimeout(resolve, 2000));
85229
+ console.timeEnd('2 seconds elapsed. trigger bonds refetch');
85246
85230
  addToastSuccess(txId, bondChain);
85247
85231
  setBillId === null || setBillId === void 0 ? void 0 : setBillId(nftMint.publicKey.toString());
85248
85232
  }
@@ -85324,11 +85308,16 @@ const ModalHandler = ({ onDismiss, bondAddress, bondChain, }) => {
85324
85308
  // State
85325
85309
  const [billId, setBillId] = useState('');
85326
85310
  const [buyTxHash, setBuyTxHash] = useState('');
85311
+ const [userBill, setUserBill] = useState();
85327
85312
  // Hooks
85328
85313
  const { data: bondsData } = useBondsData();
85329
- const { refetch } = useUserBonds(true);
85330
85314
  const locationPath = window.location.pathname;
85331
85315
  const { data: txReceipt } = useMonitorTx(buyTxHash, bondChain);
85316
+ const { address } = useEVMAccount();
85317
+ const { publicKey } = useSOLAccount();
85318
+ const solanaAccount = publicKey === null || publicKey === void 0 ? void 0 : publicKey.toBase58();
85319
+ const { data: bondList } = useBondsList();
85320
+ const queryClient = useQueryClient();
85332
85321
  // EVM - Look for billId on tx logs
85333
85322
  if (txReceipt) {
85334
85323
  try {
@@ -85356,13 +85345,36 @@ const ModalHandler = ({ onDismiss, bondAddress, bondChain, }) => {
85356
85345
  if (!hasRefetched.current) {
85357
85346
  if (billId) {
85358
85347
  console.log('Trigger user bonds refetch');
85359
- refetch();
85348
+ const bondToRefetch = bondList === null || bondList === void 0 ? void 0 : bondList.find((bond) => {
85349
+ var _a, _b;
85350
+ return (bondAddress === null || bondAddress === void 0 ? void 0 : bondAddress.toLowerCase()) === ((_b = (_a = bond === null || bond === void 0 ? void 0 : bond.contractAddress) === null || _a === void 0 ? void 0 : _a[bond === null || bond === void 0 ? void 0 : bond.chainId]) === null || _b === void 0 ? void 0 : _b.toLowerCase()) &&
85351
+ bondChain === (bond === null || bond === void 0 ? void 0 : bond.chainId);
85352
+ });
85353
+ if (!bondToRefetch)
85354
+ return;
85360
85355
  hasRefetched.current = true;
85356
+ getUserBonds(address, solanaAccount, [bondToRefetch], queryClient)
85357
+ .then((bonds) => {
85358
+ const purchasedBond = bonds.find((bond) => {
85359
+ var _a;
85360
+ if (((_a = bond === null || bond === void 0 ? void 0 : bond.bond) === null || _a === void 0 ? void 0 : _a.chainId) === types$1.ChainId.SOL) {
85361
+ return bond.asset === billId;
85362
+ }
85363
+ else {
85364
+ return bond.id === billId;
85365
+ }
85366
+ });
85367
+ console.log(purchasedBond);
85368
+ setUserBill(purchasedBond);
85369
+ })
85370
+ .catch((e) => {
85371
+ console.error(e);
85372
+ });
85361
85373
  }
85362
85374
  }
85363
85375
  /* eslint-disable react-hooks/exhaustive-deps */
85364
85376
  }, [billId]);
85365
- return billId ? (bondChain === types$1.ChainId.SOL ? (jsx$2(YourBondsModalSolana, { billId: billId, onDismiss: onDismiss })) : (jsx$2(YourBondsModal, { billId: billId, onDismiss: onDismiss }))) : (jsx$2(BuyBondModal, { bondAddress: bondAddress, bondChain: bondChain, handlePurchasedBond: setBuyTxHash, setBillId: setBillId, onDismiss: () => {
85377
+ return billId ? (bondChain === types$1.ChainId.SOL ? (jsx$2(YourBondsModalSolana, { userBill: userBill, onDismiss: onDismiss })) : (jsx$2(YourBondsModal, { userBill: userBill, onDismiss: onDismiss }))) : (jsx$2(BuyBondModal, { bondAddress: bondAddress, bondChain: bondChain, handlePurchasedBond: setBuyTxHash, setBillId: setBillId, onDismiss: () => {
85366
85378
  window.history.pushState({}, '', `${locationPath !== '/bonds' ? locationPath : '/bonds'}`);
85367
85379
  onDismiss === null || onDismiss === void 0 ? void 0 : onDismiss();
85368
85380
  } }));
@@ -86218,7 +86230,6 @@ const Bonds = () => {
86218
86230
  useHotBonds();
86219
86231
  const { favTokens } = useFavoriteTokens();
86220
86232
  const { data: bondData, refetch } = useBondsData();
86221
- // useUserBonds()
86222
86233
  const { data: allBonds } = useBondsList();
86223
86234
  const { data: allPreBonds } = useBondsListPreTGE();
86224
86235
  const { data: chainFilterOption, setChainFilterOption } = useChainFilterOption();
@@ -1,6 +1,5 @@
1
- import { UseQueryResult } from '@tanstack/react-query';
2
- import { BillsConfig, ChainId } from '@ape.swap/apeswap-lists';
1
+ import { QueryClient, UseQueryResult } from '@tanstack/react-query';
2
+ import { BillsConfig } from '@ape.swap/apeswap-lists';
3
3
  import { UserBill } from '../../types/yourbonds';
4
- import { TokenPrices } from '../tokenPrices/useTokenPrices';
5
4
  export default function useUserBonds(dontFetch?: boolean): UseQueryResult<UserBill[]>;
6
- export declare const getUserBonds: (account: string, solanaAccount: string, bondList: BillsConfig[], chains: number[], tokenPrices: Partial<Record<ChainId, TokenPrices[]>>, apiUrl?: string) => Promise<UserBill[]>;
5
+ export declare const getUserBonds: (account: string, solanaAccount: string, bondList: BillsConfig[], queryClient: QueryClient) => Promise<UserBill[]>;
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
- declare const YourBondsModal: ({ billId, onDismiss }: {
3
- billId: string;
2
+ import { UserBill } from '../../types/yourbonds';
3
+ declare const YourBondsModal: ({ userBill, onDismiss }: {
4
+ userBill?: UserBill;
4
5
  onDismiss?: () => void;
5
6
  }) => React.JSX.Element;
6
7
  export default YourBondsModal;
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
- declare const YourBondsModalSolana: ({ billId, onDismiss }: {
3
- billId: string;
2
+ import { UserBill } from '../../types/yourbonds';
3
+ declare const YourBondsModalSolana: ({ userBill, onDismiss }: {
4
+ userBill?: UserBill;
4
5
  onDismiss?: () => void;
5
6
  }) => React.JSX.Element;
6
7
  export default YourBondsModalSolana;
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": "4.1.0-test.12",
6
+ "version": "4.1.0-test.14",
7
7
  "module": "dist/main.js",
8
8
  "type": "module",
9
9
  "types": "dist/main.d.ts",