From 90ac2edefe9ff044b1e97e50ff5a31adeb872102 Mon Sep 17 00:00:00 2001 From: Gabriel Montes Date: Mon, 15 Apr 2024 17:22:36 -0300 Subject: [PATCH] Code cleanup and minor changes --- package.json | 4 ++ packages/token-list/src/index.js | 16 ++++---- site/components/DPAuctionsLayout.js | 4 +- site/components/UtilitiesTabs.js | 4 +- .../payment-streams/CreateStream.js | 5 ++- .../[locale]/dp-auctions/auctions/index.js | 2 +- site/pages/[locale]/merkle-claims.js | 37 +++++++++++-------- site/pages/[locale]/token-revokes.js | 4 +- site/pages/[locale]/wrap-eth.js | 2 +- 9 files changed, 44 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index 07569df..cb1495c 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,10 @@ "@next/next/no-html-link-for-pages": [ "warn", "site/pages" + ], + "complexity": [ + "warn", + 20 ] } } diff --git a/packages/token-list/src/index.js b/packages/token-list/src/index.js index ef9b53b..8cb2700 100644 --- a/packages/token-list/src/index.js +++ b/packages/token-list/src/index.js @@ -26,10 +26,9 @@ const getTokenListByChain = memoize(chainId => ) const findTokenByAddress = memoize( - // FIXME un-hardcode chain id - function (_address, chainId = 743111) { - const tokenlist = getTokenListByChain(chainId) - return tokenlist.find( + function (_address, chainId) { + const tokenList = getTokenListByChain(chainId) + return tokenList.find( ({ address }) => address.toLowerCase() === _address.toLowerCase() ) }, @@ -37,12 +36,11 @@ const findTokenByAddress = memoize( ) const findTokenBySymbol = memoize( - // FIXME un-hardcode chain id - function (_symbol, chainId = 743111) { - const tokenlist = getTokenListByChain(chainId) + function (_symbol, chainId) { + const tokenList = getTokenListByChain(chainId) return ( - tokenlist.find(({ symbol }) => symbol === _symbol) || - tokenlist.find( + tokenList.find(({ symbol }) => symbol === _symbol) || + tokenList.find( ({ symbol }) => symbol.toLowerCase() === _symbol.toLowerCase() ) ) diff --git a/site/components/DPAuctionsLayout.js b/site/components/DPAuctionsLayout.js index 88ff81f..e66b723 100644 --- a/site/components/DPAuctionsLayout.js +++ b/site/components/DPAuctionsLayout.js @@ -5,7 +5,7 @@ import DPAuctionsContextProvider from './DPAuctionsContext' import Layout from './Layout' import Transactions from './Transactions' -function PaymentStreamsLayout({ children }) { +function DPAuctionsLayout({ children }) { const t = useTranslations() return ( @@ -19,4 +19,4 @@ function PaymentStreamsLayout({ children }) { ) } -export default PaymentStreamsLayout +export default DPAuctionsLayout diff --git a/site/components/UtilitiesTabs.js b/site/components/UtilitiesTabs.js index 68aa51e..9940b6e 100644 --- a/site/components/UtilitiesTabs.js +++ b/site/components/UtilitiesTabs.js @@ -43,7 +43,7 @@ function UtilitiesTabs() { // positions constant. // // Add Descending Price Auctions if Uniswap v2 is supported. - if (utilsConfig[chainId].dpAuctions.uniswapV2) { + if (chainId && utilsConfig[chainId]?.dpAuctions.uniswapV2) { items.splice(5, 0, { href: '/dp-auctions', label: t('dp-auctions'), @@ -51,7 +51,7 @@ function UtilitiesTabs() { }) } // Add Payment Streams if ChainLink is supported. - if (utilsConfig[chainId]?.paymentStreams?.chainLink) { + if (chainId && utilsConfig[chainId]?.paymentStreams?.chainLink) { items.splice(3, 0, { href: '/payment-streams', label: t('payment-streams'), diff --git a/site/components/payment-streams/CreateStream.js b/site/components/payment-streams/CreateStream.js index a86935f..0b5b540 100644 --- a/site/components/payment-streams/CreateStream.js +++ b/site/components/payment-streams/CreateStream.js @@ -21,6 +21,7 @@ import { PaymentStreamsLibContext } from './PaymentStreamsLib' const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' +// To create a payment stream, the payment token has to have a ChainLink feed! const useSupportedTokens = function () { const { data, error } = useSWR('supported-tokens', () => fetchJson('https://cl-docs-addresses.web.app/addresses.json').then( @@ -57,9 +58,9 @@ const CreateStream = function () { // tokens are in the list in the form of " / [USD|ETH]"" pairs. For example: "UNI / USD" // addresses are not available - const isTokenSupported = function (value) { + const isTokenSupported = function (address) { // vesper is registered as "Vesper Finance TVL" - see https://docs.chain.link/docs/ethereum-addresses/#Ethereum%20Mainnet - const symbol = findToken(value, 1)?.symbol.toLowerCase() + const symbol = findToken(address, 1)?.symbol.toLowerCase() if (!symbol) { return false } diff --git a/site/pages/[locale]/dp-auctions/auctions/index.js b/site/pages/[locale]/dp-auctions/auctions/index.js index 366eeda..50469d8 100644 --- a/site/pages/[locale]/dp-auctions/auctions/index.js +++ b/site/pages/[locale]/dp-auctions/auctions/index.js @@ -260,7 +260,7 @@ const DPAuctionBuyControl = function ({ auction }) { opId, received: auction.tokens.map(token => ({ symbol: token.symbol, - value: fromUnit(token.amount, token.decilams) + value: fromUnit(token.amount, token.decimals) })), sent: fromUnit(auction.currentPrice, auction.paymentToken.decimals), sentSymbol: auction.paymentToken.symbol, diff --git a/site/pages/[locale]/merkle-claims.js b/site/pages/[locale]/merkle-claims.js index 5e9c795..5d6c8d4 100644 --- a/site/pages/[locale]/merkle-claims.js +++ b/site/pages/[locale]/merkle-claims.js @@ -35,7 +35,7 @@ function MerkleClaims() { merkle.getHolding && merkle .getHolding(cID) - .then(h => { + .then(function (h) { if (h.isClaimable) { clearFeedback() } else { @@ -50,16 +50,19 @@ function MerkleClaims() { [merkle] ) - const handleClaimIDChange = function (e) { - const re = /^[0-9\b]+$/ - if (e.target.value === '' || re.test(e.target.value)) { - clearFeedback() - setClaimID(e.target.value) - delayedClaimID(e.target.value) - } - } + const handleClaimIDChange = useCallback( + function (e) { + const re = /^[0-9\b]+$/ + if (e.target.value === '' || re.test(e.target.value)) { + clearFeedback() + setClaimID(e.target.value) + delayedClaimID(e.target.value) + } + }, + [delayedClaimID] + ) - const handleClaimSubmit = () => { + const handleClaimSubmit = function () { setClaimInProgress(true) setInfoMessage(t('claim-in-progress')) return merkle @@ -73,10 +76,13 @@ function MerkleClaims() { .then(() => watchAsset({ account, token: holding.token })) } - useEffect(() => { - clearFeedback() - setClaimID('') - }, [active, account]) + useEffect( + function () { + clearFeedback() + setClaimID('') + }, + [active, account] + ) useEffect(() => setHolding({ amount: '', isClaimable: false }), [claimID]) @@ -84,7 +90,7 @@ function MerkleClaims() { function setClaimIdFromQueryOnLoad() { handleClaimIDChange({ target: { value: query.id } }) }, - [merkle, query] + [handleClaimIDChange, merkle, query] ) return ( @@ -108,6 +114,7 @@ function MerkleClaims() { toFixed(fromUnit(holding.amount, holding.token.decimals), 6) } /> + {/* TODO disable the button if not claimable! */} diff --git a/site/pages/[locale]/token-revokes.js b/site/pages/[locale]/token-revokes.js index 53e6dcb..b3d9e01 100644 --- a/site/pages/[locale]/token-revokes.js +++ b/site/pages/[locale]/token-revokes.js @@ -64,7 +64,7 @@ const getNewestApprovals = function ({ logs, tokenApprovals, library }) { const newestOperation = allOperations[0] if (library.utils.hexToNumberString(newestOperation.allowance) === '0') { - return + return null } return newestOperation }) @@ -221,7 +221,7 @@ function useTokenApprovals() { useEffect( function () { if (!active || !account) { - return + return undefined } const subscription = library.eth.subscribe('logs', { diff --git a/site/pages/[locale]/wrap-eth.js b/site/pages/[locale]/wrap-eth.js index 9a5c187..c355c33 100644 --- a/site/pages/[locale]/wrap-eth.js +++ b/site/pages/[locale]/wrap-eth.js @@ -70,7 +70,7 @@ const WrapUnwrapEth = function () { const handleSubmit = function (e) { e.preventDefault() if (!active || !isValidNumber) { - return + return null } const erc20Service = erc20(account)