diff --git a/public/tokens/040a180aca4194a158c17945dd115db42086f6f074c1f77838621a4927fffa91.png b/public/tokens/040a180aca4194a158c17945dd115db42086f6f074c1f77838621a4927fffa91.png new file mode 100644 index 0000000..1afe9aa Binary files /dev/null and b/public/tokens/040a180aca4194a158c17945dd115db42086f6f074c1f77838621a4927fffa91.png differ diff --git a/public/tokens/24819c4b65786c3ac424e05d9ef4ab212de6222cc73bc5c4b012df5a3107eea4.png b/public/tokens/24819c4b65786c3ac424e05d9ef4ab212de6222cc73bc5c4b012df5a3107eea4.png new file mode 100644 index 0000000..cca1545 Binary files /dev/null and b/public/tokens/24819c4b65786c3ac424e05d9ef4ab212de6222cc73bc5c4b012df5a3107eea4.png differ diff --git a/public/tokens/34b01e731c2215ae9d1244e3a2f7a4e09569cce4b4273ee18286db41f98873a2.png b/public/tokens/34b01e731c2215ae9d1244e3a2f7a4e09569cce4b4273ee18286db41f98873a2.png new file mode 100644 index 0000000..078c3ee Binary files /dev/null and b/public/tokens/34b01e731c2215ae9d1244e3a2f7a4e09569cce4b4273ee18286db41f98873a2.png differ diff --git a/public/tokens/55a8e0a730b133fb83915ba0e4335a680ae9d07a99642b17774460560f3b003d.png b/public/tokens/55a8e0a730b133fb83915ba0e4335a680ae9d07a99642b17774460560f3b003d.png new file mode 100644 index 0000000..b751efc Binary files /dev/null and b/public/tokens/55a8e0a730b133fb83915ba0e4335a680ae9d07a99642b17774460560f3b003d.png differ diff --git a/public/tokens/6ca3fa07f1b6a75b6e195d2918c32228765968b54ea691c75958affa1c4073fb.png b/public/tokens/6ca3fa07f1b6a75b6e195d2918c32228765968b54ea691c75958affa1c4073fb.png new file mode 100644 index 0000000..136ebec Binary files /dev/null and b/public/tokens/6ca3fa07f1b6a75b6e195d2918c32228765968b54ea691c75958affa1c4073fb.png differ diff --git a/public/tokens/86143388bd056a8f0bab669f78f14873fac8e2dd8d57898cdb725a2d5e2e4f8f.png b/public/tokens/86143388bd056a8f0bab669f78f14873fac8e2dd8d57898cdb725a2d5e2e4f8f.png new file mode 100644 index 0000000..c93a78f Binary files /dev/null and b/public/tokens/86143388bd056a8f0bab669f78f14873fac8e2dd8d57898cdb725a2d5e2e4f8f.png differ diff --git a/public/tokens/93da681503353509367e241cda3234299dedbbad9ec851de31e900490807bf0c.png b/public/tokens/93da681503353509367e241cda3234299dedbbad9ec851de31e900490807bf0c.png new file mode 100644 index 0000000..a77b1ac Binary files /dev/null and b/public/tokens/93da681503353509367e241cda3234299dedbbad9ec851de31e900490807bf0c.png differ diff --git a/public/tokens/d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a.png b/public/tokens/d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a.png new file mode 100644 index 0000000..3585dc3 Binary files /dev/null and b/public/tokens/d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a.png differ diff --git a/public/tokens/fc7edd432df16c1e1bf5b7233b5bdaa040c68715b4de24478c9b276082a642a0.png b/public/tokens/fc7edd432df16c1e1bf5b7233b5bdaa040c68715b4de24478c9b276082a642a0.png new file mode 100644 index 0000000..82a421a Binary files /dev/null and b/public/tokens/fc7edd432df16c1e1bf5b7233b5bdaa040c68715b4de24478c9b276082a642a0.png differ diff --git a/public/tokens/token.png b/public/tokens/token.png new file mode 100644 index 0000000..e795f88 Binary files /dev/null and b/public/tokens/token.png differ diff --git a/src/components/UI/ImgWithFallback/index.tsx b/src/components/UI/ImgWithFallback/index.tsx new file mode 100644 index 0000000..abda96b --- /dev/null +++ b/src/components/UI/ImgWithFallback/index.tsx @@ -0,0 +1,26 @@ +'use client'; + +import { useState, useEffect } from 'react'; +import Image, { ImageProps } from 'next/image'; + +type ImgWithFallbackProps = ImageProps & { + fallbackSrc?: string; + alt: string; +}; + +const ImgWithFallback = ({ + src, + alt, + fallbackSrc = '/tokens/token.png', + ...rest +}: ImgWithFallbackProps) => { + const [imgSrc, setImgSrc] = useState(src); + + useEffect(() => { + setImgSrc(src); + }, [src]); + + return {alt} setImgSrc(fallbackSrc)} />; +}; + +export default ImgWithFallback; diff --git a/src/pages/dex/pairs/PairsCard/PairsCard.tsx b/src/pages/dex/pairs/PairsCard/PairsCard.tsx index b226470..ad81a15 100644 --- a/src/pages/dex/pairs/PairsCard/PairsCard.tsx +++ b/src/pages/dex/pairs/PairsCard/PairsCard.tsx @@ -5,6 +5,7 @@ import { ReactComponent as ArrowRight } from '@/assets/images/UI/arrow_right.svg import { Store } from '@/store/store-reducer'; import PairData from '@/interfaces/common/PairData'; import { notationToString, roundTo, tradingKnownCurrencies } from '@/utils/utils'; +import ImgWithFallback from '@/components/UI/ImgWithFallback'; import styles from './PairsCard.module.scss'; interface IProps { @@ -51,10 +52,10 @@ export default function PairsCard({ pair }: IProps) { return (
- currency
diff --git a/src/pages/dex/pairs/PairsTable/PairsTable.tsx b/src/pages/dex/pairs/PairsTable/PairsTable.tsx index 7e13a10..578a04a 100644 --- a/src/pages/dex/pairs/PairsTable/PairsTable.tsx +++ b/src/pages/dex/pairs/PairsTable/PairsTable.tsx @@ -1,3 +1,4 @@ +// PairsTable.tsx import { memo, useContext, useMemo } from 'react'; import { ColumnDef, flexRender, getCoreRowModel, useReactTable } from '@tanstack/react-table'; import { useRouter } from 'next/router'; @@ -7,29 +8,9 @@ import { Store } from '@/store/store-reducer'; import PairData from '@/interfaces/common/PairData'; import { ContextState } from '@/interfaces/common/ContextValue'; import { tradingKnownCurrencies, roundTo, notationToString } from '@/utils/utils'; +import ImgWithFallback from '@/components/UI/ImgWithFallback'; import styles from './PairsTable.module.scss'; - -type Currency = { - code: string; - name: string; - whitelisted?: boolean; - featured?: boolean; -}; - -type Row = { - id: string; - pair: { - base: Currency; - quote: Currency; - }; - price: number; - priceUSD: string; - change: number; - volume: number; - volumeUSD: string; - featured: boolean; - code: string; -}; +import { Row } from './types'; function transformPairsToRows(pairs: PairData[], state: ContextState): Row[] { return pairs.map((pair) => { @@ -38,17 +19,18 @@ function transformPairsToRows(pairs: PairData[], state: ContextState): Row[] { const price = Number(roundTo(notationToString(pair.rate ?? 0))); const currentPriceUSD = secondAssetUsdPrice ? price : 0; const priceUSD = currentPriceUSD - ? String(`$${(secondAssetUsdPrice * price).toFixed(2)}`) - : String(`$${(secondAssetUsdPrice * price).toFixed(0)}`); + ? `$${(secondAssetUsdPrice * price).toFixed(2)}` + : `$${(secondAssetUsdPrice * price).toFixed(0)}`; const volume = Number(roundTo(notationToString(pair.volume ?? 0))); const currentVolumeUSD = secondAssetUsdPrice ? volume : 0; const volumeUSD = currentVolumeUSD - ? String(`$${(secondAssetUsdPrice * volume).toFixed(2)}`) - : String(`$${(secondAssetUsdPrice * volume).toFixed(0)}`); + ? `$${(secondAssetUsdPrice * volume).toFixed(2)}` + : `$${(secondAssetUsdPrice * volume).toFixed(0)}`; return { id: pair.id, + assetId: pair.first_currency.asset_id, pair: { base: pair.first_currency, quote: pair.second_currency, @@ -74,6 +56,10 @@ function PairsTable({ data }: IProps) { const router = useRouter(); const { state } = useContext(Store); + const rows = useMemo(() => { + return transformPairsToRows(data, state); + }, [data, state.assetsRates]); + const columns = useMemo[]>( () => [ { @@ -82,15 +68,15 @@ function PairsTable({ data }: IProps) { cell: ({ row }) => { const { pair: { base, quote }, - code, featured, + assetId, } = row.original; return (
- currency
@@ -114,9 +100,8 @@ function PairsTable({ data }: IProps) { { accessorKey: 'price', header: ({ table }) => { - const row = table.options.data[0] as Row; - const name = row?.pair.quote.name; - + const row0 = table.options.data[0] as Row | undefined; + const name = row0?.pair.quote.name; return `Price ${name ? `(${name})` : ''}`; }, cell: ({ row }) => ( @@ -186,13 +171,14 @@ function PairsTable({ data }: IProps) { ), }, ], - [], + [router], ); const table = useReactTable({ - data: transformPairsToRows(data, state), + data: rows, columns, getCoreRowModel: getCoreRowModel(), + getRowId: (r) => r.id, }); return ( diff --git a/src/pages/dex/pairs/PairsTable/types.ts b/src/pages/dex/pairs/PairsTable/types.ts new file mode 100644 index 0000000..76a0aa9 --- /dev/null +++ b/src/pages/dex/pairs/PairsTable/types.ts @@ -0,0 +1,22 @@ +type Currency = { + code: string; + name: string; + whitelisted?: boolean; + featured?: boolean; +}; + +export type Row = { + id: string; + assetId: string | undefined | null; + pair: { + base: Currency; + quote: Currency; + }; + price: number; + priceUSD: string; + change: number; + volume: number; + volumeUSD: string; + featured: boolean; + code: string; +}; diff --git a/src/pages/dex/trading/[id].tsx b/src/pages/dex/trading/[id].tsx index 3f23c95..e129132 100644 --- a/src/pages/dex/trading/[id].tsx +++ b/src/pages/dex/trading/[id].tsx @@ -56,6 +56,7 @@ import LightningImg from '@/assets/images/UI/lightning.png'; import RocketImg from '@/assets/images/UI/rocket.png'; import { ReactComponent as ConnectionIcon } from '@/assets/images/UI/connection.svg'; import Image from 'next/image'; +import ImgWithFallback from '@/components/UI/ImgWithFallback'; import CandleChart from './CandleChart/CandleChart'; import OrdersBuySellSwitch from './OrdersBuySellSwitch/OrdersBuySellSwitch'; import InputPanelItem from './InputPanelItem/InputPanelItem'; @@ -1054,10 +1055,10 @@ function Trading() {
- currency