@ape.swap/bonds-sdk 5.1.51 → 6.0.1

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.
@@ -3,4 +3,4 @@ import { BondsData } from '../../types/bonds';
3
3
  export declare function useHotBondContracts(): UseQueryResult<string[], Error>;
4
4
  export default function useHotBonds(): UseQueryResult<BondsData[]>;
5
5
  export declare const getHotBondsContracts: (apiUrl: string) => Promise<string[]>;
6
- export declare const getHotBonds: (bondsData: BondsData[], hotBondContracts: string[]) => Promise<BondsData[]>;
6
+ export declare const getHotBonds: (bondsData: BondsData[], hotBondContracts: string[], showLowValueBonds: boolean) => Promise<BondsData[]>;
@@ -3,11 +3,12 @@ import { QUERY_KEYS } from '../../config/constants/queryKeys.js';
3
3
  import axios from 'axios';
4
4
  import { STRAPI_URL } from '../../config/constants/variables.js';
5
5
  import { reportError } from '../../utils/reportError.js';
6
- import { useURLByEnvironment } from '../useSDKConfig.js';
6
+ import { useSDKConfig, useURLByEnvironment } from '../useSDKConfig.js';
7
7
  import useBondsData from '../bonds/useBondsData.js';
8
8
  import { findHighestTrueBondPrice } from '../../utils/bondPriceHelpers.js';
9
9
  import { TIERS_WEIGHT } from '../tiers/useTierPoints.js';
10
10
  import { LaunchBondTiers } from '@ape.swap/apeswap-lists';
11
+ import { isBondSoldOut } from '../../views/Bonds/utils.js';
11
12
 
12
13
  function useHotBondContracts() {
13
14
  const apiUrl = useURLByEnvironment('apiV2');
@@ -21,11 +22,12 @@ function useHotBondContracts() {
21
22
  });
22
23
  }
23
24
  function useHotBonds() {
25
+ const { showLowValueBonds } = useSDKConfig();
24
26
  const { data: bondsData } = useBondsData();
25
27
  const { data: hotBondContracts } = useHotBondContracts();
26
28
  return useQuery({
27
- queryKey: [QUERY_KEYS.HOT_BONDS, bondsData?.length, hotBondContracts?.length],
28
- queryFn: () => getHotBonds(bondsData, hotBondContracts),
29
+ queryKey: [QUERY_KEYS.HOT_BONDS, bondsData?.length, hotBondContracts?.length, showLowValueBonds],
30
+ queryFn: () => getHotBonds(bondsData, hotBondContracts, showLowValueBonds),
29
31
  refetchOnWindowFocus: false,
30
32
  refetchInterval: 30000,
31
33
  enabled: !!bondsData && bondsData.length > 0 && !!hotBondContracts && hotBondContracts.length > 0,
@@ -46,7 +48,7 @@ const getHotBondsContracts = async (apiUrl) => {
46
48
  return [];
47
49
  }
48
50
  };
49
- const getHotBonds = async (bondsData, hotBondContracts) => {
51
+ const getHotBonds = async (bondsData, hotBondContracts, showLowValueBonds) => {
50
52
  const sortAndFilterBonds = (bonds) => bonds
51
53
  ?.sort((a, b) => (findHighestTrueBondPrice(TIERS_WEIGHT[LaunchBondTiers.Legend], b?.trueBondPrices)?.bonus ?? 0) -
52
54
  (findHighestTrueBondPrice(TIERS_WEIGHT[LaunchBondTiers.Legend], a?.trueBondPrices)?.bonus ?? 0))
@@ -54,9 +56,10 @@ const getHotBonds = async (bondsData, hotBondContracts) => {
54
56
  const bonus = findHighestTrueBondPrice(TIERS_WEIGHT[LaunchBondTiers.Legend], bond?.trueBondPrices)?.bonus;
55
57
  return bonus && bonus > 0 && bonus < 50;
56
58
  });
57
- const hotBonds = bondsData.filter((bond) => hotBondContracts.includes(bond?.contractAddress?.[bond?.chainId]?.toLowerCase() ?? ''));
59
+ const hotBonds = bondsData.filter((bond) => hotBondContracts.includes(bond?.contractAddress?.[bond?.chainId]?.toLowerCase() ?? '') &&
60
+ !isBondSoldOut(bond, showLowValueBonds));
58
61
  const filteredHotBonds = sortAndFilterBonds(hotBonds) ?? [];
59
- const filteredBondsData = sortAndFilterBonds(bondsData) ?? [];
62
+ const filteredBondsData = sortAndFilterBonds(bondsData.filter((bond) => !isBondSoldOut(bond, showLowValueBonds))) ?? [];
60
63
  return [...filteredHotBonds, ...filteredBondsData].slice(0, 3);
61
64
  };
62
65
 
@@ -1 +1 @@
1
- {"version":3,"file":"useHotBonds.js","sources":["../../../src/state/hotBonds/useHotBonds.ts"],"sourcesContent":["import { useQuery, UseQueryResult } from '@tanstack/react-query'\nimport { QUERY_KEYS } from '../../config/constants/queryKeys'\nimport axios from 'axios'\nimport { BondsData } from '../../types/bonds'\nimport { STRAPI_URL } from '../../config/constants/variables'\nimport { reportError } from '../../utils/reportError'\nimport { useURLByEnvironment } from '../useSDKConfig'\nimport useBondsData from '../bonds/useBondsData'\nimport { findHighestTrueBondPrice } from '../../utils/bondPriceHelpers'\nimport { TIERS_WEIGHT } from '../tiers/useTierPoints'\nimport { LaunchBondTiers } from '@ape.swap/apeswap-lists'\n\nexport function useHotBondContracts() {\n const apiUrl = useURLByEnvironment('apiV2')\n return useQuery({\n queryKey: [QUERY_KEYS.HOT_BONDS_CONTRACTS],\n queryFn: () => getHotBondsContracts(apiUrl),\n staleTime: Infinity,\n refetchOnWindowFocus: false,\n refetchOnMount: false,\n retry: 1,\n })\n}\n\nexport default function useHotBonds(): UseQueryResult<BondsData[]> {\n const { data: bondsData } = useBondsData()\n const { data: hotBondContracts } = useHotBondContracts()\n return useQuery({\n queryKey: [QUERY_KEYS.HOT_BONDS, bondsData?.length, hotBondContracts?.length],\n queryFn: () => getHotBonds(bondsData!, hotBondContracts!),\n refetchOnWindowFocus: false,\n refetchInterval: 30000,\n enabled: !!bondsData && bondsData.length > 0 && !!hotBondContracts && hotBondContracts.length > 0,\n retry: 0,\n })\n}\n\nexport const getHotBondsContracts = async (apiUrl: string): Promise<string[]> => {\n try {\n const response = await axios.get(`${STRAPI_URL}/hot-bonds`)\n return response.data.map((bond: { BondAddress: string }) => bond.BondAddress.toLowerCase())\n } catch (e) {\n reportError({\n apiUrl,\n error: e,\n extraInfo: { type: 'getHotBondsContracts', e },\n })\n return []\n }\n}\n\nexport const getHotBonds = async (bondsData: BondsData[], hotBondContracts: string[]): Promise<BondsData[]> => {\n const sortAndFilterBonds = (bonds: BondsData[]) =>\n bonds\n ?.sort(\n (a, b) =>\n (findHighestTrueBondPrice(TIERS_WEIGHT[LaunchBondTiers.Legend], b?.trueBondPrices)?.bonus ?? 0) -\n (findHighestTrueBondPrice(TIERS_WEIGHT[LaunchBondTiers.Legend], a?.trueBondPrices)?.bonus ?? 0),\n )\n ?.filter((bond) => {\n const bonus = findHighestTrueBondPrice(TIERS_WEIGHT[LaunchBondTiers.Legend], bond?.trueBondPrices)?.bonus\n return bonus && bonus > 0 && bonus < 50\n })\n\n const hotBonds = bondsData.filter((bond) =>\n hotBondContracts.includes(bond?.contractAddress?.[bond?.chainId]?.toLowerCase() ?? ''),\n )\n\n const filteredHotBonds = sortAndFilterBonds(hotBonds) ?? []\n const filteredBondsData = sortAndFilterBonds(bondsData) ?? []\n\n return [...filteredHotBonds, ...filteredBondsData].slice(0, 3)\n}\n"],"names":[],"mappings":";;;;;;;;;;;SAYgB,mBAAmB,GAAA;AACjC,IAAA,MAAM,MAAM,GAAG,mBAAmB,CAAC,OAAO,CAAC;AAC3C,IAAA,OAAO,QAAQ,CAAC;AACd,QAAA,QAAQ,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC;AAC1C,QAAA,OAAO,EAAE,MAAM,oBAAoB,CAAC,MAAM,CAAC;AAC3C,QAAA,SAAS,EAAE,QAAQ;AACnB,QAAA,oBAAoB,EAAE,KAAK;AAC3B,QAAA,cAAc,EAAE,KAAK;AACrB,QAAA,KAAK,EAAE,CAAC;AACT,KAAA,CAAC;AACJ;AAEc,SAAU,WAAW,GAAA;IACjC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,YAAY,EAAE;IAC1C,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,mBAAmB,EAAE;AACxD,IAAA,OAAO,QAAQ,CAAC;AACd,QAAA,QAAQ,EAAE,CAAC,UAAU,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,CAAC;QAC7E,OAAO,EAAE,MAAM,WAAW,CAAC,SAAU,EAAE,gBAAiB,CAAC;AACzD,QAAA,oBAAoB,EAAE,KAAK;AAC3B,QAAA,eAAe,E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c,CAAC,EAAE,KAAK;QACzG,OAAO,KAAK,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE;AACzC,IAAA,CAAC,CAAC;AAEN,IAAA,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,KACrC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CACvF;IAED,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,QAAQ,CAAC,IAAI,EAAE;IAC3D,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,SAAS,CAAC,IAAI,EAAE;AAE7D,IAAA,OAAO,CAAC,GAAG,gBAAgB,EAAE,GAAG,iBAAiB,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;AAChE;;;;"}
1
+ {"version":3,"file":"useHotBonds.js","sources":["../../../src/state/hotBonds/useHotBonds.ts"],"sourcesContent":["import { useQuery, UseQueryResult } from '@tanstack/react-query'\nimport { QUERY_KEYS } from '../../config/constants/queryKeys'\nimport axios from 'axios'\nimport { BondsData } from '../../types/bonds'\nimport { STRAPI_URL } from '../../config/constants/variables'\nimport { reportError } from '../../utils/reportError'\nimport { useSDKConfig, useURLByEnvironment } from '../useSDKConfig'\nimport useBondsData from '../bonds/useBondsData'\nimport { findHighestTrueBondPrice } from '../../utils/bondPriceHelpers'\nimport { TIERS_WEIGHT } from '../tiers/useTierPoints'\nimport { LaunchBondTiers } from '@ape.swap/apeswap-lists'\nimport { isBondSoldOut } from '../../views/Bonds/utils'\n\nexport function useHotBondContracts() {\n const apiUrl = useURLByEnvironment('apiV2')\n return useQuery({\n queryKey: [QUERY_KEYS.HOT_BONDS_CONTRACTS],\n queryFn: () => getHotBondsContracts(apiUrl),\n staleTime: Infinity,\n refetchOnWindowFocus: false,\n refetchOnMount: false,\n retry: 1,\n })\n}\n\nexport default function useHotBonds(): UseQueryResult<BondsData[]> {\n const { showLowValueBonds } = useSDKConfig()\n const { data: bondsData } = useBondsData()\n const { data: hotBondContracts } = useHotBondContracts()\n return useQuery({\n queryKey: [QUERY_KEYS.HOT_BONDS, bondsData?.length, hotBondContracts?.length, showLowValueBonds],\n queryFn: () => getHotBonds(bondsData!, hotBondContracts!, showLowValueBonds),\n refetchOnWindowFocus: false,\n refetchInterval: 30000,\n enabled: !!bondsData && bondsData.length > 0 && !!hotBondContracts && hotBondContracts.length > 0,\n retry: 0,\n })\n}\n\nexport const getHotBondsContracts = async (apiUrl: string): Promise<string[]> => {\n try {\n const response = await axios.get(`${STRAPI_URL}/hot-bonds`)\n return response.data.map((bond: { BondAddress: string }) => bond.BondAddress.toLowerCase())\n } catch (e) {\n reportError({\n apiUrl,\n error: e,\n extraInfo: { type: 'getHotBondsContracts', e },\n })\n return []\n }\n}\n\nexport const getHotBonds = async (\n bondsData: BondsData[],\n hotBondContracts: string[],\n showLowValueBonds: boolean,\n): Promise<BondsData[]> => {\n const sortAndFilterBonds = (bonds: BondsData[]) =>\n bonds\n ?.sort(\n (a, b) =>\n (findHighestTrueBondPrice(TIERS_WEIGHT[LaunchBondTiers.Legend], b?.trueBondPrices)?.bonus ?? 0) -\n (findHighestTrueBondPrice(TIERS_WEIGHT[LaunchBondTiers.Legend], a?.trueBondPrices)?.bonus ?? 0),\n )\n ?.filter((bond) => {\n const bonus = findHighestTrueBondPrice(TIERS_WEIGHT[LaunchBondTiers.Legend], bond?.trueBondPrices)?.bonus\n return bonus && bonus > 0 && bonus < 50\n })\n\n const hotBonds = bondsData.filter(\n (bond) =>\n hotBondContracts.includes(bond?.contractAddress?.[bond?.chainId]?.toLowerCase() ?? '') &&\n !isBondSoldOut(bond, showLowValueBonds),\n )\n\n const filteredHotBonds = sortAndFilterBonds(hotBonds) ?? []\n const filteredBondsData = sortAndFilterBonds(bondsData.filter((bond) => !isBondSoldOut(bond, showLowValueBonds))) ?? []\n\n return [...filteredHotBonds, ...filteredBondsData].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,aAAa,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAC1C;IAED,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,QAAQ,CAAC,IAAI,EAAE;IAC3D,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,IAAI,EAAE;AAEvH,IAAA,OAAO,CAAC,GAAG,gBAAgB,EAAE,GAAG,iBAAiB,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;AAChE;;;;"}
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": "5.1.51",
6
+ "version": "6.0.1",
7
7
  "module": "dist/main.js",
8
8
  "type": "module",
9
9
  "types": "dist/main.d.ts",