From d0fec55dd06b7a8a3b01722a4bd0b9bcc26fc75e Mon Sep 17 00:00:00 2001 From: Geolffrey Mena Date: Wed, 1 Jan 2025 08:32:58 -0600 Subject: [PATCH] refactor: added extra comments a some fixes --- src/hooks/use-deposit-metamask.ts | 4 ++++ src/hooks/use-deposit.ts | 2 +- .../finance/components/finance-deposit-from-metamask.tsx | 3 ++- .../components/finance-deposit-from-smart-account.tsx | 4 +++- .../finance/components/finance-transactions-history.tsx | 8 -------- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/hooks/use-deposit-metamask.ts b/src/hooks/use-deposit-metamask.ts index 94d5e30f..8abdda30 100644 --- a/src/hooks/use-deposit-metamask.ts +++ b/src/hooks/use-deposit-metamask.ts @@ -7,17 +7,21 @@ import { GLOBAL_CONSTANTS } from '@src/config-global'; import { publicClient } from '@src/clients/viem/publicClient'; import { useSnackbar } from 'notistack'; +// AND HERE interface VaultError { message: string; code?: number; [key: string]: any; } +// SAME HERE interface DepositParams { recipient: string; // The address receiving the deposit amount: number; // Amount in "human" format (not in Wei) } +// TODO this could be handled in one interface in a type.tsx file +// is duplicated in use-deposit, this MUST be reusable interface UseDepositHook { data?: any; deposit: (params: DepositParams) => Promise; diff --git a/src/hooks/use-deposit.ts b/src/hooks/use-deposit.ts index f5eab8f3..1564a1de 100644 --- a/src/hooks/use-deposit.ts +++ b/src/hooks/use-deposit.ts @@ -17,7 +17,7 @@ interface DepositParams { amount: number; // plain number } -interface UseDepositHook { +export interface UseDepositHook { data?: any; deposit: (params: DepositParams) => Promise; loading: boolean; diff --git a/src/sections/finance/components/finance-deposit-from-metamask.tsx b/src/sections/finance/components/finance-deposit-from-metamask.tsx index 0c4688be..417b315f 100644 --- a/src/sections/finance/components/finance-deposit-from-metamask.tsx +++ b/src/sections/finance/components/finance-deposit-from-metamask.tsx @@ -24,6 +24,7 @@ interface FinanceDepositFromMetamaskProps { onClose: () => void; } +// TODO please finance-deposit.tsx const FinanceDepositFromMetamask: FC = ({ onClose }) => { const [address, setAddress] = useState
(); const { balance } = useGetMmcContractBalance(address); @@ -72,7 +73,7 @@ const FinanceDepositFromMetamask: FC = ({ onClo } else { enqueueSnackbar("Invalid deposit amount", { variant: "warning" }); } - }, [sessionData?.address]); + }, [sessionData?.address, amount, balance]); const RainbowEffect = loading || depositLoading ? NeonPaper : Box; const mdUp = useResponsive('up', 'md'); diff --git a/src/sections/finance/components/finance-deposit-from-smart-account.tsx b/src/sections/finance/components/finance-deposit-from-smart-account.tsx index 75a53014..3c2fd976 100644 --- a/src/sections/finance/components/finance-deposit-from-smart-account.tsx +++ b/src/sections/finance/components/finance-deposit-from-smart-account.tsx @@ -22,7 +22,9 @@ interface FinanceDepositFromSmartAccountProps { onClose: () => void; } +// TODO please finance-deposit.tsx const FinanceDepositFromSmartAccount: FC = ({ onClose }) => { + // TODO Use this component as generic finance deposit and create new sub components for metamask & smart account // TODO Please keep declaration on top const [amount, setAmount] = useState(0); const [loading, setLoading] = useState(false); @@ -42,7 +44,7 @@ const FinanceDepositFromSmartAccount: FC = useEffect(() => { if (error) errorDuringDeposit() }, [error]); - + const handleConfirmDeposit = useCallback(async () => { // fail fast // TODO validation formatUint(amount) > balance diff --git a/src/sections/finance/components/finance-transactions-history.tsx b/src/sections/finance/components/finance-transactions-history.tsx index f6b6a84e..d6262ccc 100644 --- a/src/sections/finance/components/finance-transactions-history.tsx +++ b/src/sections/finance/components/finance-transactions-history.tsx @@ -48,11 +48,8 @@ type TransactionsProcessedData = { } export default function FinanceTransactionsHistory({ transactionData }: TransactionsProcessedData) { - console.log('processedTransactions passed:', transactionData); const table = useTable({ defaultOrderBy: 'name' }); - const [tableData, _setTableData] = useState(transactionData); - const [filters, setFilters] = useState(defaultFilters); const dataFiltered = applyFilter({ @@ -62,14 +59,9 @@ export default function FinanceTransactionsHistory({ transactionData }: Transact }); const denseHeight = table.dense ? 52 : 72; - const canReset = filters.status !== 'all'; - const notFound = (!dataFiltered.length && canReset) || !dataFiltered.length; - console.log('Data:', tableData); - console.log('Date Filtered:', dataFiltered); - const handleFilters = useCallback( (name: string, value: IOrderTableFilterValue) => { table.onResetPage();