11 changed files with 134 additions and 50 deletions
@ -0,0 +1,41 @@ |
|||
import { Box, Center, Divider, HStack, Skeleton, Text } from "@chakra-ui/react"; |
|||
import React from "react"; |
|||
import Timestamp from "./Timestamp"; |
|||
import { PriceInfo } from "./Types"; |
|||
|
|||
interface Props { |
|||
priceInfo: PriceInfo | null; |
|||
} |
|||
|
|||
export default function CurrentPrice( |
|||
{ |
|||
priceInfo, |
|||
}: Props, |
|||
) { |
|||
let bid = <Skeleton height="20px" />; |
|||
let ask = <Skeleton height="20px" />; |
|||
let timestamp = <Skeleton height="20px" />; |
|||
|
|||
if (priceInfo) { |
|||
bid = <Text>{priceInfo.bid} USD</Text>; |
|||
ask = <Text>{priceInfo.ask} USD</Text>; |
|||
timestamp = <Timestamp timestamp={priceInfo.last_updated_at} />; |
|||
} |
|||
|
|||
return ( |
|||
<Box shadow={"md"} marginBottom={5} padding={5}> |
|||
<Center><Text fontWeight={"bold"}>Current Price</Text></Center> |
|||
<HStack> |
|||
<Text align={"left"}>Bid:</Text> |
|||
{bid} |
|||
</HStack> |
|||
<Divider marginTop={2} marginBottom={2} /> |
|||
<HStack> |
|||
<Text align={"left"}>Ask:</Text> |
|||
{ask} |
|||
</HStack> |
|||
<Divider marginTop={2} marginBottom={2} /> |
|||
{timestamp} |
|||
</Box> |
|||
); |
|||
} |
@ -0,0 +1,26 @@ |
|||
import { Text } from "@chakra-ui/react"; |
|||
import React from "react"; |
|||
import { unixTimestampToDate } from "./Types"; |
|||
|
|||
interface Props { |
|||
timestamp: number; |
|||
} |
|||
|
|||
export default function Timestamp( |
|||
{ |
|||
timestamp, |
|||
}: Props, |
|||
) { |
|||
return ( |
|||
<Text> |
|||
Updated: {unixTimestampToDate(timestamp).toLocaleDateString("en-US", { |
|||
year: "numeric", |
|||
month: "numeric", |
|||
day: "numeric", |
|||
hour: "2-digit", |
|||
minute: "2-digit", |
|||
second: "2-digit", |
|||
})} |
|||
</Text> |
|||
); |
|||
} |
Loading…
Reference in new issue