From 04393806dfb121d8b82cbbc7bf4373264d2a76b9 Mon Sep 17 00:00:00 2001 From: tjs Date: Fri, 22 Jul 2022 13:07:55 -0400 Subject: [PATCH] add flip numbers to chart --- components/TokenList.tsx | 5 ++- components/swap/SwapTokenChart.tsx | 58 +++++++++++++++++++----------- package.json | 1 + types/index.d.ts | 1 + yarn.lock | 12 +++++++ 5 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 types/index.d.ts diff --git a/components/TokenList.tsx b/components/TokenList.tsx index 89e01029..11a23eab 100644 --- a/components/TokenList.tsx +++ b/components/TokenList.tsx @@ -137,7 +137,10 @@ const TokenList = () => { {banks.map((bank) => { const oraclePrice = bank.value.price return ( -
+
diff --git a/components/swap/SwapTokenChart.tsx b/components/swap/SwapTokenChart.tsx index 47a62eaa..72d3a9ff 100644 --- a/components/swap/SwapTokenChart.tsx +++ b/components/swap/SwapTokenChart.tsx @@ -9,6 +9,8 @@ import { Tooltip, ResponsiveContainer, } from 'recharts' +import FlipNumbers from 'react-flip-numbers' + import LineChartIcon from '../icons/LineChartIcon' import ContentBox from '../shared/ContentBox' import { GREEN, RED } from '../../styles/colors' @@ -138,20 +140,20 @@ const SwapTokenChart: FunctionComponent = ({ const calculateChartChange = () => { if (chartData.length) { - if (mouseData) { - const index = chartData.findIndex((d: any) => d.time === mouseData.time) - return ( - ((chartData[chartData.length - 1]['price'] - - chartData[index]['price']) / - chartData[0]['price']) * - 100 - ) - } else - return ( - ((chartData[chartData.length - 1]['price'] - chartData[0]['price']) / - chartData[0]['price']) * - 100 - ) + // if (mouseData) { + // const index = chartData.findIndex((d: any) => d.time === mouseData.time) + // return ( + // ((chartData[chartData.length - 1]['price'] - + // chartData[index]['price']) / + // chartData[0]['price']) * + // 100 + // ) + // } else + return ( + ((chartData[chartData.length - 1]['price'] - chartData[0]['price']) / + chartData[0]['price']) * + 100 + ) } return 0 } @@ -172,7 +174,14 @@ const SwapTokenChart: FunctionComponent = ({ {mouseData ? ( <>
- {numberFormatter.format(mouseData['price'])} + = 0 @@ -197,9 +206,14 @@ const SwapTokenChart: FunctionComponent = ({ ) : ( <>
- {numberFormatter.format( - chartData[chartData.length - 1]['price'] - )} + = 0 @@ -312,9 +326,11 @@ const SwapTokenChart: FunctionComponent = ({
) : ( -
- - Chart not available +
+
+ + Chart not available +
)} diff --git a/package.json b/package.json index 2ec01ca8..7b8c032a 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "process": "^0.11.10", "react": "18.0.0", "react-dom": "18.0.0", + "react-flip-numbers": "^3.0.5", "react-window": "^1.8.7", "recharts": "^2.1.12", "zustand": "^3.7.2" diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 00000000..7b447951 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1 @@ +declare module 'react-flip-numbers' diff --git a/yarn.lock b/yarn.lock index 7d0d59e2..731a4bdf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3867,6 +3867,13 @@ react-dom@18.0.0: loose-envify "^1.1.0" scheduler "^0.21.0" +react-flip-numbers@^3.0.5: + version "3.0.5" + resolved "https://registry.yarnpkg.com/react-flip-numbers/-/react-flip-numbers-3.0.5.tgz#37fc3f9416575bfb9e9b7af44a7d64aaf922c712" + integrity sha512-iOzLaRZbqU7G7A+uE/ySBVzEHr+vZTPMJNP20o1dFUUZ3kkrpTFxpay3+kEVSSzeOXJWQWYDUQOFbv7g/PSf1g== + dependencies: + react-simple-animate "3.0.2" + react-i18next@^11.18.0: version "11.18.1" resolved "https://registry.yarnpkg.com/react-i18next/-/react-i18next-11.18.1.tgz#ba86ed09069e129b8623a28f2b9a03d7f105ea6f" @@ -3899,6 +3906,11 @@ react-resize-detector@^7.1.2: dependencies: lodash "^4.17.21" +react-simple-animate@3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/react-simple-animate/-/react-simple-animate-3.0.2.tgz#67f29b0c64155d2dfd540c1c74f634ef521536a8" + integrity sha512-GDpznDMpIHHdH6L6AZo9nNry6Xsq7forKmd6rwigMSuxe4FS9ihK0HSC1odB4WWKbA87S8VL7EVR9JeTRVkbQA== + react-smooth@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/react-smooth/-/react-smooth-2.0.1.tgz#74c7309916d6ccca182c4b30c8992f179e6c5a05"