Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev to master #1564

Merged
merged 7 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions src/components/AreaTimelineChart/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import React from 'react';
import { Box } from '@material-ui/core';
import Chart from 'react-apexcharts';
import { useIsDarkMode } from 'state/user/hooks';
import { formatCompact, formatDateFromTimeStamp, formatNumber } from 'utils';
import 'components/styles/AreaChart.scss';

export interface AreaChartProps {
strokeColor?: string;
backgroundColor?: string;
gradientColor?: string | undefined;
data?: Array<any>;
yAxisValues?: Array<number>;
categories?: Array<string | null>;
width?: number | string;
height?: number | string;
}
const AreaTimelineChart: React.FC<AreaChartProps> = ({
strokeColor = '#00dced',
backgroundColor = '#004ce6',
gradientColor,
data = [],
yAxisValues,
width = 500,
height = 200,
}) => {
const dark = useIsDarkMode();
const _gradientColor = gradientColor || (dark ? '#64fbd3' : '#D4F8FB');
const yMax = yAxisValues
? Math.max(...yAxisValues.map((val) => Number(val)))
: 0;
const yMin = yAxisValues
? Math.min(...yAxisValues.map((val) => Number(val)))
: 0;

const series = [
{
name: 'Burn Amounts',
data: data as [number, number][],
},
];

const options = {
chart: {
sparkline: {
enabled: false,
},
toolbar: {
show: false,
},
zoom: {
enabled: false,
},
},
stroke: {
width: 2,
colors: [strokeColor],
curve: 'smooth' as any,
},
markers: {
colors: [strokeColor],
strokeWidth: 0,
},
fill: {
type: 'gradient',
colors: [_gradientColor],
gradient: {
gradientToColors: [backgroundColor],
shadeIntensity: 1,
opacityFrom: 0.5,
opacityTo: 0.15,
stops: [0, 100],
},
},
dataLabels: {
enabled: false,
},
grid: {
show: false,
padding: {
left: 0,
right: 0,
},
xaxis: {
lines: {
show: false,
},
},
},
legend: {
show: false,
},
tooltip: {
enabled: true,
theme: dark ? 'dark' : 'light',
fillSeriesColor: false,
custom: ({ series, seriesIndex, dataPointIndex }: any) => {
return `<div class="areaChartTooltip"><small>${formatDateFromTimeStamp(
data[dataPointIndex][0] / 1000,
'HH:mm MMM DD, YYYY',
)}</small><small><b>
${formatCompact(series[seriesIndex][dataPointIndex])}
</b></small></div>`;
},
},
yaxis: {
show: false,
min: yAxisValues ? yMin : undefined,
max: yAxisValues ? yMax : undefined,
tickAmount: yAxisValues?.length,
},
xaxis: {
axisBorder: {
show: false,
},
axisTicks: {
show: false,
},
tooltip: {
enabled: false,
},
type: 'datetime' as const,
},
};
return (
<Box display='flex' mt={2.5} width={width}>
<Box className='chartContainer'>
<Chart
options={options}
series={series}
type='area'
width='100%'
height={height}
/>
</Box>
{yAxisValues && (
<Box className='yAxis'>
{yAxisValues.map((value, index) => (
<p key={index}>
{// this is to show small numbers less than 0.0001
`${value > 0.0001 ? formatCompact(value) : formatNumber(value)}`}
</p>
))}
</Box>
)}
</Box>
);
};

export default AreaTimelineChart;
36 changes: 12 additions & 24 deletions src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,35 +176,23 @@ const Footer: React.FC = () => {
</Box>
</Grid>
</Grid>
{tabletWindowSize && (
<Box>
<Typography
style={{
marginBottom: '16px',
fontSize: '12px',
color: '#6880a3',
}}
>
Terms of Use
</Typography>
</Box>
)}
<Box
className={`copyrightWrapper ${
tabletWindowSize ? 'copyright-mobile' : ''
}`}
>
<small className='text-secondary'>
© {copyrightYear} QuickSwap. &nbsp;
</small>
<small className='text-secondary'>
<Link className='footer-link' to='/tos'>
{t('allRights')}
</Link>
</small>
{!tabletWindowSize && pathname === '/' && (
<Box className='fake-community-container'>&nbsp;</Box>
)}
<Box>
<small className='text-secondary'>
© {copyrightYear} QuickSwap. &nbsp;
</small>
</Box>
<Box>
<small className='text-secondary'>
<Link className='footer-link' to='/tos'>
{t('termsofuse')}
</Link>
</small>
</Box>
</Box>
</Box>
</Box>
Expand Down
1 change: 1 addition & 0 deletions src/components/styles/Footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
display: flex;
padding: 16px 0;
align-items: center;
justify-content: space-between;
color: #6880a3;
}

Expand Down
29 changes: 8 additions & 21 deletions src/pages/DragonPage/QuickBurnChart.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import React, { useState, useMemo } from 'react';
import { Box, duration } from '@material-ui/core';
import { Box } from '@material-ui/core';
import 'pages/styles/dragon.scss';
import { GlobalConst, GlobalData } from 'constants/index';
import { getLimitedData } from 'utils';
import { useActiveWeb3React } from 'hooks';
import { useQuery } from '@tanstack/react-query';
import Skeleton from '@material-ui/lab/Skeleton';
import { AreaChart } from 'components';
import {
getQuickBurnChartDates,
appendedZeroChartData,
formatNumber,
} from 'utils';
import AreaTimelineChart from 'components/AreaTimelineChart';
import { appendedZeroChartData, formatNumber } from 'utils';
import { useUSDCPriceFromAddress } from 'utils/useUSDCPrice';
import { DLQUICK } from 'constants/v3/addresses';

const QuickBurnChart: React.FC = () => {
const { chainId } = useActiveWeb3React();
const quickToken = DLQUICK[chainId];
const { price: quickPrice } = useUSDCPriceFromAddress(quickToken?.address);

const [durationIndex, setDurationIndex] = useState(
GlobalConst.quickBurnChart.ONE_DAY_CHART,
);
Expand Down Expand Up @@ -53,7 +47,7 @@ const QuickBurnChart: React.FC = () => {
const yAxisValues = useMemo(() => {
if (chartData && chartData.chartData) {
const amounts: number[] = chartData.chartData.map((value: any) =>
Number(value.amount),
Number(value[1]),
);

const minVolume = Math.floor(Math.min(...amounts));
Expand Down Expand Up @@ -112,20 +106,13 @@ const QuickBurnChart: React.FC = () => {
{isLoading ? (
<Skeleton variant='rect' width='100%' height={223} />
) : chartData && chartData.chartData ? (
<AreaChart
data={chartData.chartData.map((value: any) =>
Number(value.amount),
)}
<AreaTimelineChart
width='100%'
height={250}
strokeColor={'#3e92fe'}
gradientColor={'#448aff'}
data={chartData.chartData}
yAxisValues={yAxisValues}
dates={chartData.chartData.map((value: any) => value.timestamp)}
width='100%'
height={250}
categories={getQuickBurnChartDates(
chartData.chartData,
durationIndex,
)}
/>
) : (
<></>
Expand Down
4 changes: 3 additions & 1 deletion src/pages/PoolsPage/v3/SupplyLiquidityV3/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ export function SupplyLiquidityV3() {
/>
<Box mt={4} position='relative'>
<small className='weight-600'>{t('depositAmounts')}</small>
{gammaPair?.withdrawOnly && (
{(gammaPair?.withdrawOnly ||
liquidityRangeType ===
GlobalConst.v3LiquidityRangeType.DEFIEDGE_RANGE) && (
<Box className='v3-deposit-disable-banner'>
<p>{t('withdrawOnlyVault')}</p>
</Box>
Expand Down
77 changes: 28 additions & 49 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,66 +669,45 @@ export function getLimitedData(data: any[], count: number) {
return newArray;
}
export function appendedZeroChartData(data: any[], durationIndex) {
let newArray: any[] = [];
let newArray: number[][] = [];
const now = dayjs().unix();
let sum = 0;
data.map((value) => {
sum += Number(value.amount);
newArray.push([Number(value.timestamp * 1000), sum]);
});

if (durationIndex === GlobalConst.quickBurnChart.ONE_DAY_CHART) {
const minTimestamp = now - 86400;
const step = 3600;
for (let i = 0; i < 24; i++) {
const timestamp = minTimestamp + i * step;
newArray.push({ amount: '0', timestamp });
if (newArray.length === 0) {
newArray.push([minTimestamp * 1000, 0]);
newArray.push([now * 1000, 0]);
} else {
newArray.unshift([minTimestamp * 1000, 0]);
newArray.push([now * 1000, newArray[newArray.length - 1][1]]);
}
data.map((value) => {
const index = Math.floor((Number(value.timestamp) - minTimestamp) / step);
newArray[index].amount = (
Number(newArray[index].amount) + Number(value.amount)
).toString();
});
} else if (durationIndex === GlobalConst.quickBurnChart.ONE_WEEK_CHART) {
const minTimestamp = now - 86400 * 7;
const step = Math.floor((86400 * 7) / 21);
for (let i = 0; i < 21; i++) {
const timestamp = minTimestamp + i * step;
newArray.push({ amount: '0', timestamp });
if (newArray.length === 0) {
newArray.push([minTimestamp * 1000, 0]);
newArray.push([now * 1000, 0]);
} else {
newArray.unshift([minTimestamp * 1000, 0]);
newArray.push([now * 1000, newArray[newArray.length - 1][1]]);
}
data.map((value) => {
const index = Math.floor((Number(value.timestamp) - minTimestamp) / step);
newArray[index].amount = (
Number(newArray[index].amount) + Number(value.amount)
).toString();
});
} else if (durationIndex === GlobalConst.quickBurnChart.ONE_MONTH_CHART) {
// 31
const minTimestamp = now - 86400 * 31;
const step = 86400;
for (let i = 0; i < 31; i++) {
const timestamp = minTimestamp + i * step;
newArray.push({ amount: '0', timestamp });
const minTimestamp = now - 86400 * 30;
if (newArray.length === 0) {
newArray.push([minTimestamp * 1000, 0]);
newArray.push([now * 1000, 0]);
} else {
newArray.unshift([minTimestamp * 1000, 0]);
newArray.push([now * 1000, newArray[newArray.length - 1][1]]);
}
data.map((value) => {
const index = Math.floor((Number(value.timestamp) - minTimestamp) / step);
newArray[index].amount = (
Number(newArray[index].amount) + Number(value.amount)
).toString();
});
} else {
//ALL
const minTimestamp = Number(data[0].timestamp);
const maxTimestamp = now;
const step = (maxTimestamp - minTimestamp) / 31;
// 31
for (let i = 0; i < 31; i++) {
const timestamp = Math.floor(minTimestamp + step * i);
newArray.push({ amount: '0', timestamp });
}
data.map((value) => {
const index = Math.floor((Number(value.timestamp) - minTimestamp) / step);
newArray[index].amount = (
Number(newArray[index].amount) + Number(value.amount)
).toString();
});
newArray.push([now * 1000, newArray[newArray.length - 1][1]]);
}
newArray = newArray.sort((a, b) => a.timestamp - b.timestamp);
newArray = newArray.sort((a, b) => a[0] - b[0]);
return newArray;
}

Expand Down
Loading