From 8495a5cf8285a6c965c38d6705fc2c659b2492c2 Mon Sep 17 00:00:00 2001 From: saidam90 Date: Sat, 10 Aug 2024 03:49:01 +0400 Subject: [PATCH] Refactor and fix css --- src/app/components/CopyIcon.tsx | 33 ++++++ src/app/components/PriceChart.tsx | 191 +++++++++++++----------------- 2 files changed, 116 insertions(+), 108 deletions(-) create mode 100644 src/app/components/CopyIcon.tsx diff --git a/src/app/components/CopyIcon.tsx b/src/app/components/CopyIcon.tsx new file mode 100644 index 00000000..ef4da8b2 --- /dev/null +++ b/src/app/components/CopyIcon.tsx @@ -0,0 +1,33 @@ +import { CopyToClipboard } from "react-copy-to-clipboard"; +import { MdContentCopy } from "react-icons/md"; +import { setCopied } from "../state/priceChartSlice"; +import { DexterToast } from "components/DexterToaster"; +import { useAppDispatch } from "../hooks"; + +interface CopyIconProps { + targetUrl: string; +} + +export function CopyIcon({ targetUrl }: CopyIconProps) { + const dispatch = useAppDispatch(); + + const handleCopy = () => { + dispatch(setCopied(true)); + DexterToast.success("Copied!"); + + setTimeout(() => { + dispatch(setCopied(false)); + }, 2000); + }; + + return ( + <> + + + + + ); +} diff --git a/src/app/components/PriceChart.tsx b/src/app/components/PriceChart.tsx index 135501dd..00807d1b 100644 --- a/src/app/components/PriceChart.tsx +++ b/src/app/components/PriceChart.tsx @@ -7,15 +7,12 @@ import { handleCrosshairMove, initializeLegend, initialPriceChartState, - setCopied, } from "../state/priceChartSlice"; import { useAppDispatch, useAppSelector, useTranslations } from "../hooks"; import { displayNumber, getPrecision } from "../utils"; import * as tailwindConfig from "../../../tailwind.config"; -import { CopyToClipboard } from "react-copy-to-clipboard"; -import { MdContentCopy } from "react-icons/md"; import { shortenString } from "../utils"; -import { DexterToast } from "components/DexterToaster"; +import { CopyIcon } from "./CopyIcon"; interface PriceChartProps { data: OHLCVData[]; @@ -360,7 +357,6 @@ export function TradingChart() { export function PairInfoTab() { const t = useTranslations(); - const dispatch = useAppDispatch(); const { pairsList } = useAppSelector((state) => state.pairSelector); const selectedPairAddress = useAppSelector( (state) => state.pairSelector.address @@ -372,121 +368,100 @@ export function PairInfoTab() { if (!pairInfo) { return "Selected pair not found in pairsList"; } - const { name, address, orderReceiptAddress, token1, token2 } = pairInfo; - - const handleCopy = () => { - dispatch(setCopied(true)); - DexterToast.success("Copied!"); - - setTimeout(() => { - dispatch(setCopied(false)); - }, 2000); - }; return ( <> -
-
{name}
+
+
{pairInfo.name}
-
- {t("pair_resource")} -
-
-
- - {shortenString(address, 8, 20, "...")} - - - - -
-
- -
- {t("order_receipt_address")} -
-
-
- - {shortenString(orderReceiptAddress, 8, 20, "...")} - - - - -
-
+ +
-
-
- {token1?.symbol} -

- {token1?.name.split(" ")[0]} ({token1?.symbol}) -

-
-
-

- {t("resource")} -

-
-

- {shortenString(token1?.address, 8, 10, "...")} -

- - - -
-
-
+ +
+ +
+
+ + ); +} -
- -
-
- {token2?.symbol} -

- {token2?.name.split(" ")[0]} ({token2?.symbol}) -

-
-
-

- {t("resource")} -

-
-

- {shortenString(token2?.address, 8, 10, "...")} -

- - - -
-
-
+interface LabelAndAddressProps { + label: string; + address: string; + shortenLength?: { min: number; max: number }; +} + +function LabelAndAddress({ + label, + address, + shortenLength, +}: LabelAndAddressProps) { + const minLength = shortenLength?.min || 8; + const maxLength = shortenLength?.max || 20; + + return ( + <> +
+ {label} +
+
+
+ + {shortenString(address, minLength, maxLength, "...")} + +
); } +interface Token { + iconUrl: string; + symbol: string; + name: string; + address: string; +} + +interface TokenInfoProps { + token: Token; +} + +function CoinInfo({ token }: TokenInfoProps) { + const t = useTranslations(); + + return ( +
+
+ {token.symbol} +

+ {token.name.split(" ")[0]} ({token.symbol}) +

+
+
+ +
+
+ ); +} + export default TradingChartOrPairInfo;