Skip to content

Commit 8d503da

Browse files
authored
fix: handling of token page throttling (#1100)
The token page is prone to being throttled because it tries to load in order books for the "top 10 tokens". This change moves logic to useQuery and out of redux. It then makes sure the token's information is loaded in before trying to load in dex pairs. Fixes #790 ### Type of Change <!-- Please check relevant options, delete irrelevant ones. --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [x] Refactor (non-breaking change that only restructures code) - [x] Tests (You added tests for code that already exists, or your new feature included in this PR) - [ ] Documentation Updates - [ ] Translation Updates - [ ] Release ### TypeScript/Hooks Update - [ ] Updated files to React Hooks - [x] Updated files to TypeScript ## Before / After ### Before ![Monosnap XRPL Explorer | Something bad happened 2024-12-17 14-04-17](https://github.com/user-attachments/assets/27ea108e-59ec-4318-9da3-60ec68c3c38c) ### After ![Monosnap XRPL Explorer | rMxCKbEDwqr7 2024-12-17 14-04-24](https://github.com/user-attachments/assets/7cc2d0d3-d686-408d-a5d2-d3c1c2f8880f)
1 parent 12e04fa commit 8d503da

File tree

11 files changed

+86
-371
lines changed

11 files changed

+86
-371
lines changed

src/containers/App/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { Transaction } from '../Transactions'
3434
import { Network } from '../Network'
3535
import { Validator } from '../Validators'
3636
import { PayString } from '../PayStrings'
37-
import Token from '../Token'
37+
import { Token } from '../Token'
3838
import { NFT } from '../NFT/NFT'
3939
import { legacyRedirect } from './legacyRedirects'
4040
import { useCustomNetworks } from '../shared/hooks'

src/containers/Token/TokenHeader/actionTypes.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/containers/Token/TokenHeader/actions.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/containers/Token/TokenHeader/index.tsx

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
import { useContext, useEffect } from 'react'
21
import { useTranslation } from 'react-i18next'
3-
import { connect } from 'react-redux'
4-
import { bindActionCreators } from 'redux'
5-
import { loadTokenState } from './actions'
6-
import { Loader } from '../../shared/components/Loader'
72
import './styles.scss'
83
import { localizeNumber, formatLargeNumber } from '../../shared/utils'
9-
import SocketContext from '../../shared/SocketContext'
104
import Currency from '../../shared/components/Currency'
115
import { Account } from '../../shared/components/Account'
126
import DomainLink from '../../shared/components/DomainLink'
137
import { TokenTableRow } from '../../shared/components/TokenTableRow'
148
import { useLanguage } from '../../shared/hooks'
159
import { LEDGER_ROUTE, TRANSACTION_ROUTE } from '../../App/routes'
1610
import { RouteLink } from '../../shared/routing'
11+
import { TokenData } from '../../../rippled/token'
1712

1813
const CURRENCY_OPTIONS = {
1914
style: 'currency',
@@ -23,44 +18,21 @@ const CURRENCY_OPTIONS = {
2318
}
2419

2520
interface TokenHeaderProps {
26-
loading: boolean
2721
accountId: string
2822
currency: string
29-
data: {
30-
balance: string
31-
reserve: number
32-
sequence: number
33-
rate: number
34-
obligations: string
35-
domain: string
36-
emailHash: string
37-
previousLedger: number
38-
previousTxn: string
39-
flags: string[]
40-
}
41-
actions: {
42-
loadTokenState: typeof loadTokenState
43-
}
23+
data: TokenData
4424
}
4525

46-
const TokenHeader = ({
47-
actions,
26+
export const TokenHeader = ({
4827
accountId,
4928
currency,
5029
data,
51-
loading,
5230
}: TokenHeaderProps) => {
5331
const language = useLanguage()
5432
const { t } = useTranslation()
55-
const rippledSocket = useContext(SocketContext)
56-
57-
useEffect(() => {
58-
actions.loadTokenState(currency, accountId, rippledSocket)
59-
}, [accountId, actions, currency, rippledSocket])
33+
const { domain, rate, emailHash, previousLedger, previousTxn } = data
6034

6135
const renderDetails = () => {
62-
const { domain, rate, emailHash, previousLedger, previousTxn } = data
63-
6436
const prevTxn = previousTxn && previousTxn.replace(/(.{20})..+/, '$1...')
6537
const abbrvEmail = emailHash && emailHash.replace(/(.{20})..+/, '$1...')
6638
return (
@@ -156,7 +128,9 @@ const TokenHeader = ({
156128
language,
157129
CURRENCY_OPTIONS,
158130
)
159-
const obligationsBalance = formatLargeNumber(Number.parseFloat(obligations))
131+
const obligationsBalance = formatLargeNumber(
132+
Number.parseFloat(obligations || '0'),
133+
)
160134

161135
return (
162136
<div className="section header-container">
@@ -201,7 +175,6 @@ const TokenHeader = ({
201175
)
202176
}
203177

204-
const { emailHash } = data
205178
return (
206179
<div className="box token-header">
207180
<div className="section box-header">
@@ -213,24 +186,7 @@ const TokenHeader = ({
213186
/>
214187
)}
215188
</div>
216-
<div className="box-content">
217-
{loading ? <Loader /> : renderHeaderContent()}
218-
</div>
189+
<div className="box-content">{renderHeaderContent()}</div>
219190
</div>
220191
)
221192
}
222-
223-
export default connect(
224-
(state: any) => ({
225-
loading: state.tokenHeader.loading,
226-
data: state.tokenHeader.data,
227-
}),
228-
(dispatch) => ({
229-
actions: bindActionCreators(
230-
{
231-
loadTokenState,
232-
},
233-
dispatch,
234-
),
235-
}),
236-
)(TokenHeader)

src/containers/Token/TokenHeader/reducer.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/containers/Token/TokenHeader/test/actions.test.js

Lines changed: 0 additions & 108 deletions
This file was deleted.

src/containers/Token/TokenHeader/test/reducer.test.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)