Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/containers/Accounts/AMM/AMMAccounts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, PropsWithChildren, useContext, useEffect } from 'react'
import { FC, PropsWithChildren, useContext } from 'react'
import { useQuery } from 'react-query'
import { Helmet } from 'react-helmet-async'
import { useLanguage } from '../../../shared/hooks'
Expand Down Expand Up @@ -105,25 +105,25 @@ export const AMMAccounts = () => {
})
})

useEffect(
() => () => {
window.scrollTo(0, 0)
useQuery(
['track-screen-load', data],
() => {
if (!data) {
return null
}

trackScreenLoaded({
account_id: data.accountId,
asset1: `${hexToString(data.balance.currency)}.${data.balance.issuer}`,
asset2: `${hexToString(data.balance2.currency)}.${data.balance2.issuer}`,
})
return null
},
{
enabled: !!data,
},
[],
)

useEffect(() => {
if (!data) {
return
}

trackScreenLoaded({
account_id: data.accountId,
asset1: `${hexToString(data.balance.currency)}.${data.balance.issuer}`,
asset2: `${hexToString(data.balance2.currency)}.${data.balance2.issuer}`,
})
}, [data, trackScreenLoaded])

const tabs = ['transactions']

if (error) {
Expand Down
13 changes: 6 additions & 7 deletions src/containers/Accounts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react'
import { useState } from 'react'
import { Helmet } from 'react-helmet-async'
import { useQuery } from 'react-query'
import { AccountHeader } from './AccountHeader'
import { AccountTransactionTable } from './AccountTransactionTable'
import './styles.scss'
Expand All @@ -16,13 +17,11 @@ export const Accounts = () => {
const [currencySelected, setCurrencySelected] = useState('XRP')
const mainPath = buildPath(ACCOUNT_ROUTE, { id: accountId })

useEffect(() => {
useQuery(['screen-load', tab], () => {
trackScreenLoaded()

return () => {
window.scrollTo(0, 0)
}
}, [tab, trackScreenLoaded])
window.scrollTo(0, 0)
return null
})

const tabs = ['transactions', 'assets']

Expand Down
8 changes: 5 additions & 3 deletions src/containers/CustomNetworkHome/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { KeyboardEvent, useEffect, useState } from 'react'
import { KeyboardEvent, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Link } from 'react-router-dom'
import { useQuery } from 'react-query'
import CustomNetworkLogo from '../shared/images/custom_network_logo.svg'
import RightArrow from '../shared/images/side_arrow_green.svg'
import { useAnalytics } from '../shared/analytics'
Expand All @@ -14,9 +15,10 @@ const SidechainHome = () => {
const [networkText, setNetworkText] = useState('')
const [customNetworks = []] = useCustomNetworks()

useEffect(() => {
useQuery(['screen-load'], () => {
trackScreenLoaded()
}, [trackScreenLoaded])
return null
})

function switchMode(desiredLink: string) {
const customNetworkUrl = process.env.VITE_CUSTOMNETWORK_LINK
Expand Down
35 changes: 17 additions & 18 deletions src/containers/Header/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
FC,
KeyboardEventHandler,
useContext,
useEffect,
useState,
} from 'react'
import { FC, KeyboardEventHandler, useContext, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useNavigate } from 'react-router-dom'
import { XrplClient } from 'xrpl-client'
Expand All @@ -13,6 +7,7 @@ import {
isValidXAddress,
classicAddressToXAddress,
} from 'ripple-address-codec'
import { useQuery } from 'react-query'
import CloseIcon from '../shared/images/close.png'

import { useAnalytics } from '../shared/analytics'
Expand Down Expand Up @@ -177,8 +172,22 @@ export const Search = ({ callback = () => {} }: SearchProps) => {
const { t } = useTranslation()
const socket = useContext(SocketContext)
const navigate = useNavigate()

const [currentSearchInput, setCurrentSearchInput] = useState('')
const [isBannerVisible, setIsBannerVisible] = useState(true)

useQuery(
['banner-timeout'],
() => {
const timeoutId = setTimeout(() => {
setIsBannerVisible(false)
}, 10000) // Disappear after 10 seconds

return () => clearTimeout(timeoutId)
},
{
enabled: isBannerVisible,
},
)

const handleSearch = async (id: string) => {
const strippedId = id.replace(/^["']|["']$/g, '')
Expand All @@ -199,16 +208,6 @@ export const Search = ({ callback = () => {} }: SearchProps) => {
}
}

const [isBannerVisible, setIsBannerVisible] = useState(true)

useEffect(() => {
const timeoutId = setTimeout(() => {
setIsBannerVisible(false)
}, 10000) // Disappear after 10 seconds

return () => clearTimeout(timeoutId)
}, [])

return (
<>
{process.env.VITE_ENVIRONMENT === 'mainnet' && isBannerVisible && (
Expand Down
7 changes: 4 additions & 3 deletions src/containers/Ledger/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useEffect } from 'react'
import { useContext } from 'react'
import { Helmet } from 'react-helmet-async'
import { useTranslation } from 'react-i18next'
import { useQuery } from 'react-query'
Expand Down Expand Up @@ -83,9 +83,10 @@ export const Ledger = () => {
)
})

useEffect(() => {
useQuery(['screen-load'], () => {
trackScreenLoaded()
}, [trackScreenLoaded])
return null
})

const renderNav = (data: any) => {
const { ledger_index: LedgerIndex, ledger_hash: LedgerHash } = data
Expand Down
8 changes: 5 additions & 3 deletions src/containers/Ledgers/Legend.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useWindowSize } from 'usehooks-ts'
import { useQuery } from 'react-query'
import {
TransactionAction,
TransactionCategory,
Expand All @@ -19,11 +20,12 @@ export const Legend = () => {
const [hidden, setHidden] = useState(previousInteraction)

// Show legend by default when on desktop sizes
useEffect(() => {
useQuery(['legend-visibility', windowSize.width, previousInteraction], () => {
if (previousInteraction === false) {
setHidden(!(windowSize.width > 900))
}
}, [previousInteraction, windowSize])
return null
})

const actions = [
TransactionAction.CREATE,
Expand Down
11 changes: 5 additions & 6 deletions src/containers/Ledgers/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useEffect, useState } from 'react'
import { useContext, useState } from 'react'
import { Helmet } from 'react-helmet-async'
import { useTranslation } from 'react-i18next'
import { useQuery } from 'react-query'
Expand Down Expand Up @@ -30,12 +30,11 @@ export const LedgersPage = () => {
const { t } = useTranslation()
const network = useContext(NetworkContext)

useEffect(() => {
useQuery(['screen-load'], () => {
trackScreenLoaded()
return () => {
window.scrollTo(0, 0)
}
}, [trackScreenLoaded])
window.scrollTo(0, 0)
return null
})

const fetchValidators = () => {
const url = `${process.env.VITE_DATA_URL}/validators/${network}`
Expand Down
12 changes: 6 additions & 6 deletions src/containers/MPT/MPT.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FC, PropsWithChildren, useEffect, useState } from 'react'
import { FC, PropsWithChildren, useState } from 'react'
import { useParams } from 'react-router'
import { Helmet } from 'react-helmet-async'
import { useQuery } from 'react-query'
import NoMatch from '../NoMatch'
import { MPTHeader } from './MPTHeader/MPTHeader'
import { useAnalytics } from '../shared/analytics'
Expand Down Expand Up @@ -41,14 +42,13 @@ export const MPT = () => {
const { id: tokenId = '' } = useParams<{ id: string }>()
const [error, setError] = useState<number | null>(null)

useEffect(() => {
useQuery(['screen-load', tokenId], () => {
trackScreenLoaded({
mpt_issuance_id: tokenId,
})
return () => {
window.scrollTo(0, 0)
}
}, [tokenId, trackScreenLoaded])
window.scrollTo(0, 0)
return null
})

const renderError = () => {
const message = getErrorMessage(error)
Expand Down
7 changes: 4 additions & 3 deletions src/containers/MPT/MPTHeader/MPTHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useContext, useState } from 'react'
import { useContext, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useQuery } from 'react-query'
import { Loader } from '../../shared/components/Loader'
Expand Down Expand Up @@ -40,11 +40,12 @@ export const MPTHeader = (props: Props) => {
},
)

useEffect(() => {
useQuery(['validate-token-id', tokenId], () => {
if (!HASH192_REGEX.test(tokenId)) {
setError(BAD_REQUEST)
}
}, [setError, tokenId])
return null
})

const showTooltip = (event: any, d: any) => {
setTooltip({
Expand Down
12 changes: 6 additions & 6 deletions src/containers/NFT/NFT.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FC, PropsWithChildren, useEffect, useState } from 'react'
import { FC, PropsWithChildren, useState } from 'react'
import { useParams } from 'react-router'
import { Helmet } from 'react-helmet-async'
import { useQuery } from 'react-query'
import NoMatch from '../NoMatch'
import { NFTHeader } from './NFTHeader/NFTHeader'
import { NFTTabs } from './NFTTabs/NFTTabs'
Expand Down Expand Up @@ -43,15 +44,14 @@ export const NFT = () => {
const { id: tokenId = '' } = useParams<{ id: string }>()
const [error, setError] = useState<number | null>(null)

useEffect(() => {
useQuery(['screen-load', tokenId], () => {
trackScreenLoaded({
nftoken_id: tokenId,
issuer: parseIssuerFromNFTokenID(tokenId),
})
return () => {
window.scrollTo(0, 0)
}
}, [tokenId, trackScreenLoaded])
window.scrollTo(0, 0)
return null
})

const renderError = () => {
const message = getErrorMessage(error)
Expand Down
7 changes: 4 additions & 3 deletions src/containers/NFT/NFTHeader/NFTHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useContext, useState } from 'react'
import { useContext, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useQuery } from 'react-query'
import { Loader } from '../../shared/components/Loader'
Expand Down Expand Up @@ -55,11 +55,12 @@ export const NFTHeader = (props: Props) => {
},
)

useEffect(() => {
useQuery(['validate-token-id', tokenId], () => {
if (!HASH256_REGEX.test(tokenId)) {
setError(BAD_REQUEST)
}
}, [setError, tokenId])
return null
})

// fetch the oldest NFT transaction to get its minted data
const { data: firstTransaction } = useQuery(
Expand Down
8 changes: 5 additions & 3 deletions src/containers/Network/Hexagons.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react'
import { useState } from 'react'
import PropTypes from 'prop-types'
import { useWindowSize } from 'usehooks-ts'
import { useQuery } from 'react-query'

import { hexbin } from 'd3-hexbin'
import { Loader } from '../shared/components/Loader'
Expand Down Expand Up @@ -60,13 +61,14 @@ export const Hexagons = ({ list, data }) => {
])
.radius(radius)

useEffect(() => {
useQuery(['prepare-hexagons', data, list, width, gridHeight, radius], () => {
if (width > 0) {
setHexagons((prevHexagons) =>
prepareHexagons(data, list, gridHeight, radius, prevHexagons),
)
}
}, [data, list, width, gridHeight, radius])
return null
})

const renderHexagon = (d, theHex) => {
const { cookie, pubkey, ledger_hash: ledgerHash } = d
Expand Down
8 changes: 5 additions & 3 deletions src/containers/Network/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useContext, useEffect } from 'react'
import { useContext } from 'react'
import { useTranslation } from 'react-i18next'
import { Helmet } from 'react-helmet-async'
import { useQuery } from 'react-query'
import { NETWORK_ROUTE } from '../App/routes'
import { useAnalytics } from '../shared/analytics'
import { useRouteParams } from '../shared/routing'
Expand All @@ -17,9 +18,10 @@ export const Network = () => {
const { tab = 'nodes' } = useRouteParams(NETWORK_ROUTE)
const network = useContext(NetworkContext)

useEffect(() => {
useQuery(['screen-load', tab], () => {
trackScreenLoaded()
}, [tab, trackScreenLoaded])
return null
})

if (network === null) {
return (
Expand Down
8 changes: 5 additions & 3 deletions src/containers/NoMatch/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useContext, useEffect } from 'react'
import { useContext } from 'react'
import { Helmet } from 'react-helmet-async'
import { useTranslation } from 'react-i18next'
import { useQuery } from 'react-query'
import { useAnalytics } from '../shared/analytics'
import SocketContext from '../shared/SocketContext'
import InfoIcon from '../shared/images/info.svg'
Expand Down Expand Up @@ -32,12 +33,13 @@ const NoMatch = ({
const socket = useContext(SocketContext)
const values = { connection: socket?.getState() }

useEffect(() => {
useQuery(['track-not-found', ...hints, title], () => {
track('not_found', {
description: `${title} -- ${hints.join(', ')}`,
})
// eslint-disable-next-line react-hooks/exhaustive-deps -- hints has to be spread to prevent this from running multiple times
}, [...hints, title, track])
return null
})

const notFound = title.includes('not_found')
const hintMsg = hints.map((hint) => (
Expand Down
Loading
Loading