Skip to content

Commit

Permalink
Code cleanup and minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gabmontes committed Apr 15, 2024
1 parent 548c7be commit bef380d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 24 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
"@next/next/no-html-link-for-pages": [
"warn",
"site/pages"
],
"complexity": [
"warn",
20
]
}
}
Expand Down
4 changes: 2 additions & 2 deletions site/components/DPAuctionsLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<TransactionsContextProvider>
Expand All @@ -19,4 +19,4 @@ function PaymentStreamsLayout({ children }) {
)
}

export default PaymentStreamsLayout
export default DPAuctionsLayout
4 changes: 2 additions & 2 deletions site/components/UtilitiesTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ 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'),
selected: pathname === '/dp-auctions'
})
}
// 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'),
Expand Down
5 changes: 3 additions & 2 deletions site/components/payment-streams/CreateStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -57,9 +58,9 @@ const CreateStream = function () {

// tokens are in the list in the form of "<token> / [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
}
Expand Down
37 changes: 22 additions & 15 deletions site/pages/[locale]/merkle-claims.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function MerkleClaims() {
merkle.getHolding &&
merkle
.getHolding(cID)
.then(h => {
.then(function (h) {
if (h.isClaimable) {
clearFeedback()
} else {
Expand All @@ -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
Expand All @@ -73,18 +76,21 @@ 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])

useEffect(
function setClaimIdFromQueryOnLoad() {
handleClaimIDChange({ target: { value: query.id } })
},
[merkle, query]
[handleClaimIDChange, merkle, query]
)

return (
Expand All @@ -108,6 +114,7 @@ function MerkleClaims() {
toFixed(fromUnit(holding.amount, holding.token.decimals), 6)
}
/>
{/* TODO disable the button if not claimable! */}
<Button className="flex justify-center" onClick={handleClaimSubmit}>
{t('claim')}
</Button>
Expand Down
4 changes: 2 additions & 2 deletions site/pages/[locale]/token-revokes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down Expand Up @@ -221,7 +221,7 @@ function useTokenApprovals() {
useEffect(
function () {
if (!active || !account) {
return
return undefined
}

const subscription = library.eth.subscribe('logs', {
Expand Down
2 changes: 1 addition & 1 deletion site/pages/[locale]/wrap-eth.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const WrapUnwrapEth = function () {
const handleSubmit = function (e) {
e.preventDefault()
if (!active || !isValidNumber) {
return
return null
}

const erc20Service = erc20(account)
Expand Down

0 comments on commit bef380d

Please sign in to comment.