@ape.swap/bonds-sdk 6.0.3 → 6.0.4

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,98 +1,95 @@
1
1
  import { jsx } from 'theme-ui/jsx-runtime';
2
- import { useState, useRef, useEffect } from 'react';
2
+ import { useRef, useMemo, useEffect } from 'react';
3
3
  import { createChart, CrosshairMode, ColorType, LineStyle } from 'lightweight-charts';
4
4
  import { getFirstNonZeroDigits } from '../../../../../utils/roundNumber.js';
5
5
  import { determineValues } from './utils.js';
6
6
 
7
7
  const LineChart = ({ historicalPrices, hasDiscount, bondPrice, tokenPrice, }) => {
8
- // reference for DOM element to create with chart
9
- const data = historicalPrices;
10
8
  const chartContainerId = 'lineChartContainer';
11
- const formattedData = data?.map((entry) => {
12
- return {
13
- time: parseInt(entry.timestamp),
14
- value: parseFloat(getFirstNonZeroDigits(entry.close, 4)),
15
- };
16
- });
17
- // pointer to the chart object
18
- const [chartCreated, setChartCreated] = useState();
19
- const chartInitiatedRef = useRef(false);
9
+ const chartRef = useRef(null);
20
10
  const discount = 1 - parseFloat(bondPrice ?? '0') / parseFloat(tokenPrice ?? '0');
21
11
  const discountToUse = discount > 0 ? discount : 0;
22
- const bottomScaleMargin = discountToUse + 0.15;
12
+ const bottomScaleMargin = Math.min(discountToUse + 0.15, 0.85);
13
+ const formattedData = useMemo(() => {
14
+ const mapped = historicalPrices?.map((entry) => ({
15
+ time: parseInt(entry.timestamp),
16
+ value: parseFloat(getFirstNonZeroDigits(entry.close, 4)),
17
+ })) ?? [];
18
+ mapped.push({ time: Math.floor(new Date().getTime() / 1000), value: parseFloat(tokenPrice) });
19
+ return mapped;
20
+ }, [historicalPrices, tokenPrice]);
23
21
  useEffect(() => {
24
22
  const chartContainer = document.getElementById(chartContainerId);
25
- if (chartContainer && !chartCreated && !chartInitiatedRef.current) {
26
- console.log('creating chart');
27
- const chart = createChart(chartContainer, {
28
- width: 0,
29
- height: 0,
30
- layout: {
31
- background: {
32
- type: ColorType.Solid,
33
- color: 'transparent',
34
- },
35
- textColor: '#73728E',
36
- },
37
- grid: {
38
- vertLines: {
39
- color: '#73728E',
40
- },
41
- horzLines: {
42
- color: '#73728E',
43
- },
44
- },
45
- crosshair: {
46
- mode: CrosshairMode.Magnet,
47
- },
48
- rightPriceScale: {
49
- borderColor: '#73728E',
50
- visible: true,
51
- scaleMargins: {
52
- top: 0.12,
53
- bottom: bottomScaleMargin,
54
- },
55
- },
56
- timeScale: {
57
- borderColor: '#73728E',
58
- },
59
- localization: {
60
- priceFormatter: (val) => {
61
- return `$${getFirstNonZeroDigits(parseFloat(val), 3)}`;
62
- },
63
- },
64
- });
65
- const [precision, minMove] = determineValues(parseFloat(bondPrice));
66
- const areaSeries = chart.addAreaSeries({
67
- lineColor: '#5E59B5',
68
- topColor: '#5E59B5',
69
- bottomColor: '#514CA133',
70
- priceLineWidth: 2,
71
- priceLineStyle: LineStyle.Dashed,
72
- priceLineVisible: true,
73
- priceFormat: {
74
- precision,
75
- minMove,
76
- formatter: (val) => getFirstNonZeroDigits(parseFloat(val), 3),
77
- },
78
- });
79
- formattedData?.push({ time: Math.floor(new Date().getTime() / 1000), value: parseFloat(tokenPrice) });
80
- //@ts-ignore
81
- areaSeries.setData(formattedData);
82
- areaSeries.createPriceLine({
83
- price: parseFloat(bondPrice),
84
- color: hasDiscount ? '#38A611' : '#DF4141',
85
- lineWidth: 2,
86
- lineStyle: LineStyle.Dashed,
87
- axisLabelVisible: true,
88
- title: `Bond Price`,
89
- });
90
- chart.timeScale().fitContent();
91
- //@ts-ignore
92
- setChartCreated(chart);
93
- chartInitiatedRef.current = true;
94
- }
95
- }, [bondPrice, bottomScaleMargin, chartCreated, formattedData, hasDiscount, tokenPrice]);
23
+ if (!chartContainer || chartRef.current)
24
+ return;
25
+ const [precision, minMove] = determineValues(parseFloat(bondPrice));
26
+ const chart = createChart(chartContainer, {
27
+ width: 0,
28
+ height: 0,
29
+ layout: {
30
+ background: { type: ColorType.Solid, color: 'transparent' },
31
+ textColor: '#73728E',
32
+ },
33
+ grid: {
34
+ vertLines: { color: '#73728E' },
35
+ horzLines: { color: '#73728E' },
36
+ },
37
+ crosshair: { mode: CrosshairMode.Magnet },
38
+ rightPriceScale: {
39
+ borderColor: '#73728E',
40
+ visible: true,
41
+ scaleMargins: { top: 0.12, bottom: bottomScaleMargin },
42
+ },
43
+ timeScale: {
44
+ borderColor: '#73728E',
45
+ fixLeftEdge: true,
46
+ fixRightEdge: true,
47
+ },
48
+ handleScroll: {
49
+ mouseWheel: false,
50
+ pressedMouseMove: false,
51
+ horzTouchDrag: false,
52
+ vertTouchDrag: false,
53
+ },
54
+ handleScale: {
55
+ axisPressedMouseMove: false,
56
+ mouseWheel: false,
57
+ pinch: false,
58
+ },
59
+ localization: {
60
+ priceFormatter: (val) => `$${getFirstNonZeroDigits(parseFloat(val), 3)}`,
61
+ },
62
+ });
63
+ const areaSeries = chart.addAreaSeries({
64
+ lineColor: '#5E59B5',
65
+ topColor: '#5E59B5',
66
+ bottomColor: '#514CA133',
67
+ priceLineWidth: 2,
68
+ priceLineStyle: LineStyle.Dashed,
69
+ priceLineVisible: true,
70
+ priceFormat: {
71
+ precision,
72
+ minMove,
73
+ formatter: (val) => getFirstNonZeroDigits(parseFloat(val), 3),
74
+ },
75
+ });
76
+ //@ts-ignore
77
+ areaSeries.setData(formattedData);
78
+ areaSeries.createPriceLine({
79
+ price: parseFloat(bondPrice),
80
+ color: hasDiscount ? '#38A611' : '#DF4141',
81
+ lineWidth: 2,
82
+ lineStyle: LineStyle.Dashed,
83
+ axisLabelVisible: true,
84
+ title: 'Bond Price',
85
+ });
86
+ chart.timeScale().fitContent();
87
+ chartRef.current = chart;
88
+ return () => {
89
+ chart.remove();
90
+ chartRef.current = null;
91
+ };
92
+ }, [bondPrice, bottomScaleMargin, formattedData, hasDiscount]);
96
93
  return jsx("div", { id: chartContainerId, style: { width: '100%', height: '100%' } });
97
94
  };
98
95
 
@@ -1 +1 @@
1
- {"version":3,"file":"LineChart.js","sources":["../../../../../../src/views/ProjectView/components/PriceChart/components/LineChart.tsx"],"sourcesContent":["import React, { useState, useEffect, useRef } from 'react'\nimport { ColorType, createChart, CrosshairMode, LineStyle } from 'lightweight-charts'\nimport { HistoricalPrices } from '../../../ProjectView'\nimport { getFirstNonZeroDigits } from '../../../../../utils/roundNumber'\nimport { determineValues } from './utils'\n\nconst LineChart = ({\n historicalPrices,\n hasDiscount,\n bondPrice,\n tokenPrice,\n}: {\n historicalPrices?: HistoricalPrices[] | null\n hasDiscount: boolean\n bondPrice: string\n tokenPrice: string\n}) => {\n // reference for DOM element to create with chart\n const data = historicalPrices\n const chartContainerId = 'lineChartContainer'\n\n const formattedData = data?.map((entry) => {\n return {\n time: parseInt(entry.timestamp),\n value: parseFloat(getFirstNonZeroDigits(entry.close, 4)),\n }\n })\n\n // pointer to the chart object\n const [chartCreated, setChartCreated] = useState()\n const chartInitiatedRef = useRef(false)\n\n const discount = 1 - parseFloat(bondPrice ?? '0') / parseFloat(tokenPrice ?? '0')\n const discountToUse = discount > 0 ? discount : 0\n const bottomScaleMargin = discountToUse + 0.15\n\n useEffect(() => {\n const chartContainer = document.getElementById(chartContainerId)\n if (chartContainer && !chartCreated && !chartInitiatedRef.current) {\n console.log('creating chart')\n const chart = createChart(chartContainer, {\n width: 0,\n height: 0,\n layout: {\n background: {\n type: ColorType.Solid,\n color: 'transparent',\n },\n textColor: '#73728E',\n },\n grid: {\n vertLines: {\n color: '#73728E',\n },\n horzLines: {\n color: '#73728E',\n },\n },\n crosshair: {\n mode: CrosshairMode.Magnet,\n },\n rightPriceScale: {\n borderColor: '#73728E',\n visible: true,\n scaleMargins: {\n top: 0.12,\n bottom: bottomScaleMargin,\n },\n },\n timeScale: {\n borderColor: '#73728E',\n },\n\n localization: {\n priceFormatter: (val: string) => {\n return `$${getFirstNonZeroDigits(parseFloat(val), 3)}`\n },\n },\n })\n const [precision, minMove] = determineValues(parseFloat(bondPrice))\n\n const areaSeries = chart.addAreaSeries({\n lineColor: '#5E59B5',\n topColor: '#5E59B5',\n bottomColor: '#514CA133',\n priceLineWidth: 2,\n priceLineStyle: LineStyle.Dashed,\n priceLineVisible: true,\n priceFormat: {\n precision,\n minMove,\n formatter: (val: string) => getFirstNonZeroDigits(parseFloat(val), 3),\n },\n })\n\n formattedData?.push({ time: Math.floor(new Date().getTime() / 1000), value: parseFloat(tokenPrice) })\n //@ts-ignore\n areaSeries.setData(formattedData)\n\n areaSeries.createPriceLine({\n price: parseFloat(bondPrice),\n color: hasDiscount ? '#38A611' : '#DF4141',\n lineWidth: 2,\n lineStyle: LineStyle.Dashed,\n axisLabelVisible: true,\n title: `Bond Price`,\n })\n\n chart.timeScale().fitContent()\n //@ts-ignore\n setChartCreated(chart)\n chartInitiatedRef.current = true\n }\n }, [bondPrice, bottomScaleMargin, chartCreated, formattedData, hasDiscount, tokenPrice])\n\n return <div id={chartContainerId} style={{ width: '100%', height: '100%' }}></div>\n}\n\nexport default LineChart\n"],"names":["_jsx"],"mappings":";;;;;;AAMA,MAAM,SAAS,GAAG,CAAC,EACjB,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,UAAU,GAMX,KAAI;;IAEH,MAAM,IAAI,GAAG,gBAAgB;IAC7B,MAAM,gBAAgB,GAAG,oBAAoB;IAE7C,MAAM,aAAa,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC,KAAK,KAAI;QACxC,OAAO;AACL,YAAA,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC;YAC/B,KAAK,EAAE,UAAU,CAAC,qBAAqB,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;SACzD;AACH,IAAA,CAAC,CAAC;;IAGF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,EAAE;AAClD,IAAA,MAAM,iBAAiB,GAAG,MAAM,CAAC,KAAK,CAAC;AAEvC,IAAA,MAAM,QAAQ,GAAG,CAAC,G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AAA,CAAY;AACpB,aAAA,CAAC;AAEF,YAAA,KAAK,CAAC,SAAS,EAAE,CAAC,UAAU,EAAE;;YAE9B,eAAe,CAAC,KAAK,CAAC;AACtB,YAAA,iBAAiB,CAAC,OAAO,GAAG,IAAI;QAClC;AACF,IAAA,CAAC,EAAE,CAAC,SAAS,EAAE,iBAAiB,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AAExF,IAAA,OAAOA,aAAK,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAQ;AACpF;;;;"}
1
+ {"version":3,"file":"LineChart.js","sources":["../../../../../../src/views/ProjectView/components/PriceChart/components/LineChart.tsx"],"sourcesContent":["import React, { useEffect, useRef, useMemo } from 'react'\nimport { ColorType, createChart, CrosshairMode, LineStyle } from 'lightweight-charts'\nimport { HistoricalPrices } from '../../../ProjectView'\nimport { getFirstNonZeroDigits } from '../../../../../utils/roundNumber'\nimport { determineValues } from './utils'\n\nconst LineChart = ({\n historicalPrices,\n hasDiscount,\n bondPrice,\n tokenPrice,\n}: {\n historicalPrices?: HistoricalPrices[] | null\n hasDiscount: boolean\n bondPrice: string\n tokenPrice: string\n}) => {\n const chartContainerId = 'lineChartContainer'\n const chartRef = useRef<ReturnType<typeof createChart> | null>(null)\n\n const discount = 1 - parseFloat(bondPrice ?? '0') / parseFloat(tokenPrice ?? '0')\n const discountToUse = discount > 0 ? discount : 0\n const bottomScaleMargin = Math.min(discountToUse + 0.15, 0.85)\n\n const formattedData = useMemo(() => {\n const mapped =\n historicalPrices?.map((entry) => ({\n time: parseInt(entry.timestamp),\n value: parseFloat(getFirstNonZeroDigits(entry.close, 4)),\n })) ?? []\n mapped.push({ time: Math.floor(new Date().getTime() / 1000), value: parseFloat(tokenPrice) })\n return mapped\n }, [historicalPrices, tokenPrice])\n\n useEffect(() => {\n const chartContainer = document.getElementById(chartContainerId)\n if (!chartContainer || chartRef.current) return\n\n const [precision, minMove] = determineValues(parseFloat(bondPrice))\n\n const chart = createChart(chartContainer, {\n width: 0,\n height: 0,\n layout: {\n background: { type: ColorType.Solid, color: 'transparent' },\n textColor: '#73728E',\n },\n grid: {\n vertLines: { color: '#73728E' },\n horzLines: { color: '#73728E' },\n },\n crosshair: { mode: CrosshairMode.Magnet },\n rightPriceScale: {\n borderColor: '#73728E',\n visible: true,\n scaleMargins: { top: 0.12, bottom: bottomScaleMargin },\n },\n timeScale: {\n borderColor: '#73728E',\n fixLeftEdge: true,\n fixRightEdge: true,\n },\n handleScroll: {\n mouseWheel: false,\n pressedMouseMove: false,\n horzTouchDrag: false,\n vertTouchDrag: false,\n },\n handleScale: {\n axisPressedMouseMove: false,\n mouseWheel: false,\n pinch: false,\n },\n localization: {\n priceFormatter: (val: string) => `$${getFirstNonZeroDigits(parseFloat(val), 3)}`,\n },\n })\n\n const areaSeries = chart.addAreaSeries({\n lineColor: '#5E59B5',\n topColor: '#5E59B5',\n bottomColor: '#514CA133',\n priceLineWidth: 2,\n priceLineStyle: LineStyle.Dashed,\n priceLineVisible: true,\n priceFormat: {\n precision,\n minMove,\n formatter: (val: string) => getFirstNonZeroDigits(parseFloat(val), 3),\n },\n })\n\n //@ts-ignore\n areaSeries.setData(formattedData)\n\n areaSeries.createPriceLine({\n price: parseFloat(bondPrice),\n color: hasDiscount ? '#38A611' : '#DF4141',\n lineWidth: 2,\n lineStyle: LineStyle.Dashed,\n axisLabelVisible: true,\n title: 'Bond Price',\n })\n\n chart.timeScale().fitContent()\n chartRef.current = chart\n\n return () => {\n chart.remove()\n chartRef.current = null\n }\n }, [bondPrice, bottomScaleMargin, formattedData, hasDiscount])\n\n return <div id={chartContainerId} style={{ width: '100%', height: '100%' }}></div>\n}\n\nexport default LineChart\n"],"names":["_jsx"],"mappings":";;;;;;AAMA,MAAM,SAAS,GAAG,CAAC,EACjB,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,UAAU,G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0.01]
3
- if (input > 1) {
2
+ if (input > 1)
4
3
  return [2, 0.01];
5
- }
6
- // loop that starts handling the cases smaller than or equal to 1
7
- let index = 2; // Index to get next value to consider. Start from 1 since we handled the "greater than 1" case.
8
- let check = 1; // Start with 0.1 as the value to compare with. If input is smaller, increase index and decrease check by a factor of 10.
4
+ // Guard: 0, NaN, Infinity all cause the while loop to run forever
5
+ if (!input || !isFinite(input))
6
+ return [2, 0.01];
7
+ let index = 2;
8
+ let check = 1;
9
9
  while (input <= check) {
10
10
  index += 1;
11
11
  check *= 0.1;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../../../../src/views/ProjectView/components/PriceChart/components/utils.ts"],"sourcesContent":["export const determineValues = (input: number): [number, number] => {\n // if input is larger than 1 return [2, 0.01]\n if (input > 1) {\n return [2, 0.01]\n }\n // loop that starts handling the cases smaller than or equal to 1\n let index = 2 // Index to get next value to consider. Start from 1 since we handled the \"greater than 1\" case.\n let check = 1 // Start with 0.1 as the value to compare with. If input is smaller, increase index and decrease check by a factor of 10.\n while (input <= check) {\n index += 1\n check *= 0.1\n }\n const decimalString = '0.' + Array(index).join('0') + '1'\n // Convert string back to number\n const decimalNumber = Number(decimalString)\n return [index, decimalNumber]\n}\n"],"names":[],"mappings":"AAAO,MAAM,eAAe,GAAG,CAAC,KAAa,KAAsB;;AAEjE,IAAA,IAAI,KAAK,GAAG,CAAC,EAAE;AACb,QAAA,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC;IAClB;;AAEA,IAAA,IAAI,KAAK,GAAG,CAAC,CAAA;AACb,IAAA,IAAI,KAAK,GAAG,CAAC,CAAA;AACb,IAAA,OAAO,KAAK,IAAI,KAAK,EAAE;QACrB,KAAK,IAAI,CAAC;QACV,KAAK,IAAI,GAAG;IACd;AACA,IAAA,MAAM,aAAa,GAAG,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG;;AAEzD,IAAA,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;AAC3C,IAAA,OAAO,CAAC,KAAK,EAAE,aAAa,CAAC;AAC/B;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../../../../src/views/ProjectView/components/PriceChart/components/utils.ts"],"sourcesContent":["export const determineValues = (input: number): [number, number] => {\n if (input > 1) return [2, 0.01]\n // Guard: 0, NaN, Infinity all cause the while loop to run forever\n if (!input || !isFinite(input)) return [2, 0.01]\n\n let index = 2\n let check = 1\n while (input <= check) {\n index += 1\n check *= 0.1\n }\n const decimalString = '0.' + Array(index).join('0') + '1'\n // Convert string back to number\n const decimalNumber = Number(decimalString)\n return [index, decimalNumber]\n}\n"],"names":[],"mappings":"AAAO,MAAM,eAAe,GAAG,CAAC,KAAa,KAAsB;IACjE,IAAI,KAAK,GAAG,CAAC;AAAE,QAAA,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC;;AAE/B,IAAA,IAAI,CAAC,KAAK,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;AAAE,QAAA,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC;IAEhD,IAAI,KAAK,GAAG,CAAC;IACb,IAAI,KAAK,GAAG,CAAC;AACb,IAAA,OAAO,KAAK,IAAI,KAAK,EAAE;QACrB,KAAK,IAAI,CAAC;QACV,KAAK,IAAI,GAAG;IACd;AACA,IAAA,MAAM,aAAa,GAAG,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG;;AAEzD,IAAA,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;AAC3C,IAAA,OAAO,CAAC,KAAK,EAAE,aAAa,CAAC;AAC/B;;;;"}
@@ -18,6 +18,7 @@ const PriceChart = ({ selectedBond, historicalPrices, }) => {
18
18
  const hasDiscount = (trueBondPrice?.bonus ?? 0) > 0;
19
19
  const contractAddress = selectedBond.contractAddress[selectedBond.chainId];
20
20
  const [show, setShow] = useState(false);
21
+ const priceBelowChartPrecision = earnTokenPrice > 0 && earnTokenPrice < 1e-6;
21
22
  const [chartOption, setChartOption] = useState('line');
22
23
  useEffect(() => {
23
24
  // This effect is to ensure that the charts are only rendered on the client
@@ -31,7 +32,7 @@ const PriceChart = ({ selectedBond, historicalPrices, }) => {
31
32
  }, 50);
32
33
  return () => clearTimeout(timer);
33
34
  }, [contractAddress]);
34
- return (jsxs(Flex, { sx: styles.priceContainer, children: [jsxs(Flex, { sx: { width: '100%', justifyContent: 'space-between', mb: '15px', pr: '20px' }, children: [jsx(Flex, { children: "Prices" }), jsxs(Flex, { children: [jsxs(Flex, { sx: { color: hasDiscount ? 'success' : 'error', fontSize: '12px', fontWeight: 500, mr: '15px' }, children: ["Bond Price: $", bondPrice] }), jsxs(Flex, { sx: { color: 'textDisabledButton', fontSize: '12px', fontWeight: 500 }, children: ["Market Price: $", getFirstNonZeroDigits(earnTokenPrice ?? 0)] })] })] }), show && (jsxs(Flex, { sx: styles.container, children: [jsxs(Flex, { sx: styles.buttonsContainer, children: [jsx(Flex, { sx: { ...styles.button, mr: '15px' }, onClick: () => setChartOption('line'), children: jsx(Svg, { icon: "lineChart", width: 20 }) }), jsx(Flex, { sx: styles.button, onClick: () => setChartOption('candleStick'), children: "D" })] }), historicalPrices && historicalPrices.length > 0 ? (chartOption === 'line' ? (jsx(LineChart, { historicalPrices: historicalPrices, hasDiscount: hasDiscount, bondPrice: bondPrice ?? '0', tokenPrice: selectedBond.payoutTokenPrice ?? '0' })) : (jsx(CandleStickChart, { historicalPrices: historicalPrices, hasDiscount: hasDiscount, bondPrice: bondPrice ?? '0', tokenPrice: selectedBond.payoutTokenPrice ?? '0' }))) : (jsxs(Flex, { sx: { flexDirection: 'column', justifyContent: 'center', alignItems: 'center', width: '100%' }, children: [jsx(Svg, { icon: "placeholderMonkey" }), jsx(Flex, { sx: { mt: '15px' }, children: "No Historical Price for this Token" })] }))] }))] }));
35
+ return (jsxs(Flex, { sx: styles.priceContainer, children: [jsxs(Flex, { sx: { width: '100%', justifyContent: 'space-between', mb: '15px', pr: '20px' }, children: [jsx(Flex, { children: "Prices" }), jsxs(Flex, { children: [jsxs(Flex, { sx: { color: hasDiscount ? 'success' : 'error', fontSize: '12px', fontWeight: 500, mr: '15px' }, children: ["Bond Price: $", bondPrice] }), jsxs(Flex, { sx: { color: 'textDisabledButton', fontSize: '12px', fontWeight: 500 }, children: ["Market Price: $", getFirstNonZeroDigits(earnTokenPrice ?? 0)] })] })] }), show && (jsxs(Flex, { sx: styles.container, children: [jsxs(Flex, { sx: styles.buttonsContainer, children: [jsx(Flex, { sx: { ...styles.button, mr: '15px' }, onClick: () => setChartOption('line'), children: jsx(Svg, { icon: "lineChart", width: 20 }) }), jsx(Flex, { sx: styles.button, onClick: () => setChartOption('candleStick'), children: "D" })] }), historicalPrices && historicalPrices.length > 0 && !priceBelowChartPrecision ? (chartOption === 'line' ? (jsx(LineChart, { historicalPrices: historicalPrices, hasDiscount: hasDiscount, bondPrice: bondPrice ?? '0', tokenPrice: selectedBond.payoutTokenPrice ?? '0' })) : (jsx(CandleStickChart, { historicalPrices: historicalPrices, hasDiscount: hasDiscount, bondPrice: bondPrice ?? '0', tokenPrice: selectedBond.payoutTokenPrice ?? '0' }))) : (jsxs(Flex, { sx: { flexDirection: 'column', justifyContent: 'center', alignItems: 'center', width: '100%' }, children: [jsx(Svg, { icon: "placeholderMonkey" }), jsx(Flex, { sx: { mt: '15px' }, children: "No Historical Price for this Token" })] }))] }))] }));
35
36
  };
36
37
 
37
38
  export { PriceChart as default };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../../src/views/ProjectView/components/PriceChart/index.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react'\nimport CandleStickChart from './components/CandleStickChart'\nimport LineChart from './components/LineChart'\nimport { styles } from './styles'\nimport { BondsData } from '../../../../types/bonds'\nimport { HistoricalPrices } from '../../ProjectView'\nimport { getFirstNonZeroDigits } from '../../../../utils/roundNumber'\nimport Flex from '../../../../components/uikit-sdk/Flex'\nimport Svg from '../../../../components/uikit-sdk/Svg'\nimport { TIERS_WEIGHT } from '../../../../state/tiers/useTierPoints'\nimport { LaunchBondTiers } from '@ape.swap/apeswap-lists'\nimport { discountEarnTokenPrice } from '../../../../utils/displayHelpers'\nimport { findHighestTrueBondPrice } from '../../../../utils/bondPriceHelpers'\n\nconst PriceChart = ({\n selectedBond,\n historicalPrices,\n}: {\n selectedBond: BondsData\n historicalPrices?: HistoricalPrices[] | null\n}) => {\n const earnTokenPrice = parseFloat(selectedBond?.payoutTokenPrice ?? '0')\n const trueBondPrice = findHighestTrueBondPrice(TIERS_WEIGHT[LaunchBondTiers.Legend], selectedBond?.trueBondPrices)\n const bondPrice = discountEarnTokenPrice(selectedBond, true)\n const hasDiscount = (trueBondPrice?.bonus ?? 0) > 0\n const contractAddress = selectedBond.contractAddress[selectedBond.chainId]\n\n const [show, setShow] = useState<boolean>(false)\n const [chartOption, setChartOption] = useState<'line' | 'candleStick'>('line')\n\n useEffect(() => {\n // This effect is to ensure that the charts are only rendered on the client\n setShow(true)\n }, [])\n\n useEffect(() => {\n // This effect is to ensure the charts are re-rendered everytime the selectedBond changes\n setShow(false)\n const timer = setTimeout(() => {\n setShow(true)\n }, 50)\n return () => clearTimeout(timer)\n }, [contractAddress])\n\n return (\n <Flex sx={styles.priceContainer}>\n <Flex sx={{ width: '100%', justifyContent: 'space-between', mb: '15px', pr: '20px' }}>\n <Flex>Prices</Flex>\n <Flex>\n <Flex sx={{ color: hasDiscount ? 'success' : 'error', fontSize: '12px', fontWeight: 500, mr: '15px' }}>\n Bond Price: ${bondPrice}\n </Flex>\n <Flex sx={{ color: 'textDisabledButton', fontSize: '12px', fontWeight: 500 }}>\n Market Price: ${getFirstNonZeroDigits(earnTokenPrice ?? 0)}\n </Flex>\n </Flex>\n </Flex>\n {show && (\n <Flex sx={styles.container}>\n <Flex sx={styles.buttonsContainer}>\n <Flex sx={{ ...styles.button, mr: '15px' }} onClick={() => setChartOption('line')}>\n <Svg icon=\"lineChart\" width={20} />\n </Flex>\n <Flex sx={styles.button} onClick={() => setChartOption('candleStick')}>\n D\n </Flex>\n </Flex>\n {historicalPrices && historicalPrices.length > 0 ? (\n chartOption === 'line' ? (\n <LineChart\n historicalPrices={historicalPrices}\n hasDiscount={hasDiscount}\n bondPrice={bondPrice ?? '0'}\n tokenPrice={selectedBond.payoutTokenPrice ?? '0'}\n />\n ) : (\n <CandleStickChart\n historicalPrices={historicalPrices}\n hasDiscount={hasDiscount}\n bondPrice={bondPrice ?? '0'}\n tokenPrice={selectedBond.payoutTokenPrice ?? '0'}\n />\n )\n ) : (\n <Flex sx={{ flexDirection: 'column', justifyContent: 'center', alignItems: 'center', width: '100%' }}>\n <Svg icon=\"placeholderMonkey\" />\n <Flex sx={{ mt: '15px' }}>No Historical Price for this Token</Flex>\n </Flex>\n )}\n </Flex>\n )}\n </Flex>\n )\n}\n\nexport default PriceChart\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;;AAcA,MAAM,UAAU,GAAG,CAAC,EAClB,YAAY,EACZ,gBAAgB,GAIjB,KAAI;IACH,MAAM,cAAc,GAAG,UAAU,CAAC,YAAY,EAAE,gBAAgB,IAAI,GAAG,CAAC;AACxE,IAAA,MAAM,aAAa,GAAG,wBAAwB,CAAC,YAAY,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,cAAc,CAAC;IAClH,MAAM,SAAS,GAAG,sBAAsB,CAAC,YAAY,EAAE,IAAI,CAAC;IAC5D,MAAM,WAAW,GAAG,CAAC,aAAa,EAAE,KAAK,IAAI,CAAC,IAAI,CAAC;IACnD,MAAM,eAAe,GAAG,YAAY,CAAC,eAAe,CAAC,YAAY,CAAC,OAAO,CAAC;IAE1E,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC;IAChD,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAyB,MAAM,CA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EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAA,QAAA,EAAA,oCAAA,EAAA,CAA2C,IAC9D,CACR,CAAA,EAAA,CACI,CACR,CAAA,EAAA,CACI;AAEX;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/views/ProjectView/components/PriceChart/index.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react'\nimport CandleStickChart from './components/CandleStickChart'\nimport LineChart from './components/LineChart'\nimport { styles } from './styles'\nimport { BondsData } from '../../../../types/bonds'\nimport { HistoricalPrices } from '../../ProjectView'\nimport { getFirstNonZeroDigits } from '../../../../utils/roundNumber'\nimport Flex from '../../../../components/uikit-sdk/Flex'\nimport Svg from '../../../../components/uikit-sdk/Svg'\nimport { TIERS_WEIGHT } from '../../../../state/tiers/useTierPoints'\nimport { LaunchBondTiers } from '@ape.swap/apeswap-lists'\nimport { discountEarnTokenPrice } from '../../../../utils/displayHelpers'\nimport { findHighestTrueBondPrice } from '../../../../utils/bondPriceHelpers'\n\nconst PriceChart = ({\n selectedBond,\n historicalPrices,\n}: {\n selectedBond: BondsData\n historicalPrices?: HistoricalPrices[] | null\n}) => {\n const earnTokenPrice = parseFloat(selectedBond?.payoutTokenPrice ?? '0')\n const trueBondPrice = findHighestTrueBondPrice(TIERS_WEIGHT[LaunchBondTiers.Legend], selectedBond?.trueBondPrices)\n const bondPrice = discountEarnTokenPrice(selectedBond, true)\n const hasDiscount = (trueBondPrice?.bonus ?? 0) > 0\n const contractAddress = selectedBond.contractAddress[selectedBond.chainId]\n\n const [show, setShow] = useState<boolean>(false)\n const priceBelowChartPrecision = earnTokenPrice > 0 && earnTokenPrice < 1e-6\n const [chartOption, setChartOption] = useState<'line' | 'candleStick'>('line')\n\n useEffect(() => {\n // This effect is to ensure that the charts are only rendered on the client\n setShow(true)\n }, [])\n\n useEffect(() => {\n // This effect is to ensure the charts are re-rendered everytime the selectedBond changes\n setShow(false)\n const timer = setTimeout(() => {\n setShow(true)\n }, 50)\n return () => clearTimeout(timer)\n }, [contractAddress])\n\n return (\n <Flex sx={styles.priceContainer}>\n <Flex sx={{ width: '100%', justifyContent: 'space-between', mb: '15px', pr: '20px' }}>\n <Flex>Prices</Flex>\n <Flex>\n <Flex sx={{ color: hasDiscount ? 'success' : 'error', fontSize: '12px', fontWeight: 500, mr: '15px' }}>\n Bond Price: ${bondPrice}\n </Flex>\n <Flex sx={{ color: 'textDisabledButton', fontSize: '12px', fontWeight: 500 }}>\n Market Price: ${getFirstNonZeroDigits(earnTokenPrice ?? 0)}\n </Flex>\n </Flex>\n </Flex>\n {show && (\n <Flex sx={styles.container}>\n <Flex sx={styles.buttonsContainer}>\n <Flex sx={{ ...styles.button, mr: '15px' }} onClick={() => setChartOption('line')}>\n <Svg icon=\"lineChart\" width={20} />\n </Flex>\n <Flex sx={styles.button} onClick={() => setChartOption('candleStick')}>\n D\n </Flex>\n </Flex>\n {historicalPrices && historicalPrices.length > 0 && !priceBelowChartPrecision ? (\n chartOption === 'line' ? (\n <LineChart\n historicalPrices={historicalPrices}\n hasDiscount={hasDiscount}\n bondPrice={bondPrice ?? '0'}\n tokenPrice={selectedBond.payoutTokenPrice ?? '0'}\n />\n ) : (\n <CandleStickChart\n historicalPrices={historicalPrices}\n hasDiscount={hasDiscount}\n bondPrice={bondPrice ?? '0'}\n tokenPrice={selectedBond.payoutTokenPrice ?? '0'}\n />\n )\n ) : (\n <Flex sx={{ flexDirection: 'column', justifyContent: 'center', alignItems: 'center', width: '100%' }}>\n <Svg icon=\"placeholderMonkey\" />\n <Flex sx={{ mt: '15px' }}>No Historical Price for this Token</Flex>\n </Flex>\n )}\n </Flex>\n )}\n </Flex>\n )\n}\n\nexport default PriceChart\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;;AAcA,MAAM,UAAU,GAAG,CAAC,EAClB,YAAY,EACZ,gBAAgB,GAIjB,KAAI;IACH,MAAM,cAAc,GAAG,UAAU,CAAC,YAAY,EAAE,gBAAgB,IAAI,GAAG,C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WAAW,EACxB,SAAS,EAAE,SAAS,IAAI,GAAG,EAC3B,UAAU,EAAE,YAAY,CAAC,gBAAgB,IAAI,GAAG,EAAA,CAChD,KAEFA,GAAA,CAAC,gBAAgB,EAAA,EACf,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,IAAI,GAAG,EAC3B,UAAU,EAAE,YAAY,CAAC,gBAAgB,IAAI,GAAG,EAAA,CAChD,CACH,KAEDD,IAAA,CAAC,IAAI,IAAC,EAAE,EAAE,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,aAClGC,GAAA,CAAC,GAAG,EAAA,EAAC,IAAI,EAAC,mBAAmB,EAAA,CAAG,EAChCA,GAAA,CAAC,IAAI,EAAA,EAAC,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAA,QAAA,EAAA,oCAAA,EAAA,CAA2C,IAC9D,CACR,CAAA,EAAA,CACI,CACR,CAAA,EAAA,CACI;AAEX;;;;"}
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": "6.0.3",
6
+ "version": "6.0.4",
7
7
  "module": "dist/main.js",
8
8
  "type": "module",
9
9
  "types": "dist/main.d.ts",