Skip to content

Commit

Permalink
Integrate back-end with Overview Charts and Key Metrics Table (#1557)
Browse files Browse the repository at this point in the history
Co-authored-by: Trung-Tin Pham <[email protected]>
  • Loading branch information
vutuanlinh2k2 and AtelyPham authored Aug 25, 2023
1 parent ee60e32 commit a3853bd
Show file tree
Hide file tree
Showing 32 changed files with 778 additions and 156 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ BRIDGE_DAPP_HOSTED_ORBIT_MULTLICALL3_ADDRESS=""
BRIDGE_DAPP_ATHENA_ORBIT_MULTICALL3_DEPLOYMENT_BLOCK=0
BRIDGE_DAPP_HERMES_ORBIT_MULTICALL3_DEPLOYMENT_BLOCK=0
BRIDGE_DAPP_DEMETER_ORBIT_MULTICALL3_DEPLOYMENT_BLOCK=0

VANCHOR_ADDRESSES='["<VANCHOR_ADDRESS>"]'
ACTIVE_SUBGRAPHS="local"
30 changes: 28 additions & 2 deletions apps/hubble-stats/components/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { FC } from 'react';
import { FC, useMemo } from 'react';
import {
ResponsiveContainer,
AreaChart as AreaChartCmp,
Expand All @@ -10,6 +10,7 @@ import {
} from 'recharts';
import { useDarkMode } from '@webb-tools/webb-ui-components';

import { ChartTooltip } from '..';
import { AreaChartProps } from './types';

const AreaChart: FC<AreaChartProps> = ({
Expand All @@ -18,9 +19,17 @@ const AreaChart: FC<AreaChartProps> = ({
setValue,
width = '100%',
height = 180,
showTooltip = true,
tooltipLabel = '',
tooltipValuePrefix = '',
}) => {
const [isDarkMode] = useDarkMode();

const fillColor = useMemo(
() => (isDarkMode ? '#C6BBFA' : '#624FBE'),
[isDarkMode]
);

return (
<ResponsiveContainer width={width} height={height}>
<AreaChartCmp
Expand All @@ -44,21 +53,38 @@ const AreaChart: FC<AreaChartProps> = ({
fontWeight: 400,
}}
tickMargin={16}
interval="preserveStartEnd"
/>
<Tooltip
contentStyle={{ display: 'none' }}
content={({ active, payload }) => {
if (active && payload && payload.length) {
setValue && setValue(payload[0].payload['value']);
setDate && setDate(payload[0].payload['date']);
if (!showTooltip) {
return null;
}
return (
<ChartTooltip
date={payload[0].payload['date']}
info={[
{
color: fillColor,
label: tooltipLabel,
value: payload[0].payload['value'],
valuePrefix: tooltipValuePrefix,
},
]}
/>
);
}

return null;
}}
/>
<Area
dataKey="value"
stroke={isDarkMode ? '#C6BBFA' : '#624FBE'}
stroke={fillColor}
fillOpacity={0}
strokeWidth={2}
/>
Expand Down
3 changes: 3 additions & 0 deletions apps/hubble-stats/components/AreaChart/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ export type AreaChartProps = {
setDate: (date: Date | null) => void;
width?: number | string;
height?: number | string;
showTooltip?: boolean;
tooltipLabel?: string;
tooltipValuePrefix?: string;
};
1 change: 1 addition & 0 deletions apps/hubble-stats/components/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const BarChart: FC<BarChartProps> = ({
fontWeight: 400,
}}
tickMargin={16}
interval="preserveStartEnd"
/>
<Tooltip
contentStyle={{ display: 'none' }}
Expand Down
33 changes: 33 additions & 0 deletions apps/hubble-stats/components/ChartTooltip/ChartTooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { FC } from 'react';
import { Typography } from '@webb-tools/webb-ui-components';

import { ChartTooltipProps } from './types';

const ChartTooltip: FC<ChartTooltipProps> = ({ date, info }) => {
return (
<div className="rounded-lg p-2 bg-[rgba(255,255,255,0.70)] dark:bg-[rgba(31,29,43,0.70)]">
<Typography variant="body2">
{new Date(date).toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
})}
</Typography>
{info.map((item, idx) => (
<div key={idx} className="flex items-center gap-1">
<div
className="rounded-full w-2 h-2"
style={{ backgroundColor: item.color }}
/>
<Typography variant="body2">
{item.label}: {item.valuePrefix ?? ''}
{item.value.toFixed(2)}
{item.valueSuffix ?? ''}
</Typography>
</div>
))}
</div>
);
};

export default ChartTooltip;
1 change: 1 addition & 0 deletions apps/hubble-stats/components/ChartTooltip/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as ChartTooltip } from './ChartTooltip';
10 changes: 10 additions & 0 deletions apps/hubble-stats/components/ChartTooltip/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface ChartTooltipProps {
date: Date;
info: Array<{
color: string;
label: string;
value: number;
valuePrefix?: string;
valueSuffix?: string;
}>;
}
46 changes: 24 additions & 22 deletions apps/hubble-stats/components/KeyMetricItem/KeyMetricItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { Typography } from '@webb-tools/webb-ui-components';
import { getRoundedAmountString } from '@webb-tools/webb-ui-components/utils';

import { MetricItemProps } from './types';
import { getRoundedDownWith2Decimals } from '../../utils';

const KeyMetricItem: FC<MetricItemProps> = ({
title,
value,
prefix,
changeRate,
suffix,
}) => {
return (
<div
Expand All @@ -28,34 +30,34 @@ const KeyMetricItem: FC<MetricItemProps> = ({
<Typography
variant="body1"
fw="black"
className="uppercase text-mono-140 dark:text-mono-40"
className="text-mono-140 dark:text-mono-40"
>
{value && (prefix ?? '')}
{typeof value === 'number' && (prefix ?? '')}
{typeof value === 'number' && value < 10000
? value
: getRoundedAmountString(value, 2, {
roundingFunction: Math.floor,
totalLength: 0,
})}
? Math.floor(value * 100) / 100
: getRoundedDownWith2Decimals(value)}
{typeof value === 'number' && (suffix ?? '')}
</Typography>
</span>

{/* Change Rate */}
{changeRate && (
<span>
<Typography
variant="body2"
fw="bold"
className={cx({
'!text-green-70': changeRate >= 0,
'!text-red-70': changeRate < 0,
})}
>
({changeRate >= 0 ? `+` : `-`}
{getRoundedAmountString(Math.abs(changeRate), 2)}%)
</Typography>
</span>
)}
{typeof changeRate === 'number' &&
Number.isFinite(changeRate) &&
!Number.isNaN(changeRate) && (
<span>
<Typography
variant="body2"
fw="bold"
className={cx({
'!text-green-70': changeRate >= 0,
'!text-red-70': changeRate < 0,
})}
>
({changeRate >= 0 ? `+` : `-`}
{getRoundedAmountString(Math.abs(changeRate), 2)}%)
</Typography>
</span>
)}
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions apps/hubble-stats/components/KeyMetricItem/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export interface MetricItemProps {
value?: number;
changeRate?: number;
prefix?: string;
suffix?: string;
}
77 changes: 77 additions & 0 deletions apps/hubble-stats/components/VolumeChart/VolumeChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use client';

import { FC } from 'react';
import { ResponsiveContainer, BarChart, XAxis, Tooltip, Bar } from 'recharts';

import { ChartTooltip } from '..';
import { VolumeChartProps } from './types';

const VolumeChart: FC<VolumeChartProps> = ({
data,
setValue,
setDate,
width = '100%',
height = 180,
}) => {
return (
<ResponsiveContainer width={width} height={height}>
<BarChart
data={data}
onMouseLeave={() => {
setValue && setValue(null);
setDate && setDate(null);
}}
barGap={0}
>
<XAxis
dataKey="date"
tickFormatter={(date) =>
new Date(date).toLocaleDateString('en-US', {
day: 'numeric',
})
}
strokeOpacity={0}
tick={{
fontSize: '16px',
fill: '#9CA0B0',
fontWeight: 400,
}}
tickMargin={16}
interval="preserveStartEnd"
/>
<Tooltip
content={({ active, payload }) => {
if (active && payload && payload.length) {
setValue && setValue(payload[0].payload['deposit']);
setDate && setDate(payload[0].payload['date']);
return (
<ChartTooltip
date={payload[0].payload['date']}
info={[
{
color: '#624FBE',
label: 'Deposits',
value: payload[0].payload['deposit'],
valueSuffix: ' tTNT',
},
{
color: '#B5A9F2',
label: 'Withdrawals',
value: payload[0].payload['withdrawal'],
valueSuffix: ' tTNT',
},
]}
/>
);
}
return null;
}}
/>
<Bar dataKey="deposit" fill="#624FBE" />
<Bar dataKey="withdrawal" fill="#B5A9F2" />
</BarChart>
</ResponsiveContainer>
);
};

export default VolumeChart;
1 change: 1 addition & 0 deletions apps/hubble-stats/components/VolumeChart/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as VolumeChart } from './VolumeChart';
11 changes: 11 additions & 0 deletions apps/hubble-stats/components/VolumeChart/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type VolumeChartProps = {
data: Array<{
date: Date;
deposit: number;
withdrawal: number;
}>;
setValue: (value: number | null) => void;
setDate: (date: Date | null) => void;
width?: number | string;
height?: number | string;
};
2 changes: 2 additions & 0 deletions apps/hubble-stats/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './AreaChart';
export * from './BarChart';
export * from './Breadcrumbs';
export * from './ChartTooltip';
export * from './KeyMetricItem';
export * from './NetworkPoolTable';
export * from './NetworkTokenTable';
Expand All @@ -10,5 +11,6 @@ export * from './PoolTransactionsTable';
export * from './PoolTypeChip';
export * from './ShieldedAssetsTable';
export * from './ShieldedPoolsTable';
export * from './VolumeChart';

export * from './sideBar';
18 changes: 15 additions & 3 deletions apps/hubble-stats/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import vAnchorClient from '@webb-tools/vanchor-client';

export const vAnchorAddresses = ['0x4b88368Eb14D7d09f0ca737832cEBfb8F12e3f05'];

export const allSubgraphUrls = [
export const LIVE_SUBGRAPH_URLS = [
vAnchorClient.SubgraphUrl.vAnchorOrbitAthena,
vAnchorClient.SubgraphUrl.vAnchorOrbitHermes,
vAnchorClient.SubgraphUrl.vAnchorOrbitDemeter,
];

export const LOCAL_SUBGRAPH_URLS = [
vAnchorClient.SubgraphUrl.vAnchorAthenaLocal,
vAnchorClient.SubgraphUrl.vAnchorHermesLocal,
vAnchorClient.SubgraphUrl.vAnchorDemeterLocal,
];

export const ACTIVE_SUBGRAPH_URLS = process.env.USING_LOCAL_SUBGRAPHS
? LOCAL_SUBGRAPH_URLS
: LIVE_SUBGRAPH_URLS;

export const VANCHOR_ADDRESSES: string[] = process.env.VANCHOR_ADDRESSES
? JSON.parse(process.env.VANCHOR_ADDRESSES)
: ['0x7aA556dD0AF8bed063444E14A6A9af46C9266973'];
Loading

0 comments on commit a3853bd

Please sign in to comment.