Skip to content

Commit

Permalink
Hubble Stats dummy data (#1499)
Browse files Browse the repository at this point in the history
  • Loading branch information
vutuanlinh2k2 authored Aug 4, 2023
1 parent 926caf6 commit 85ac1bd
Show file tree
Hide file tree
Showing 34 changed files with 622 additions and 254 deletions.
2 changes: 2 additions & 0 deletions apps/hubble-stats/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export default async function Index() {
return (
<div className="py-4 space-y-6">
<OverviewChartsContainer />
{/* @ts-expect-error Server Component */}
<KeyMetricsTableContainer />
{/* @ts-expect-error Server Component */}
<ShieldedTablesContainer />
</div>
);
Expand Down
14 changes: 10 additions & 4 deletions apps/hubble-stats/app/pool/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ export default function Pool({ params }: { params: { slug: string } }) {
<div className="py-4 space-y-8">
<div className="flex flex-col lg:flex-row gap-4">
<div className="lg:w-[400px]">
<PoolOverviewContainer />
{/* TypeScript doesn't understand async components. */}
{/* Current approach: https://github.com/vercel/next.js/issues/42292#issuecomment-1298459024 */}
{/* @ts-expect-error Server Component */}
<PoolOverviewContainer poolAddress={poolAddress} />
</div>
<div className="flex-grow"></div>
</div>

<NetworkTablesContainer />
{/* @ts-expect-error Server Component */}
<NetworkTablesContainer poolAddress={poolAddress} />

<PoolTransactionsTableContainer />
{/* @ts-expect-error Server Component */}
<PoolTransactionsTableContainer poolAddress={poolAddress} />

<PoolMetadataTableContainer />
{/* @ts-expect-error Server Component */}
<PoolMetadataTableContainer poolAddress={poolAddress} />
</div>
);
}
14 changes: 9 additions & 5 deletions apps/hubble-stats/components/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ import { BreadcrumbType } from './types';

const Breadcrumbs: FC = () => {
const pathname = usePathname();
const parts = pathname.split('/');
let activeItem = parts[parts.length - 1];

const breadCrumbs = useMemo(() => {
const parts = pathname.split('/');
const activeItem = parts[parts.length - 1];
if (parts.length === 3 && parts[0] === '' && parts[1] === 'pool') {
// TODO: handle getting pool name from address and redirect user if invalid address
activeItem = 'webbParachain';
}

const breadCrumbs = useMemo(() => {
const breadCrumbItems: BreadcrumbType[] = [
{
label: 'Hubble Overview',
isLast: activeItem !== '' ? false : true,
isLast: activeItem === '',
icon: (
<ContrastLine className={activeItem !== '' ? 'fill-mono-120' : ''} />
),
Expand All @@ -39,7 +43,7 @@ const Breadcrumbs: FC = () => {
}

return breadCrumbItems;
}, [pathname]);
}, [activeItem]);

return (
<BreadcrumbsCmp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ const staticColumns: ColumnDef<NetworkPoolType, any>[] = [
];

const NetworkPoolTable: FC<NetworkPoolTableProps> = ({
typedChainIds,
data,
typedChainIds = [],
data = [],
prefixUnit = '$',
}) => {
const sortedTypedChainIds = useMemo(
Expand Down
4 changes: 2 additions & 2 deletions apps/hubble-stats/components/NetworkPoolTable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export interface NetworkPoolTableProps {
/**
* The list of all available chains
*/
typedChainIds: number[];
typedChainIds?: number[];

/**
* The data for whole table
*/
data: Array<NetworkPoolType>;
data?: Array<NetworkPoolType>;

/**
* The prefix unit of all the values on the table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ const staticColumns: ColumnDef<NetworkTokenType, any>[] = [
className="text-mono-200 dark:text-mono-0"
/>
),
cell: (props) => <NumberCell value={props.getValue()} prefix="$" />,
cell: (props) => (
<NumberCell value={props.getValue()} prefix="$" className="lowercase" />
),
}),
];

const NetworkTokenTable: FC<NetworkTokenTableProps> = ({
typedChainIds,
data,
typedChainIds = [],
data = [],
prefixUnit = '$',
}) => {
const sortedTypedChainIds = useMemo(
Expand Down Expand Up @@ -106,6 +108,7 @@ const NetworkTokenTable: FC<NetworkTokenTableProps> = ({
<NumberCell
value={props.row.original.chainsData[typedChainId]}
prefix={prefixUnit}
className="lowercase"
/>
) : (
<Typography variant="body1" ta="center">
Expand Down
4 changes: 2 additions & 2 deletions apps/hubble-stats/components/NetworkTokenTable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ export interface NetworkTokenTableProps {
/**
* The list of all available chains
*/
typedChainIds: number[];
typedChainIds?: number[];

/**
* The data for whole table (list of tokens and subTokens)
*/
data: Array<NetworkTokenType>;
data?: Array<NetworkTokenType>;

/**
* The prefix unit of all the values on the table
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { FC } from 'react';
import cx from 'classnames';
import {
createColumnHelper,
useReactTable,
Expand Down Expand Up @@ -36,27 +37,28 @@ const columns: ColumnDef<PoolAttributeType, any>[] = [
<Typography
variant="body1"
ta="center"
className="text-mono-140 dark:text-mono-40"
className={cx(
'text-mono-140 dark:text-mono-40',
'flex justify-center items-center gap-1'
)}
>
{props.getValue() ? (
props.row.original.isAddress ? (
<div className="flex justify-center items-center gap-1">
{shortenHex(props.getValue())}
{props.row.original.externalLink && (
<a
href={props.row.original.externalLink}
target="_blank"
rel="noreferrer"
>
<ExternalLinkIcon className="fill-mono-140 dark:fill-mono-40" />
</a>
)}
</div>
) : (
props.getValue()
)
) : (
{props.getValue() === undefined ? (
'-'
) : props.row.original.isAddress ? (
<>
{shortenHex(props.getValue())}
{props.row.original.externalLink && (
<a
href={props.row.original.externalLink}
target="_blank"
rel="noreferrer"
>
<ExternalLinkIcon className="fill-mono-140 dark:fill-mono-40" />
</a>
)}
</>
) : (
props.getValue()
)}
</Typography>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const PoolOverviewItem: FC<PoolOverviewItemProps> = ({
<div className="flex justify-center items-center gap-1">
<Typography variant="h5" fw="black" className="text-center">
{value && (prefix ?? '')}
{getRoundedAmountString(value, 2, {
{getRoundedAmountString(value, 1, {
roundingFunction: Math.floor,
totalLength: 0,
})}
Expand All @@ -42,7 +42,7 @@ const PoolOverviewItem: FC<PoolOverviewItemProps> = ({
'rotate-90 !fill-red-70': changeRate < 0,
})}
/>
{getRoundedAmountString(Math.abs(changeRate), 2)}%
{getRoundedAmountString(Math.abs(changeRate), 1)}%
</Typography>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Table as RTTable,
} from '@tanstack/react-table';
import { Table, fuzzyFilter, ChainChip } from '@webb-tools/webb-ui-components';
import { chainsConfig } from '@webb-tools/dapp-config/chains';

import { PoolTransactionType, PoolTransactionsTableProps } from './types';
import {
Expand Down Expand Up @@ -45,16 +46,18 @@ const columns: ColumnDef<PoolTransactionType, any>[] = [
/>
),
}),
columnHelper.accessor('source', {
columnHelper.accessor('sourceTypedChainId', {
header: () => <HeaderCell title="Source" className="justify-start" />,
cell: (props) => (
<ChainChip
chainName={props.row.original.source}
chainType={props.row.original.sourceChainType}
chainName={chainsConfig[props.getValue()].name}
chainType={chainsConfig[props.getValue()].group}
// shorten the title to last word of the chain name
title={chainsConfig[props.getValue()].name.split(' ').pop()}
/>
),
}),
columnHelper.accessor('destination', {
columnHelper.accessor('destinationTypedChainId', {
header: () => <HeaderCell title="Destination" className="justify-start" />,
cell: (props) => <DestinationCell />,
}),
Expand Down
8 changes: 3 additions & 5 deletions apps/hubble-stats/components/PoolTransactionsTable/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { ChainGroup } from '@webb-tools/dapp-config';
import { ActivityType } from '../table/types';

export type PoolTransactionType = {
txHash: string;
activity: ActivityType;
tokenAmount: number;
tokenSymbol: string;
source: string;
sourceChainType: ChainGroup;
destination: string;
time: number;
sourceTypedChainId: number;
destinationTypedChainId?: number;
time?: string;
};

export interface PoolTransactionsTableProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const columns: ColumnDef<ShieldedAssetType, any>[] = [
];

const ShieldedAssetsTable: FC<ShieldedAssetsTableProps> = ({
data,
data = [],
pageSize,
}) => {
const table = useReactTable({
Expand Down
2 changes: 1 addition & 1 deletion apps/hubble-stats/components/ShieldedAssetsTable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export interface ShieldedAssetType {
}

export interface ShieldedAssetsTableProps {
data: ShieldedAssetType[];
data?: ShieldedAssetType[];
pageSize: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const columns: ColumnDef<ShieldedPoolType, any>[] = [
}),
columnHelper.accessor('token', {
header: () => <HeaderCell title="Token #" className="justify-end" />,
cell: (props) => <NumberCell value={props.getValue()} />,
cell: (props) => (
<NumberCell value={props.getValue()} className="text-right" />
),
}),
columnHelper.accessor('deposits24h', {
header: () => <HeaderCell title="24H Deposits" />,
Expand All @@ -65,7 +67,7 @@ const columns: ColumnDef<ShieldedPoolType, any>[] = [
];

const ShieldedPoolsTable: FC<ShieldedPoolsTableProps> = ({
data,
data = [],
pageSize,
}) => {
const table = useReactTable({
Expand Down
2 changes: 1 addition & 1 deletion apps/hubble-stats/components/ShieldedPoolsTable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export interface ShieldedPoolType {
}

export interface ShieldedPoolsTableProps {
data: ShieldedPoolType[];
data?: ShieldedPoolType[];
pageSize: number;
}
2 changes: 1 addition & 1 deletion apps/hubble-stats/components/table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface ActivityCellProps {
}

export interface TimeCellProps {
time?: number;
time?: string;
className?: string;
}

Expand Down
Loading

0 comments on commit 85ac1bd

Please sign in to comment.