From bbd86754f5c2ce36ff334a947b1aae4227d544a6 Mon Sep 17 00:00:00 2001 From: 0age <37939117+0age@users.noreply.github.com> Date: Wed, 11 Dec 2024 13:38:22 -0800 Subject: [PATCH] complete nit pass --- frontend/src/components/APISection.tsx | 3 +- frontend/src/components/BalanceDisplay.tsx | 2 +- frontend/src/components/DepositForm.tsx | 36 +++++++++++-------- .../src/components/ForcedWithdrawalDialog.tsx | 11 +++--- frontend/src/context/NotificationProvider.tsx | 11 +++--- frontend/src/hooks/useBalanceDisplay.ts | 16 +++++---- frontend/src/hooks/useCreateAllocation.ts | 4 ++- frontend/src/hooks/useERC20.ts | 11 ++++-- frontend/src/utils/chains.ts | 19 +++++----- 9 files changed, 67 insertions(+), 46 deletions(-) diff --git a/frontend/src/components/APISection.tsx b/frontend/src/components/APISection.tsx index b9362a1..0b72f53 100644 --- a/frontend/src/components/APISection.tsx +++ b/frontend/src/components/APISection.tsx @@ -100,9 +100,8 @@ const APISection: React.FC = () => { {Object.entries(typeDefinitions).map(([name, definition]) => (
-
+
{name} - = {definition}
diff --git a/frontend/src/components/BalanceDisplay.tsx b/frontend/src/components/BalanceDisplay.tsx index 76ab93e..1d2ad7f 100644 --- a/frontend/src/components/BalanceDisplay.tsx +++ b/frontend/src/components/BalanceDisplay.tsx @@ -325,7 +325,7 @@ export function BalanceDisplay({ return (
-

Allocations

+

Resource Locks

@@ -425,7 +430,8 @@ export function DepositForm() { !allocatorAddress || amountValidation?.type === 'error' || amountValidation?.type === 'warning' || - (tokenType === 'erc20' && (!tokenAddress || !isValid || isLoadingToken)) + (tokenType === 'erc20' && + (!tokenAddress || !isValid || isLoadingToken)) } className="w-full py-2 px-4 bg-[#00ff00] text-gray-900 rounded-lg font-medium hover:bg-[#00dd00] transition-colors disabled:opacity-50 disabled:cursor-not-allowed" > diff --git a/frontend/src/components/ForcedWithdrawalDialog.tsx b/frontend/src/components/ForcedWithdrawalDialog.tsx index d17d227..6234c79 100644 --- a/frontend/src/components/ForcedWithdrawalDialog.tsx +++ b/frontend/src/components/ForcedWithdrawalDialog.tsx @@ -106,11 +106,12 @@ export function ForcedWithdrawalDialog({ }); // Handle both object with hash and direct hash string - const txHash = typeof result === 'object' && result !== null - ? (result as TransactionResponse).hash - : typeof result === 'string' - ? result as `0x${string}` - : undefined; + const txHash = + typeof result === 'object' && result !== null + ? (result as TransactionResponse).hash + : typeof result === 'string' + ? (result as `0x${string}`) + : undefined; if (txHash) { showNotification({ diff --git a/frontend/src/context/NotificationProvider.tsx b/frontend/src/context/NotificationProvider.tsx index f42af2c..d0b6f13 100644 --- a/frontend/src/context/NotificationProvider.tsx +++ b/frontend/src/context/NotificationProvider.tsx @@ -139,9 +139,12 @@ export function NotificationProvider({ children }: { children: ReactNode }) { } const shortHash = `${notification.txHash.slice(0, 6)}...${notification.txHash.slice(-4)}`; - + if (notification.chainId) { - const explorerUrl = getBlockExplorerTxUrl(notification.chainId, notification.txHash); + const explorerUrl = getBlockExplorerTxUrl( + notification.chainId, + notification.txHash + ); if (explorerUrl) { return (

@@ -161,9 +164,7 @@ export function NotificationProvider({ children }: { children: ReactNode }) { // Fallback to non-linked hash if no explorer URL is available return ( -

- Transaction: {shortHash} -

+

Transaction: {shortHash}

); }; diff --git a/frontend/src/hooks/useBalanceDisplay.ts b/frontend/src/hooks/useBalanceDisplay.ts index 3cfe11c..1725263 100644 --- a/frontend/src/hooks/useBalanceDisplay.ts +++ b/frontend/src/hooks/useBalanceDisplay.ts @@ -27,9 +27,11 @@ interface EthereumProvider { request: (args: { method: string; params: unknown[] }) => Promise; } -type TransactionResponse = { - hash: `0x${string}`; -} | `0x${string}`; +type TransactionResponse = + | { + hash: `0x${string}`; + } + | `0x${string}`; export { getChainName }; @@ -135,13 +137,13 @@ export function useBalanceDisplay() { } try { - const result = await disableForcedWithdrawal({ + const result = (await disableForcedWithdrawal({ args: [BigInt(lockId)], - }) as TransactionResponse; - + })) as TransactionResponse; + // Get the transaction hash whether it's returned directly or as part of an object const txHash = typeof result === 'object' ? result.hash : result; - + if (txHash) { showNotification({ type: 'success', diff --git a/frontend/src/hooks/useCreateAllocation.ts b/frontend/src/hooks/useCreateAllocation.ts index 04eff0c..59de283 100644 --- a/frontend/src/hooks/useCreateAllocation.ts +++ b/frontend/src/hooks/useCreateAllocation.ts @@ -184,7 +184,9 @@ export function useCreateAllocation(sessionToken: string) { newErrors.nonce = 'Nonce is required'; } - const expirationTime = customExpiry ? formData.expiration : getExpirationTime(); + const expirationTime = customExpiry + ? formData.expiration + : getExpirationTime(); if (!expirationTime) { newErrors.expiration = 'Expiration is required'; } else { diff --git a/frontend/src/hooks/useERC20.ts b/frontend/src/hooks/useERC20.ts index cdd947a..61e17e7 100644 --- a/frontend/src/hooks/useERC20.ts +++ b/frontend/src/hooks/useERC20.ts @@ -1,11 +1,18 @@ import { useState, useEffect } from 'react'; -import { useReadContract, useWriteContract, useAccount, useChainId, usePublicClient } from 'wagmi'; +import { + useReadContract, + useWriteContract, + useAccount, + useChainId, + usePublicClient, +} from 'wagmi'; import { formatUnits, isAddress, type Hash } from 'viem'; import { ERC20_ABI, COMPACT_ADDRESS } from '../constants/contracts'; import { useNotification } from './useNotification'; // Max uint256 value for infinite approval -const MAX_UINT256 = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'; +const MAX_UINT256 = + '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'; export function useERC20(tokenAddress?: `0x${string}`) { const { address } = useAccount(); diff --git a/frontend/src/utils/chains.ts b/frontend/src/utils/chains.ts index a58ebe3..6fe4afa 100644 --- a/frontend/src/utils/chains.ts +++ b/frontend/src/utils/chains.ts @@ -8,10 +8,10 @@ import { chains } from '../config/wagmi'; export function getChainName(chainId: string | number): string { // Convert chainId to number if it's a string const id = typeof chainId === 'string' ? parseInt(chainId) : chainId; - + // Find the chain in wagmi config - const chain = chains.find(chain => chain.id === id); - + const chain = chains.find((chain) => chain.id === id); + // Return the chain name if found, otherwise return a generic name return chain?.name || `Chain ${chainId}`; } @@ -22,17 +22,20 @@ export function getChainName(chainId: string | number): string { * @param txHash The transaction hash * @returns The formatted block explorer URL if available, otherwise null */ -export function getBlockExplorerTxUrl(chainId: string | number, txHash: string): string | null { +export function getBlockExplorerTxUrl( + chainId: string | number, + txHash: string +): string | null { // Convert chainId to number if it's a string const id = typeof chainId === 'string' ? parseInt(chainId) : chainId; - + // Find the chain in wagmi config - const chain = chains.find(chain => chain.id === id); - + const chain = chains.find((chain) => chain.id === id); + // If chain has a block explorer URL, format the transaction URL if (chain?.blockExplorers?.default?.url) { return `${chain.blockExplorers.default.url}/tx/${txHash}`; } - + return null; }