diff --git a/src/app/components/PriceChart.tsx b/src/app/components/PriceChart.tsx index 41a904c0..500715a3 100644 --- a/src/app/components/PriceChart.tsx +++ b/src/app/components/PriceChart.tsx @@ -7,12 +7,15 @@ 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"; interface PriceChartProps { data: OHLCVData[]; @@ -267,7 +270,7 @@ enum ChartTabOptions { PAIR_INFO = "PAIR_INFO", } -export function PriceChart() { +export function TradingChartOrPairInfo() { const t = useTranslations(); const dispatch = useAppDispatch(); const candlePeriod = useAppSelector((state) => state.priceChart.candlePeriod); @@ -282,7 +285,7 @@ export function PriceChart() { return (
-
+
{[ [t("trading_chart"), ChartTabOptions.TRADING_CHART], [t("pair_info"), ChartTabOptions.PAIR_INFO], @@ -357,24 +360,28 @@ export function TradingChart() { export function PairInfoTab() { const t = useTranslations(); - const { pairsList } = useAppSelector((state) => state.rewardSlice); + const dispatch = useAppDispatch(); + const { pairsList } = useAppSelector((state) => state.pairSelector); const selectedPairAddress = useAppSelector( (state) => state.pairSelector.address ); const pairInfo = pairsList.find( (pairInfo) => pairInfo.address === selectedPairAddress ); + // const isCopied = useAppSelector((state) => state.priceChart.copied); - let name, address, orderReceiptAddress, token1, token2; - if (pairInfo) { - ({ name, address, orderReceiptAddress, token1, token2 } = pairInfo); - } else { + if (!pairInfo) { return "Selected pair not found in pairsList"; } + const { name, address, orderReceiptAddress, token1, token2 } = pairInfo; + + const handleCopy = () => { + dispatch(setCopied(true)); + DexterToast.success("Copied!"); - const shortenAddress = (address: any) => { - if (!address) return ""; - return `${address.slice(0, 40)}...`; + setTimeout(() => { + dispatch(setCopied(false)); + }, 2000); }; return ( @@ -382,13 +389,15 @@ export function PairInfoTab() {
{name}
-
+
{t("pair_resource")}
- {shortenAddress(address)} - + + {shortenString(address, 8, 20, "...")} + +
-
+ +
{t("order_receipt_address")}
- {shortenAddress(orderReceiptAddress)} + {shortenString(orderReceiptAddress, 8, 20, "...")} - +
-
+
-

+

{t("resource")}

-

{shortenAddress(token1?.address)}

- +

+ {shortenString(token1?.address, 8, 20, "...")} +

+
-
+

@@ -456,12 +468,14 @@ export function PairInfoTab() {

-

+

{t("resource")}

-

{shortenAddress(token2?.address)}

- +

+ {shortenString(token2?.address, 8, 20, "...")} +

+ ({ + type: COPY_SUCCESS, +}); + function cleanData(data: OHLCVData[]): OHLCVData[] { // avoid lightweight-charts Error: Assertion failed: data must be asc ordered by time // without this step, the chart does not work in firefox (but works in chrome) @@ -163,6 +172,9 @@ export const priceChartSlice = createSlice({ setLegendCurrentVolume: (state, action: PayloadAction) => { state.legendCurrentVolume = action.payload; }, + setCopied: (state, action: PayloadAction) => { + state.copied = action.payload; + }, }, }); @@ -174,4 +186,5 @@ export const { setLegendPercChange, setLegendCurrentVolume, initializeLegend, + setCopied, } = priceChartSlice.actions; diff --git a/src/app/trade/page.tsx b/src/app/trade/page.tsx index 63ccd1d5..9ee854ec 100644 --- a/src/app/trade/page.tsx +++ b/src/app/trade/page.tsx @@ -6,7 +6,7 @@ import { useSearchParams } from "next/navigation"; import { OrderBook } from "../components/OrderBook"; import { OrderInput } from "../components/OrderInput"; import { PairSelector } from "../components/PairSelector"; -import { PriceChart } from "../components/PriceChart"; +import { TradingChartOrPairInfo } from "../components/PriceChart"; import { AccountHistory } from "../components/AccountHistory"; import { PriceInfo } from "../components/PriceInfo"; import { fetchBalances, selectPair } from "state/pairSelectorSlice"; @@ -120,7 +120,7 @@ export default function Trade() {
- +