From 4f0d2dde275fd7c19a5e50ee42f23f6b763cc0e2 Mon Sep 17 00:00:00 2001 From: Lucas Magnus Date: Tue, 20 Feb 2024 09:42:31 -0300 Subject: [PATCH] feat: responsive contract history --- .../components/contract-history/index.tsx | 131 ++++++++++++++---- .../templates/contracts-detail/index.tsx | 2 +- 2 files changed, 104 insertions(+), 29 deletions(-) diff --git a/frontend/src/components/templates/contracts-detail/components/contract-history/index.tsx b/frontend/src/components/templates/contracts-detail/components/contract-history/index.tsx index 4fa3cdf7..6729d957 100644 --- a/frontend/src/components/templates/contracts-detail/components/contract-history/index.tsx +++ b/frontend/src/components/templates/contracts-detail/components/contract-history/index.tsx @@ -1,4 +1,14 @@ -import { Flex, Table, Tbody, Td, Text, Th, Thead, Tr } from '@chakra-ui/react' +import { + Flex, + Table, + Tbody, + Td, + Text, + Th, + Thead, + Tr, + useMediaQuery, +} from '@chakra-ui/react' import React from 'react' import { formatDateFullClean, toCrypto } from 'utils/formatter' @@ -12,6 +22,8 @@ export const ContractHistory: React.FC = ({ contract, history, }) => { + const [isLargerThanSm] = useMediaQuery('(min-width: 480px)') + const calculateVariation = ( depositAmount: number, withdrawAmount: number @@ -22,8 +34,7 @@ export const ContractHistory: React.FC = ({ return ( - + = ({ > Your history - - - - - - - - - - + {isLargerThanSm ? ( +
Date of depositDepositedDate of withdrawWithdrawn
+ + + + + + + + + + {history?.map((itemHistory, index) => ( + + + + + + + ))} + +
Date of depositDepositedDate of withdrawWithdrawn
{formatDateFullClean(itemHistory.deposited_at)}{`${toCrypto(itemHistory.deposit_amount)} ${ + contract.asset.code + }`} + {itemHistory.withdrawn_at + ? formatDateFullClean(itemHistory.withdrawn_at) + : '-'} + + + {itemHistory.withdraw_amount + ? `${toCrypto(itemHistory.withdraw_amount)} ${ + contract.asset.code + }` + : '-'} + {itemHistory.withdraw_amount && ( + + {calculateVariation( + itemHistory.deposit_amount, + itemHistory.withdraw_amount + )} + + )} + +
+ ) : ( + {history?.map((itemHistory, index) => ( - - {formatDateFullClean(itemHistory.deposited_at)} - {`${toCrypto(itemHistory.deposit_amount)} ${ - contract.asset.code - }`} - - {itemHistory.withdrawn_at - ? formatDateFullClean(itemHistory.withdrawn_at) - : '-'} - - + + + Date of deposit + {formatDateFullClean(itemHistory.deposited_at)} + + + Deposited + {`${toCrypto(itemHistory.deposit_amount)} ${ + contract.asset.code + }`} + + + Date of withdraw + + {itemHistory.withdrawn_at + ? formatDateFullClean(itemHistory.withdrawn_at) + : '-'} + + + + Withdrawn {itemHistory.withdraw_amount ? `${toCrypto(itemHistory.withdraw_amount)} ${ @@ -84,11 +159,11 @@ export const ContractHistory: React.FC = ({ )} - - + + ))} - - + + )} {history && history.length == 0 && ( = ({ timerCounter, }) => { return ( - +