Skip to content

Commit

Permalink
Merge pull request #60 from garosan/feature/group-utils
Browse files Browse the repository at this point in the history
Feature/group utils
  • Loading branch information
iafhurtado authored Nov 29, 2024
2 parents 0c0df50 + da6e066 commit 4757503
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 98 deletions.
13 changes: 1 addition & 12 deletions packages/nextjs/app/cdp/components/modals/DepositModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -86,18 +87,6 @@ const DepositModal: React.FC<DepositModalProps> = ({
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(() => {
Expand Down
13 changes: 1 addition & 12 deletions packages/nextjs/app/cdp/components/modals/MintModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,18 +103,6 @@ const MintModal: React.FC<MintModalProps> = ({
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;
Expand Down
13 changes: 1 addition & 12 deletions packages/nextjs/app/cdp/components/modals/RepayModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -91,18 +92,6 @@ const RepayModal: React.FC<RepayModalProps> = ({ 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;
Expand Down
13 changes: 1 addition & 12 deletions packages/nextjs/app/cdp/components/modals/WithdrawModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -62,18 +63,6 @@ const WithdrawModal: React.FC<WithdrawModalProps> = ({ 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({
Expand Down
3 changes: 2 additions & 1 deletion packages/nextjs/app/cdp/components/tables/DepositTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -126,7 +127,7 @@ const DepositTable: React.FC = () => {
};

return (
<div className="overflow-x-auto">
<div>
<table className="min-w-full divide-y divide-gray-200">
<thead>
<tr className="text-center">
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/app/cdp/components/tables/YourDeposits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ const YourDeposits = () => {
const chainDeposits = deposits[chainId] || [];
const allDepositsZero = formattedBalances.every(balance => balance === 0);
return (
<div className="rounded-md overflow-x-auto">
<div className="rounded-md">
{/* Section for displaying the user's deposits */}
{chainDeposits.length > 0 && !allDepositsZero ? (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,18 +47,6 @@ const BorrowTransactionModal: React.FC<ModalProps> = ({ 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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -50,18 +51,6 @@ const RepayTransactionModal: React.FC<ModalProps> = ({ 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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -173,18 +174,6 @@ const SupplyTransactionModal: React.FC<ModalProps> = ({ 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -39,18 +40,6 @@ const WithdrawTransactionModal: React.FC<ModalProps> = ({ 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(() => {
Expand Down
12 changes: 12 additions & 0 deletions packages/nextjs/app/utils/blockExplorer.ts
Original file line number Diff line number Diff line change
@@ -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
}
};

0 comments on commit 4757503

Please sign in to comment.