diff --git a/components/account/AccountChart.tsx b/components/account/AccountChart.tsx index c9797d8f..615e685b 100644 --- a/components/account/AccountChart.tsx +++ b/components/account/AccountChart.tsx @@ -22,9 +22,12 @@ const AccountChart = ({ const [daysToShow, setDaysToShow] = useState(1) const loading = mangoStore((s) => s.mangoAccount.stats.performance.loading) - const handleDaysToShow = (days: number) => { + const handleDaysToShow = async (days: number) => { + await actions.fetchAccountPerformance( + mangoAccount.publicKey.toString(), + days + ) setDaysToShow(days) - actions.fetchAccountPerformance(mangoAccount.publicKey.toString(), days) } return ( diff --git a/components/shared/ChartRangeButtons.tsx b/components/shared/ChartRangeButtons.tsx new file mode 100644 index 00000000..e430bb5e --- /dev/null +++ b/components/shared/ChartRangeButtons.tsx @@ -0,0 +1,55 @@ +import { FunctionComponent } from 'react' + +interface ChartRangeButtonsProps { + activeValue: number + className?: string + onChange: (x: number) => void + values: Array + names?: Array +} + +const ChartRangeButtons: FunctionComponent = ({ + activeValue, + className, + values, + onChange, + names, +}) => { + return ( +
+
+ {activeValue && values.includes(activeValue) ? ( +
v === activeValue) * 100 + }%)`, + width: `${100 / values.length}%`, + }} + /> + ) : null} + {values.map((v, i) => ( + + ))} +
+
+ ) +} + +export default ChartRangeButtons diff --git a/components/shared/DetailedAreaChart.tsx b/components/shared/DetailedAreaChart.tsx index 87c69f65..1efa5130 100644 --- a/components/shared/DetailedAreaChart.tsx +++ b/components/shared/DetailedAreaChart.tsx @@ -20,6 +20,7 @@ import { useTheme } from 'next-themes' import { IconButton } from './Button' import { ArrowLeftIcon } from '@heroicons/react/20/solid' import { FadeInFadeOut } from './Transitions' +import ChartRangeButtons from './ChartRangeButtons' dayjs.extend(relativeTime) @@ -176,30 +177,12 @@ const DetailedAreaChart: FunctionComponent = ({
- - - + setDaysToShow(v)} + />
diff --git a/components/swap/SwapTokenChart.tsx b/components/swap/SwapTokenChart.tsx index de611ccf..fd968bdc 100644 --- a/components/swap/SwapTokenChart.tsx +++ b/components/swap/SwapTokenChart.tsx @@ -19,12 +19,12 @@ import FlipNumbers from 'react-flip-numbers' import LineChartIcon from '../icons/LineChartIcon' import ContentBox from '../shared/ContentBox' -import { DownTriangle, UpTriangle } from '../shared/DirectionTriangles' import { formatFixedDecimals } from '../../utils/numbers' import SheenLoader from '../shared/SheenLoader' import { COLORS } from '../../styles/colors' import { useTheme } from 'next-themes' import PercentageChange from '../shared/PercentageChange' +import ChartRangeButtons from '../shared/ChartRangeButtons' dayjs.extend(relativeTime) @@ -297,30 +297,12 @@ const SwapTokenChart: FunctionComponent = ({
- - - + setDaysToShow(v)} + />