From 9622b15f8aeaba3ab1460d6141d02ccb4b655a7d Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 12 Sep 2024 01:15:44 -0400 Subject: [PATCH] fix: add useMemo hook to `components/wallet/UserAssets.js` --- src/components/BookmarkAdded.js | 22 ++-- src/components/wallet/UserAssets.js | 153 +++++++++++++++------------- 2 files changed, 90 insertions(+), 85 deletions(-) diff --git a/src/components/BookmarkAdded.js b/src/components/BookmarkAdded.js index bfda0d7..993dc88 100644 --- a/src/components/BookmarkAdded.js +++ b/src/components/BookmarkAdded.js @@ -1,13 +1,6 @@ -import {Image} from "@chakra-ui/react"; -const explorerUrls = { - 0: "https://sepolia.basescan.org/tx/", - 1: "https://etherscan.io/tx/", - 56: "https://bscscan.com/tx/", - 137: "https://polygonscan.com/tx/", - 84532: "https://sepolia.basescan.org/tx/", -}; +import Image from 'next/image'; -function BookmarkAdded({message, status, chainId, txHash}) { +const BookmarkAdded = ({ message, status, chainId, txHash }) => { const explorerUrl = explorerUrls[chainId] ? `${explorerUrls[chainId]}${txHash}` : null; @@ -16,14 +9,13 @@ function BookmarkAdded({message, status, chainId, txHash}) {

{status}

transaction status -

{message}

- - {status === "success" && explorerUrl && ( + {status === 'success' && explorerUrl && ( ); -} +}; export default BookmarkAdded; diff --git a/src/components/wallet/UserAssets.js b/src/components/wallet/UserAssets.js index 00596cc..fec543c 100644 --- a/src/components/wallet/UserAssets.js +++ b/src/components/wallet/UserAssets.js @@ -1,17 +1,94 @@ 'use client'; import { FormControl, FormLabel, Switch } from '@chakra-ui/react'; import { motion } from 'framer-motion'; -import { useState } from 'react'; +import { useState, useMemo } from 'react'; import { FaEthereum } from 'react-icons/fa'; import AssetsValues from './AssetsValues'; function UserAssets() { + // Keep track of the switch state const [isSwitched, setIsSwitched] = useState(false); + // Switch handler const switchHandler = () => { setIsSwitched(!isSwitched); }; + // Memoized values for deposit and withdraw sections + const depositSection = useMemo( + () => ( + +
+ Deposit Tokens +
+
+ + +
+

Deposited:

+

Withdrawn:

+
+
+ +
+
+
+ ), + [] + ); + + const withdrawSection = useMemo( + () => ( + +
+ Withdraw Tokens +
+
+ + +
+

Deposited:

+

Withdrawn:

+
+
+ +
+
+
+ ), + [] + ); + return (
@@ -26,78 +103,14 @@ function UserAssets() { - {isSwitched ? ( - -
- Withdraw Tokens -
-
- - -
-

Deposited:

-

Withdrawn:

-
-
- -
-
-
- ) : ( - -
- Deposit Tokens -
-
- - -
-

Deposited:

-

Withdrawn:

-
-
- -
-
-
- )} + {/* Conditionally render deposit or withdraw section */} + {isSwitched ? withdrawSection : depositSection}
+
- {' '}
- {' '}

Net Worth

$0.00

@@ -110,8 +123,8 @@ function UserAssets() {
- - + +