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

More info on the sale details modal #207

Merged
merged 6 commits into from
Aug 8, 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
8 changes: 7 additions & 1 deletion src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,18 @@ export const fetchSalesHistoryData = async (
const query = `{
sales(
after: ${after},
orderBy: REGION_BEGIN_DESC
orderBy: SALE_CYCLE_DESC
) {
nodes {
saleCycle
regionBegin
regionEnd
height
saleEnd
timestamp
tsSaleEnd
startPrice
endPrice
}
pageInfo {
hasNextPage
Expand Down
9 changes: 6 additions & 3 deletions src/components/Charts/SalePrice/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { CircularProgress, Stack } from '@mui/material';
import { ApexOptions } from 'apexcharts';
import moment from 'moment';
import dynamic from 'next/dynamic';
import * as React from 'react';

import { formatNumber, planckBnToUnit } from '@/utils/functions';
import {
formatNumber,
getTimeStringShort,
planckBnToUnit,
} from '@/utils/functions';
import { getCorePriceAt, isNewPricing } from '@/utils/sale';

import { useCoretimeApi } from '@/contexts/apis';
Expand Down Expand Up @@ -135,7 +138,7 @@ export const SalePriceChart = () => {
shared: false,
x: {
formatter: (v: number) =>
v === currentTimestamp ? 'Now' : moment(v).format('D MMM HH:mm'),
v === currentTimestamp ? 'Now' : getTimeStringShort(v),
},
},
grid: {
Expand Down
25 changes: 25 additions & 0 deletions src/components/Elements/InfoItem/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Stack, Typography, useTheme } from '@mui/material';

export type ItemDetail = {
label: string;
value: string | React.ReactNode;
};
export const InfoItem = ({ label, value }: ItemDetail) => {
const theme = useTheme();
return (
<Stack direction='column' gap='0.5rem'>
<Typography sx={{ color: theme.palette.text.primary }}>
{label}
</Typography>
<Typography
sx={{
color: theme.palette.common.black,
fontWeight: 700,
marginRight: '0.2em',
}}
>
{value}
</Typography>
</Stack>
);
};
1 change: 1 addition & 0 deletions src/components/Elements/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './Banner';
export * from './Buttons';
export * from './Cards';
export * from './CountDown';
export * from './InfoItem';
export * from './Inputs';
export * from './Label';
export * from './Link';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/Orders/OrderCreation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export const OrderCreationModal = ({
</FormControl>
</Stack>
<Typography>Region duration:</Typography>
<Stack sx={{ padding: '1rem', bgcolor: '#EFF0F3' }} gap='1rem'>
<Stack padding='1rem' bgcolor='#EFF0F3' gap='1rem'>
<FormControl>
<ToggleButtonGroup
value={durationType}
Expand Down
79 changes: 75 additions & 4 deletions src/components/Modals/SaleDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,59 @@
import { Warning } from '@mui/icons-material';
import InfoIcon from '@mui/icons-material/Info';
import {
Box,
CircularProgress,
Dialog,
DialogActions,
DialogContent,
DialogProps,
IconButton,
Stack,
Tooltip,
Typography,
useTheme,
} from '@mui/material';
import React from 'react';

import { useSaleDetails } from '@/hooks';
import { getBalanceString, getTimeStringShort } from '@/utils/functions';

import { ActionButton } from '@/components/Elements';
import { ActionButton, InfoItem } from '@/components/Elements';
import { PurchaseHistoryTable } from '@/components/Tables';

import { useCoretimeApi } from '@/contexts/apis';
import { useNetwork } from '@/contexts/network';
import { SalesHistoryItem } from '@/models';

import styles from './index.module.scss';

interface SaleDetailsModalProps extends DialogProps {
onClose: () => void;
saleCycle: number;
info: SalesHistoryItem;
}

export const SaleDetailsModal = ({
open,
onClose,
saleCycle,
info,
}: SaleDetailsModalProps) => {
const theme = useTheme();
const { network } = useNetwork();
const {
state: { decimals, symbol },
} = useCoretimeApi();
const {
saleCycle,
regionBegin,
regionEnd,
startPrice,
endPrice,
startTimestamp,
endTimestamp,
startBlock,
endBlock,
} = info;

const { loading, data, isError } = useSaleDetails(network, saleCycle);

return (
Expand All @@ -48,7 +69,7 @@ export const SaleDetailsModal = ({
variant='subtitle1'
sx={{ color: theme.palette.common.black }}
>
Sale Details
Coretime Sale#{saleCycle}
</Typography>
</Box>
{loading || isError ? (
Expand All @@ -64,6 +85,56 @@ export const SaleDetailsModal = ({
</Stack>
) : (
<Box className={styles.tableContainer}>
<Stack direction='row' justifyContent='space-between'>
<InfoItem
label='Region Begin'
value={regionBegin.toLocaleString()}
/>
<InfoItem
label='Length'
value={(regionEnd - regionBegin).toLocaleString()}
/>
<InfoItem
label='Start Price'
value={getBalanceString(
startPrice.toString(),
decimals,
symbol
)}
/>
<InfoItem
label='End Price'
value={getBalanceString(endPrice.toString(), decimals, symbol)}
/>
</Stack>
<Stack direction='row' alignItems='center'>
<Typography sx={{ color: theme.palette.text.primary }}>
{endTimestamp ? 'Sale Ended' : 'Sale Started'}
</Typography>
<Typography
sx={{
color: theme.palette.common.black,
fontWeight: 700,
ml: '1rem',
}}
>
{endTimestamp
? `${getTimeStringShort(
startTimestamp
)} ~ ${getTimeStringShort(endTimestamp)}`
: getTimeStringShort(startTimestamp)}
</Typography>
<Tooltip
title={`Start Block: ${startBlock.toLocaleString()}${
endBlock ? ' End Block: ' + endBlock.toLocaleString() : ''
}`}
placement='right'
>
<IconButton>
<InfoIcon />
</IconButton>
</Tooltip>
</Stack>
<PurchaseHistoryTable data={data} />
</Box>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,3 @@
align-items: center;
justify-content: space-between;
}

.infoItem {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
31 changes: 4 additions & 27 deletions src/components/Panels/SaleInfoPanel/DetailCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import { Box, Paper, Typography, useTheme } from '@mui/material';
import Image from 'next/image';
import React from 'react';

import styles from './index.module.scss';
import { InfoItem, ItemDetail } from '@/components/Elements';

interface ItemDetail {
label: string;
value: string | React.ReactNode;
}
import styles from './index.module.scss';

interface DetailCardProps {
icon: any;
Expand All @@ -20,26 +17,6 @@ interface DetailCardProps {
children?: React.ReactNode;
}

const ItemContainer = ({ label, value }: ItemDetail) => {
const theme = useTheme();
return (
<Box className={styles.infoItem}>
<Typography sx={{ color: theme.palette.text.primary }}>
{label}
</Typography>
<Typography
sx={{
color: theme.palette.common.black,
fontWeight: 700,
marginRight: '0.2em',
}}
>
{value}
</Typography>
</Box>
);
};

export const DetailCard = ({
icon,
title,
Expand Down Expand Up @@ -68,8 +45,8 @@ export const DetailCard = ({
>
{items ? (
<>
<ItemContainer {...items.left} />
<ItemContainer {...items.right} />
<InfoItem {...items.left} />
<InfoItem {...items.right} />
</>
) : (
children
Expand Down
7 changes: 3 additions & 4 deletions src/components/Panels/SaleInfoPanel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Box, Button, CircularProgress, useTheme } from '@mui/material';
import TimeAgo from 'javascript-time-ago';
import en from 'javascript-time-ago/locale/en.json';
import moment from 'moment';
import { useState } from 'react';

import { getBalanceString } from '@/utils/functions';
import { getBalanceString, getTimeStringShort } from '@/utils/functions';

import { SalePhaseCard } from '@/components/Elements';
import { PriceModal } from '@/components/Modals';
Expand Down Expand Up @@ -61,11 +60,11 @@ export const SaleInfoPanel = () => {
left: {
label:
saleStartTimestamp < Date.now() ? 'Started at' : 'Starts at:',
value: moment(saleStartTimestamp).format('D MMM HH:mm'),
value: getTimeStringShort(saleStartTimestamp),
},
right: {
label: saleEndTimestamp > Date.now() ? 'Ends at' : 'Ended at:',
value: moment(saleEndTimestamp).format('D MMMM HH:mm'),
value: getTimeStringShort(saleEndTimestamp),
},
}}
/>
Expand Down
7 changes: 3 additions & 4 deletions src/components/Regions/MarketRegion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import {
useTheme,
} from '@mui/material';
import { humanizer } from 'humanize-duration';
import moment from 'moment';
import React from 'react';

import { getBalanceString } from '@/utils/functions';
import { getBalanceString, getTimeStringShort } from '@/utils/functions';

import { useRelayApi } from '@/contexts/apis';
import { Listing } from '@/models';
Expand Down Expand Up @@ -94,15 +93,15 @@ export const MarketRegion = ({ listing }: MarketRegionProps) => {
<Typography
sx={{ color: theme.palette.common.black, fontWeight: 500 }}
>
{moment(beginTimestamp).format('D MMM HH:mm')}
{getTimeStringShort(beginTimestamp)}
</Typography>
</Box>
<Box className={styles.timeItem}>
<Typography>End: </Typography>
<Typography
sx={{ color: theme.palette.common.black, fontWeight: 500 }}
>
{moment(endTimestamp).format('D MMM HH:mm')}
{getTimeStringShort(endTimestamp)}
</Typography>
</Box>
</Box>
Expand Down
11 changes: 9 additions & 2 deletions src/components/Tables/PurchaseHistoryTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const PurchaseHistoryTable = ({ data }: PurchaseHistoryTableProps) => {

return (
<Stack direction='column' gap='1em'>
<TableContainer component={Paper} sx={{ height: '35rem' }}>
<TableContainer component={Paper} sx={{ height: '32rem' }}>
<Table stickyHeader>
<TableHead>
<TableRow>
Expand All @@ -76,7 +76,14 @@ export const PurchaseHistoryTable = ({ data }: PurchaseHistoryTableProps) => {
: data
).map(
(
{ address, core, extrinsicId: extrinsic_index, timestamp, price, type },
{
address,
core,
extrinsicId: extrinsic_index,
timestamp,
price,
type,
},
index
) => (
<StyledTableRow key={index}>
Expand Down
Loading
Loading