diff --git a/packages/nextjs/app/cdp/components/modals/DepositModal.tsx b/packages/nextjs/app/cdp/components/modals/DepositModal.tsx index 4bf60ad..b8634fa 100644 --- a/packages/nextjs/app/cdp/components/modals/DepositModal.tsx +++ b/packages/nextjs/app/cdp/components/modals/DepositModal.tsx @@ -8,6 +8,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Address } from "viem"; import { useChainId, useReadContract, useWaitForTransactionReceipt, useWriteContract } from "wagmi"; import { ERC20ABI } from "~~/app/components/abis/erc20"; +import { getBlockExplorerUrl } from "~~/app/utils/blockExplorer"; import { useBalanceOf } from "~~/hooks/useBalanceOf"; import { useDeposit } from "~~/hooks/useDeposit"; @@ -86,18 +87,6 @@ const DepositModal: React.FC = ({ depositHash, } = useDeposit(houseOfReserveContract as Address); - const getBlockExplorerUrl = (chainId: number): string => { - switch (chainId) { - case 56: // BNB Smart Chain Mainnet - return "https://bscscan.com/tx/"; - case 137: // Polygon Mainnet - return "https://polygonscan.com/tx/"; - case 8453: // Base Mainnet - return "https://basescan.org/tx/"; - default: - return ""; // Fallback for unsupported networks - } - }; const blockExplorerUrl = `${getBlockExplorerUrl(chainId)}${depositHash}`; useEffect(() => { diff --git a/packages/nextjs/app/cdp/components/modals/MintModal.tsx b/packages/nextjs/app/cdp/components/modals/MintModal.tsx index 3578382..9d3ba45 100644 --- a/packages/nextjs/app/cdp/components/modals/MintModal.tsx +++ b/packages/nextjs/app/cdp/components/modals/MintModal.tsx @@ -5,6 +5,7 @@ import { faClipboardCheck } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Address } from "viem"; import { useChainId } from "wagmi"; +import { getBlockExplorerUrl } from "~~/app/utils/blockExplorer"; interface MintModalProps { isOpen: boolean; @@ -102,18 +103,6 @@ const MintModal: React.FC = ({ onClose(); }; - const getBlockExplorerUrl = (chainId: number): string => { - switch (chainId) { - case 56: // BNB Smart Chain Mainnet - return "https://bscscan.com/tx/"; - case 137: // Polygon Mainnet - return "https://polygonscan.com/tx/"; - case 8453: // Base Mainnet - return "https://basescan.org/tx/"; - default: - return ""; // Fallback for unsupported networks - } - }; const blockExplorerUrl = `${getBlockExplorerUrl(chainId)}${mintingHash}`; if (!isOpen) return null; diff --git a/packages/nextjs/app/cdp/components/modals/RepayModal.tsx b/packages/nextjs/app/cdp/components/modals/RepayModal.tsx index 5796095..50f2e28 100644 --- a/packages/nextjs/app/cdp/components/modals/RepayModal.tsx +++ b/packages/nextjs/app/cdp/components/modals/RepayModal.tsx @@ -4,6 +4,7 @@ import { faClipboardCheck } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Address } from "viem"; import { useChainId } from "wagmi"; +import { getBlockExplorerUrl } from "~~/app/utils/blockExplorer"; import useRepayCPD from "~~/hooks/useRepayCDP"; interface RepayModalProps { @@ -91,18 +92,6 @@ const RepayModal: React.FC = ({ isOpen, onClose, backedTokenID, onClose(); }; - const getBlockExplorerUrl = (chainId: number): string => { - switch (chainId) { - case 56: // BNB Smart Chain Mainnet - return "https://bscscan.com/tx/"; - case 137: // Polygon Mainnet - return "https://polygonscan.com/tx/"; - case 8453: // Base Mainnet - return "https://basescan.org/tx/"; - default: - return ""; // Fallback for unsupported networks - } - }; const blockExplorerUrl = `${getBlockExplorerUrl(chainId)}${repayHash}`; if (!isOpen) return null; diff --git a/packages/nextjs/app/cdp/components/modals/WithdrawModal.tsx b/packages/nextjs/app/cdp/components/modals/WithdrawModal.tsx index 224bd36..caa8bdf 100644 --- a/packages/nextjs/app/cdp/components/modals/WithdrawModal.tsx +++ b/packages/nextjs/app/cdp/components/modals/WithdrawModal.tsx @@ -7,6 +7,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Address, formatEther } from "viem"; import { useChainId, useReadContract, useWaitForTransactionReceipt } from "wagmi"; import { houseOfReserveABI } from "~~/app/components/abis/houseofreserve"; +import { getBlockExplorerUrl } from "~~/app/utils/blockExplorer"; import { useWithdraw } from "~~/hooks/useWithdrawCDP"; interface WithdrawModalProps { @@ -62,18 +63,6 @@ const WithdrawModal: React.FC = ({ isOpen, onClose, assetNam withdrawHash, } = useWithdraw(houseOfReserveContract as Address); - const getBlockExplorerUrl = (chainId: number): string => { - switch (chainId) { - case 56: // BNB Smart Chain Mainnet - return "https://bscscan.com/tx/"; - case 137: // Polygon Mainnet - return "https://polygonscan.com/tx/"; - case 8453: // Base Mainnet - return "https://basescan.org/tx/"; - default: - return ""; // Fallback for unsupported networks - } - }; const blockExplorerUrl = `${getBlockExplorerUrl(chainId)}${withdrawHash}`; const { isLoading: isWithdrawLoading, isSuccess: isWithdrawSuccess } = useWaitForTransactionReceipt({ diff --git a/packages/nextjs/app/cdp/components/tables/DepositTable.tsx b/packages/nextjs/app/cdp/components/tables/DepositTable.tsx index b27fe08..d8c31d0 100644 --- a/packages/nextjs/app/cdp/components/tables/DepositTable.tsx +++ b/packages/nextjs/app/cdp/components/tables/DepositTable.tsx @@ -80,6 +80,7 @@ const DepositTable: React.FC = () => { const { t } = useTranslation(); // Get the chain ID const chainId = useChainId(); + // Define the state variables const [isModalOpen, setIsModalOpen] = useState(false); const [isWithdrawModalOpen, setIsWithdrawModalOpen] = useState(false); diff --git a/packages/nextjs/app/lending/components/modals/BorrowTransactionModal.tsx b/packages/nextjs/app/lending/components/modals/BorrowTransactionModal.tsx index e370688..21f228a 100644 --- a/packages/nextjs/app/lending/components/modals/BorrowTransactionModal.tsx +++ b/packages/nextjs/app/lending/components/modals/BorrowTransactionModal.tsx @@ -9,6 +9,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Address } from "viem"; import { useChainId } from "wagmi"; import { useTranslation } from "~~/app/context/LanguageContext"; +import { getBlockExplorerUrl } from "~~/app/utils/blockExplorer"; interface ModalProps { isOpen: boolean; @@ -46,18 +47,6 @@ const BorrowTransactionModal: React.FC = ({ isOpen, onClose, reserve // Fetch the user's wallet address const { address: walletAddress } = useAccountAddress(); - const getBlockExplorerUrl = (chainId: number): string => { - switch (chainId) { - case 56: // BNB Smart Chain Mainnet - return "https://bscscan.com/tx/"; - case 137: // Polygon Mainnet - return "https://polygonscan.com/tx/"; - case 8453: // Base Mainnet - return "https://basescan.org/tx/"; - default: - return ""; // Fallback for unsupported networks - } - }; const blockExplorerUrl = `${getBlockExplorerUrl(chainId)}${borrowHash}`; useEffect(() => { diff --git a/packages/nextjs/app/lending/components/modals/RepayTransactionModal.tsx.tsx b/packages/nextjs/app/lending/components/modals/RepayTransactionModal.tsx.tsx index 6f420dd..e72ac86 100644 --- a/packages/nextjs/app/lending/components/modals/RepayTransactionModal.tsx.tsx +++ b/packages/nextjs/app/lending/components/modals/RepayTransactionModal.tsx.tsx @@ -10,6 +10,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Address } from "viem"; import { useChainId } from "wagmi"; import { useTranslation } from "~~/app/context/LanguageContext"; +import { getBlockExplorerUrl } from "~~/app/utils/blockExplorer"; import useRepay from "~~/hooks/useRepay"; interface ModalProps { @@ -50,18 +51,6 @@ const RepayTransactionModal: React.FC = ({ isOpen, onClose, reserve, isPending: approvePending, } = useApproval(CONFIG.POOL, reserve?.underlyingAsset as Address); // Using the useApproval hook - const getBlockExplorerUrl = (chainId: number): string => { - switch (chainId) { - case 56: // BNB Smart Chain Mainnet - return "https://bscscan.com/tx/"; - case 137: // Polygon Mainnet - return "https://polygonscan.com/tx/"; - case 8453: // Base Mainnet - return "https://basescan.org/tx/"; - default: - return ""; // Fallback for unsupported networks - } - }; const blockExplorerUrl = `${getBlockExplorerUrl(chainId)}${repayHash}`; useEffect(() => { diff --git a/packages/nextjs/app/lending/components/modals/SupplyTransactionModal.tsx b/packages/nextjs/app/lending/components/modals/SupplyTransactionModal.tsx index edd053c..0e33bce 100644 --- a/packages/nextjs/app/lending/components/modals/SupplyTransactionModal.tsx +++ b/packages/nextjs/app/lending/components/modals/SupplyTransactionModal.tsx @@ -11,6 +11,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Address } from "viem"; import { useChainId } from "wagmi"; import { useTranslation } from "~~/app/context/LanguageContext"; +import { getBlockExplorerUrl } from "~~/app/utils/blockExplorer"; interface ModalProps { isOpen: boolean; @@ -173,18 +174,6 @@ const SupplyTransactionModal: React.FC = ({ isOpen, onClose, reserve onClose(); }; - const getBlockExplorerUrl = (chainId: number): string => { - switch (chainId) { - case 56: // BNB Smart Chain Mainnet - return "https://bscscan.com/tx/"; - case 137: // Polygon Mainnet - return "https://polygonscan.com/tx/"; - case 8453: // Base Mainnet - return "https://basescan.org/tx/"; - default: - return ""; // Fallback for unsupported networks - } - }; const blockExplorerUrl = `${getBlockExplorerUrl(chainId)}${supplyHash}`; if (!isOpen || !reserve) { diff --git a/packages/nextjs/app/lending/components/modals/WithdrawTransactionModal.tsx b/packages/nextjs/app/lending/components/modals/WithdrawTransactionModal.tsx index 1d53400..249b754 100644 --- a/packages/nextjs/app/lending/components/modals/WithdrawTransactionModal.tsx +++ b/packages/nextjs/app/lending/components/modals/WithdrawTransactionModal.tsx @@ -8,6 +8,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Address } from "viem"; import { useChainId } from "wagmi"; import { useTranslation } from "~~/app/context/LanguageContext"; +import { getBlockExplorerUrl } from "~~/app/utils/blockExplorer"; import useWithdraw from "~~/hooks/useWithdraw"; interface ModalProps { @@ -39,18 +40,6 @@ const WithdrawTransactionModal: React.FC = ({ isOpen, onClose, reser const { handleWithdraw, isError: withdrawError, error, withdrawHash } = useWithdraw(); const { address: walletAddress } = useAccountAddress(); - const getBlockExplorerUrl = (chainId: number): string => { - switch (chainId) { - case 56: // BNB Smart Chain Mainnet - return "https://bscscan.com/tx/"; - case 137: // Polygon Mainnet - return "https://polygonscan.com/tx/"; - case 8453: // Base Mainnet - return "https://basescan.org/tx/"; - default: - return ""; // Fallback for unsupported networks - } - }; const blockExplorerUrl = `${getBlockExplorerUrl(chainId)}${withdrawHash}`; useEffect(() => { diff --git a/packages/nextjs/app/utils/blockExplorer.ts b/packages/nextjs/app/utils/blockExplorer.ts new file mode 100644 index 0000000..07e5a54 --- /dev/null +++ b/packages/nextjs/app/utils/blockExplorer.ts @@ -0,0 +1,12 @@ +export const getBlockExplorerUrl = (chainId: number): string => { + switch (chainId) { + case 56: // BNB Smart Chain Mainnet + return "https://bscscan.com/tx/"; + case 137: // Polygon Mainnet + return "https://polygonscan.com/tx/"; + case 8453: // Base Mainnet + return "https://basescan.org/tx/"; + default: + return ""; // Fallback for unsupported networks + } +};