From c09ef3e0770b7b467a7841aa6a5b271044650210 Mon Sep 17 00:00:00 2001 From: "ste.vaidis" Date: Sun, 11 Dec 2022 21:49:24 +0200 Subject: [PATCH] better types --- Front/src/coinDetails/coinChart.tsx | 4 +- Front/src/coinDetails/coinDetails.tsx | 4 - Front/src/coinDetails/coinInfo.tsx | 13 ++- Front/src/coinDetails/coinStats.tsx | 11 ++- Front/src/coinList/coinList-types.ts | 122 +++++++++++++------------- Front/src/index.css | 6 -- 6 files changed, 83 insertions(+), 77 deletions(-) diff --git a/Front/src/coinDetails/coinChart.tsx b/Front/src/coinDetails/coinChart.tsx index 45b41c5..96afe2c 100644 --- a/Front/src/coinDetails/coinChart.tsx +++ b/Front/src/coinDetails/coinChart.tsx @@ -85,8 +85,8 @@ const CoinChart = (props: ICoinChartProps): JSX.Element => { }); } - function formatChartLabels(data: any): any { - return data['prices'].map((value: (string | number | Date)[]) => + function formatChartLabels(data: IChartData): string[] { + return data['prices'].map((value: IChartDataItem) => format(new Date(value[0]), 'MM/dd/yyyy') ); } diff --git a/Front/src/coinDetails/coinDetails.tsx b/Front/src/coinDetails/coinDetails.tsx index f1c40b1..727b284 100644 --- a/Front/src/coinDetails/coinDetails.tsx +++ b/Front/src/coinDetails/coinDetails.tsx @@ -19,10 +19,6 @@ const CoinDetails = (): JSX.Element => { isSuccess, } = useGetCoinInfoQuery(id ? id : ''); - React.useEffect(() => { - console.log(data) - }, []) - return (
{isLoading &&
Loading...
} diff --git a/Front/src/coinDetails/coinInfo.tsx b/Front/src/coinDetails/coinInfo.tsx index 53e1431..75f4549 100644 --- a/Front/src/coinDetails/coinInfo.tsx +++ b/Front/src/coinDetails/coinInfo.tsx @@ -9,12 +9,24 @@ import Button from '@mui/material/Button'; import Grid from '@mui/material/Grid'; +import { IGetCoinInfoResponse } from '../coinApi-types' + +// export interface ICoinInfoProps { +// [key: string]: any; +// } + +// interface ICoinInfoProps { +// data: IGetCoinInfoResponse; +// } + + export interface ICoinInfoProps { [key: string]: any; } const CoinInfo = (props: ICoinInfoProps): JSX.Element => { const { data } = props; + console.log("CoinInfo props.data: ", data) return (
@@ -51,7 +63,6 @@ const CoinInfo = (props: ICoinInfoProps): JSX.Element => { Object.entries(data.links.chat_url).map( ([key, value]) => { if (Boolean(value)) { - console.log(value); const domain = new URL(String(value)); const label = domain.hostname.split(".")[0] return ( diff --git a/Front/src/coinDetails/coinStats.tsx b/Front/src/coinDetails/coinStats.tsx index 77d7686..fc624da 100644 --- a/Front/src/coinDetails/coinStats.tsx +++ b/Front/src/coinDetails/coinStats.tsx @@ -5,14 +5,19 @@ import TableContainer from '@mui/material/TableContainer'; import TableHead from '@mui/material/TableHead'; import TableRow from '@mui/material/TableRow'; -import { IGetCoinInfoResponse, IGetCoinInfoData } from '../coinApi-types' +import { IGetCoinInfoResponse } from '../coinApi-types' interface ICoinStatsProps { data: IGetCoinInfoResponse; } +interface IRow { + title: string; + value: string; +} + const CoinStats = (props: ICoinStatsProps): JSX.Element => { - console.log("CoinStats props", props) + // console.log("CoinStats props", props) const { data } = props; @@ -37,7 +42,7 @@ const CoinStats = (props: ICoinStatsProps): JSX.Element => { { - tableData.map((row: any, index: any) => ( + tableData.map((row: IRow, index: number) => ( {row.title} {row.value} diff --git a/Front/src/coinList/coinList-types.ts b/Front/src/coinList/coinList-types.ts index aa9c358..011897c 100644 --- a/Front/src/coinList/coinList-types.ts +++ b/Front/src/coinList/coinList-types.ts @@ -1,64 +1,64 @@ export interface IGetAssetsResponse { - result: { [key: string]: any }; - error: [] - } - - export interface IGetPairsResponse { - [key: string]: any ; - } - - export interface IGetDataResponse { - result: { [key: string]: any }; - error: [] - } - - export interface IGetDataRequest { - pair: string; - interval: number; - } - - export interface IOHLCData { - close: number; - date: Date; - high: number; - low: number; - open: number; - volume: number; - } - - export interface ChartProps { - data: IOHLCData[]; - itemWidth: number; - } - - export interface InitialData { - readonly data: IOHLCData[]; - readonly height: number; - readonly width: number; - readonly ratio: number; - readonly crosshair?: boolean; - } - - export interface IProps { + result: { [key: string]: any }; + error: [] +} + +export interface IGetPairsResponse { + [key: string]: any; +} + +export interface IGetDataResponse { + result: { [key: string]: any }; + error: [] +} + +export interface IGetDataRequest { + pair: string; + interval: number; +} + +export interface IOHLCData { + close: number; + date: Date; + high: number; + low: number; + open: number; + volume: number; +} + +export interface ChartProps { + data: IOHLCData[]; + itemWidth: number; +} + +export interface InitialData { + readonly data: IOHLCData[]; + readonly height: number; + readonly width: number; + readonly ratio: number; + readonly crosshair?: boolean; +} + +export interface IProps { + id: string; + pair: string; +} + +export interface IChartState { + assets: { [key: string]: any }; + pairs: { [key: string]: any }; + data: { [key: string]: any }; + items: { id: string; pair: string; - } - - export interface IChartState { - assets: { [key: string]: any }; - pairs: { [key: string]: any }; - data: { [key: string]: any }; - items: { - id: string; - pair: string; - data?: IOHLCData[] - }[] - } - - - export interface IintervalValue { - label: string; - value: number; - } - - export interface IintervalValues extends Array { } \ No newline at end of file + data?: IOHLCData[] + }[] +} + + +export interface IintervalValue { + label: string; + value: number; +} + +export interface IintervalValues extends Array { } \ No newline at end of file diff --git a/Front/src/index.css b/Front/src/index.css index b71c7c9..606d554 100644 --- a/Front/src/index.css +++ b/Front/src/index.css @@ -32,12 +32,6 @@ header a { color: #e15241 } - -/* #chart { - position: absolute; - height: 400px; -} */ - .coinName { font-weight: bold; margin-left: 10px;