-
Notifications
You must be signed in to change notification settings - Fork 126
Add Token Search Results #1056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Token Search Results #1056
Changes from 59 commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
81d1f0e
sesrch queries a socket
achowdhry-ripple c5a7288
websocet successfully pulls from publix xrplmeta node
achowdhry-ripple 0d04d6f
fully working search bar for tokens
achowdhry-ripple 2fe25da
rudimentary nontoken search parsing in results bar
achowdhry-ripple a7e9bb7
new search results per design
achowdhry-ripple a0d00fa
scrollable fix
achowdhry-ripple 23ea42f
better icon and linking
achowdhry-ripple cc3ef20
minor pathves
achowdhry-ripple 3d945b9
fixed uiu cleanups
achowdhry-ripple 7cdadb4
upgraded websocket logic. now reconnects as well
achowdhry-ripple 0477a5e
added commas
achowdhry-ripple bfbcad6
spacing improvements
achowdhry-ripple c586a74
real xrp usd price and style fixes
achowdhry-ripple 87e6280
external logo
achowdhry-ripple 1a54c5b
header fixed to top
achowdhry-ripple a88aaf0
minor style fixes
achowdhry-ripple 7534676
partial code cleanup
achowdhry-ripple 3e43166
separate row component'
achowdhry-ripple bb22b2c
banner
achowdhry-ripple 35e9787
break down large html code
achowdhry-ripple 9a29c92
translations
achowdhry-ripple addb988
only render on mainnet env
achowdhry-ripple 5d4165b
external search banner for better behavior
achowdhry-ripple 2aa3e50
closable banner
achowdhry-ripple cd409db
Merge branch 'staging' into search-results
pdp2121 fba95ad
fix package merge issue
pdp2121 74ad246
fix lint
pdp2121 3e80c7d
small fixes & renames
pdp2121 3d0b6c2
use existing socket for oracle
pdp2121 5d2909e
use api instead of websocket to fetch tokens
pdp2121 6b89972
add interval for usd conversion
pdp2121 f009f22
Replace renderCurrency with Currency
pdp2121 8e5bc75
use css for default logo
pdp2121 9b2a663
remove react-tooltip
pdp2121 b7006b2
fix lint
pdp2121 598dcea
fix tests
pdp2121 42c38b4
use domain link
pdp2121 33458ad
remove parseDomain
pdp2121 76eb402
make close banner clickable
pdp2121 dff1d89
change banner duration back to 10 seconds
pdp2121 dcf0f97
fix banner
pdp2121 f658c06
initial server implementation
pdp2121 da1745b
fix mobile view
pdp2121 31add9f
only render banner for mainnet
pdp2121 a43a333
Merge branch 'staging' into search-results
pdp2121 d69b53a
cache all filtered tokens
achowdhry-ripple 7e48d13
consistent capitalization in search algo, parse currency code on backend
achowdhry-ripple 970db70
website spacing fix
achowdhry-ripple acb273a
cleanup in looping logic
achowdhry-ripple b04d3f9
cleanups and comments
achowdhry-ripple 69d20b6
spacing issue on pills fix
achowdhry-ripple dc3a059
add tests
pdp2121 6a783e3
Merge branch 'search-results' into search-results-server
achowdhry-ripple 9ee057b
translate banner
achowdhry-ripple 6440723
remove extra whitespace
achowdhry-ripple 196ab39
remove extra import
achowdhry-ripple dbbf791
lint translation fix
achowdhry-ripple f57e4b1
search issuer startswith instead of include
achowdhry-ripple 1cc9ce3
dom cleanup and mobile width fix
achowdhry-ripple 2cd9ca9
fix test
pdp2121 bfd3e8a
use color variables
achowdhry-ripple a2f99b3
Update src/containers/shared/components/TokenSearchResults/TokenSearc…
achowdhry-ripple eff6cbb
Update src/containers/shared/components/TokenSearchResults/TokenSearc…
achowdhry-ripple 44ed125
Update src/containers/shared/components/TokenSearchResults/TokenSearc…
achowdhry-ripple be79f53
remove propTypes
pdp2121 0e54e10
Merge branch 'search-results' of https://github.com/ripple/explorer i…
pdp2121 af1c964
review suggestions cleanups
achowdhry-ripple 8f95e07
remove QuickHarness
pdp2121 99943d6
fix lint
pdp2121 0c054d2
usequery instead of useeffect
achowdhry-ripple 5036059
usequery fix
achowdhry-ripple c9fec39
lint
achowdhry-ripple d258ac7
add protocol
pdp2121 d1d3769
log url
pdp2121 3ed1350
remove test log
pdp2121 2d67c78
fix issue link spacing
achowdhry-ripple 20d6656
fix stale result
pdp2121 64ef3c8
remove test log
pdp2121 cd44d9e
usequery for rate
pdp2121 c75b2dc
fix lint
pdp2121 e58436e
manage state in usequery
achowdhry-ripple fa439f6
usequery cleanup
achowdhry-ripple c25603d
use component
pdp2121 c94ea47
Merge branch 'search-results' of https://github.com/ripple/explorer i…
pdp2121 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |
| "explorer": "Explorer", | ||
| "xrpl_org": "XRPL.org", | ||
| "github": "GitHub", | ||
| "header.search.placeholder": "Search by Address, Ledger or Txn", | ||
| "header.search.placeholder": "Search by Token, Address, Ledger or Txn", | ||
| "xrp": "XRP", | ||
| "xrpl_explorer": "XRPL Explorer", | ||
| "ledgers": "Ledgers", | ||
|
|
@@ -540,6 +540,9 @@ | |
| "asset_class": "Asset Class", | ||
| "trading_pairs": "Trading Pairs", | ||
| "deleted": "Deleted", | ||
| "holders": "HOLDERS: {{holders}}", | ||
| "trustlines": " TRUSTLINES: {{trustlines}}", | ||
| "website": "Wesbite", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo, should be "Website". |
||
| "mpt_issuance_id": "MPT Issuance ID", | ||
| "asset_scale": "Asset Scale", | ||
| "metadata": "Metadata", | ||
|
|
@@ -553,5 +556,6 @@ | |
| "can_escrow": "Can Escrow", | ||
| "can_trade": "Can Trade", | ||
| "can_transfer": "Can Transfer", | ||
| "can_clawback": "Can Clawback" | ||
| "can_clawback": "Can Clawback", | ||
| "search_results_banner": "Token search by name and account is now available! Try searching for USD" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| const axios = require('axios') | ||
| const log = require('../../lib/logger')({ name: 'tokens search' }) | ||
|
|
||
| const REFETCH_INTERVAL = 60 * 60 * 1000 // 1 hour | ||
| const XRPLMETA_QUERY_LIMIT = 1000 | ||
| const cachedTokenSearchList = { tokens: [], last_updated: null } | ||
|
|
||
| const parseCurrency = (currency) => { | ||
| const NON_STANDARD_CODE_LENGTH = 40 | ||
| const LP_TOKEN_IDENTIFIER = '03' | ||
|
|
||
| const hexToString = (hex) => { | ||
| let string = '' | ||
| for (let i = 0; i < hex.length; i += 2) { | ||
| const part = hex.substring(i, i + 2) | ||
| const code = parseInt(part, 16) | ||
| if (!isNaN(code) && code !== 0) { | ||
| string += String.fromCharCode(code) | ||
| } | ||
| } | ||
| return string | ||
| } | ||
|
|
||
| return currency.length === NON_STANDARD_CODE_LENGTH && | ||
| currency?.substring(0, 2) !== LP_TOKEN_IDENTIFIER | ||
| ? hexToString(currency) | ||
| : currency | ||
| } | ||
|
|
||
| async function fetchXRPLMetaTokens(offset) { | ||
| log.info('caching tokens from XRPLMeta') | ||
| return axios | ||
| .get( | ||
| `${process.env.XRPL_META_URL}/tokens?trust_level=1&trust_level=2&trust_level=3`, | ||
| { | ||
| params: { | ||
| sort_by: 'holders', | ||
| offset, | ||
| limit: XRPLMETA_QUERY_LIMIT, | ||
| }, | ||
| }, | ||
| ) | ||
| .then((resp) => resp.data) | ||
| .catch((e) => log.error(e)) | ||
| } | ||
|
|
||
| async function cacheXRPLMetaTokens() { | ||
| let offset = 0 | ||
| let tokensDataBatch = [] | ||
| const allTokensFetched = [] | ||
|
|
||
| tokensDataBatch = await fetchXRPLMetaTokens(0) | ||
| const { count } = tokensDataBatch | ||
| while (offset < count) { | ||
| allTokensFetched.push(...tokensDataBatch.tokens) | ||
| offset += XRPLMETA_QUERY_LIMIT | ||
| // eslint-disable-next-line no-await-in-loop | ||
| tokensDataBatch = await fetchXRPLMetaTokens(offset) | ||
| } | ||
|
|
||
| cachedTokenSearchList.tokens = allTokensFetched.filter( | ||
| (result) => | ||
| result.metrics.trustlines > 50 && | ||
| result.metrics.holders > 50 && | ||
| result.metrics.marketcap > 0 && | ||
| result.metrics.volume_7d > 0, | ||
| ) | ||
| cachedTokenSearchList.last_updated = Date.now() | ||
|
|
||
| // nonstandard from XRPLMeta, check for hex codes in currencies and store parsed | ||
| cachedTokenSearchList.tokens.map((token) => ({ | ||
| ...token, | ||
| currency: parseCurrency(token.currency), | ||
| })) | ||
| } | ||
|
|
||
| function startCaching() { | ||
| if (process.env.VITE_ENVIRONMENT !== 'mainnet') { | ||
| return | ||
| } | ||
| cacheXRPLMetaTokens() | ||
| setInterval(() => cacheXRPLMetaTokens(), REFETCH_INTERVAL) | ||
| } | ||
|
|
||
| startCaching() | ||
|
|
||
| function queryTokens(tokenList, query) { | ||
| const sanitizedQuery = query.toLowerCase() | ||
|
|
||
| return tokenList.filter( | ||
| (token) => | ||
| token.currency?.toLowerCase().includes(sanitizedQuery) || | ||
| token.meta?.token?.name?.toLowerCase().includes(sanitizedQuery) || | ||
| token.meta?.issuer?.name?.toLowerCase().includes(sanitizedQuery) || | ||
| token.issuer?.toLowerCase().startsWith(sanitizedQuery), | ||
| ) | ||
| } | ||
|
|
||
| function sleep(ms) { | ||
| return new Promise((resolve) => setTimeout(resolve, ms)) | ||
| } | ||
|
|
||
| module.exports = async (req, res) => { | ||
| try { | ||
| log.info('getting tokens list for search') | ||
| const { query } = req.params | ||
| while (cachedTokenSearchList.tokens.length === 0) { | ||
| // eslint-disable-next-line no-await-in-loop -- necessary here to wait for cache to be filled | ||
| await sleep(1000) | ||
| } | ||
| const queriedTokens = await queryTokens(cachedTokenSearchList.tokens, query) | ||
| return res.status(200).json({ | ||
| result: 'success', | ||
| updated: cachedTokenSearchList.last_updated, | ||
| tokens: queriedTokens, | ||
| }) | ||
| } catch (error) { | ||
| log.error(error) | ||
| return res.status(error.code || 500).json({ message: error.message }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.