Skip to content

Commit cefea79

Browse files
pandablue0809ihomp
andauthored
search bar on /token page (#584)
* Add a search bar on the /token page * reset delay in setTimeout * fix search block * reset searchblock * fix using the popup * prettify * prettify, remove currencyQueryName * move token page specific code to the token page * Remove not needed flag for api endpoint * remove not needed api flags - part 2 * remove added fetch from the token selector component, rename function * clean up * image fix on mobile --------- Co-authored-by: Viacheslav Bakshaev <[email protected]>
1 parent 0b68dc0 commit cefea79

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

components/UI/TokenSelector.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export default function TokenSelector({
142142
tokens = await fetchTrustlinesForDestination(destinationAddress)
143143
} else {
144144
// Fallback to original behavior if no destination address
145+
// &statistics=true - shall we get USD prices and show them?
145146
const response = await axios('v2/trustlines/tokens?limit=' + limit + '&currencyDetails=true')
146147
tokens = response.data?.tokens || []
147148
if (!excludeNative) {
@@ -199,6 +200,7 @@ export default function TokenSelector({
199200
setCachedSearchResults(tokensWithNative)
200201
} else {
201202
// Fallback to original search behavior
203+
// &statistics=true - shall we get USD prices and show them?
202204
const response = await axios(`v2/trustlines/tokens/search/${searchQuery}?limit=${limit}&currencyDetails=true`)
203205
const tokens = response.data?.tokens || []
204206
const tokensWithNative = addNativeCurrencyIfNeeded(tokens, excludeNative, searchQuery)

pages/token/[[...id]].js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Link from 'next/link'
44
import { useRouter } from 'next/router'
55

66
import SEO from '../../components/SEO'
7+
import TokenSelector from '../../components/UI/TokenSelector'
78
import { tokenClass } from '../../styles/pages/token.module.scss'
89
import { niceNumber, shortNiceNumber, fullNiceNumber, AddressWithIconFilled } from '../../utils/format'
910
import { axiosServer, getFiatRateServer, passHeaders } from '../../utils/axios'
@@ -97,6 +98,7 @@ export default function TokenPage({
9798
const router = useRouter()
9899
const [token, setToken] = useState(initialData)
99100
const [loading, setLoading] = useState(false)
101+
const [selectedToken, setSelectedToken] = useState(initialData)
100102
const errorMessage = initialErrorMessage || ''
101103
const firstRenderRef = useRef(true)
102104

@@ -115,11 +117,11 @@ export default function TokenPage({
115117
}
116118
}, [initialData, initialErrorMessage, router])
117119

118-
const getHistoricalRates = async () => {
120+
const getData = async () => {
119121
setLoading(true)
120122
const cur = selectedCurrency?.toLowerCase()
121123
if (!cur) return
122-
const url = `v2/trustlines/token/${initialData.issuer}/${initialData.currency}?statistics=true&currencyDetails=true&convertCurrencies=${cur}`
124+
const url = `v2/trustlines/token/${selectedToken.issuer}/${selectedToken.currency}?statistics=true&currencyDetails=true&convertCurrencies=${cur}`
123125
const res = await axiosServer({
124126
method: 'get',
125127
url
@@ -136,11 +138,18 @@ export default function TokenPage({
136138
firstRenderRef.current = false
137139
return
138140
}
139-
getHistoricalRates()
141+
getData()
140142
// eslint-disable-next-line react-hooks/exhaustive-deps
141-
}, [selectedCurrency])
142-
// Helper: price line as "fiat (XRP)" using historical rate when available
143+
}, [selectedCurrency, selectedToken])
144+
145+
useEffect(() => {
146+
const { pathname, query } = router
147+
query.id = [selectedToken?.issuer, selectedToken?.currency]
148+
router.replace({ pathname, query }, null, { shallow: true })
149+
// eslint-disable-next-line react-hooks/exhaustive-deps
150+
}, [selectedToken])
143151

152+
// Helper: price line as "fiat (XRP)" using historical rate when available
144153
const priceLine = ({ priceNative, priceFiat }) => {
145154
const price = priceNative
146155
return (
@@ -272,16 +281,26 @@ export default function TokenPage({
272281
token.issuerDetails?.service || token.issuerDetails?.username || 'Token Details'
273282
}`}
274283
/>
275-
276284
<div className={tokenClass}>
277285
<div className="content-profile">
286+
<div
287+
style={{
288+
display: 'flex',
289+
flexDirection: 'column',
290+
alignItems: 'center'
291+
}}
292+
>
293+
<div style={{ width: isSsrMobile ? '100%' : '80%', marginBottom: '20px' }}>
294+
<TokenSelector value={selectedToken} onChange={setSelectedToken} excludeNative={true} />
295+
</div>
296+
</div>
278297
<div className="column-left">
279298
{/* Big Token Icon */}
280299
<img
281300
alt="token"
282301
src={tokenImageSrc(token)}
283302
className="token-image"
284-
style={{ width: '100%', height: 'auto' }}
303+
style={{ width: 'calc(100% - 4px)', height: 'auto' }}
285304
/>
286305
<h1>{token?.currencyDetails?.currency}</h1>
287306

0 commit comments

Comments
 (0)