Skip to content
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

feat: special case arb search #6584

Merged
merged 2 commits into from
May 22, 2023
Merged

feat: special case arb search #6584

merged 2 commits into from
May 22, 2023

Conversation

cartcrom
Copy link
Contributor

Description

Special cases the ARB token on Arbitrum to always display over the ARB token on Mainnet in search results when both are returned by the backend, regardless of the user's current chain.

Also cleans up / renames the cross token search code to make functionality more clear.

Linear ticket

Screen capture

Before After (Desktop)
image image

QA (ie manual testing)

  • Search for a string that should return ARB as a search result, ensure it has the Arbitrum logo rather than no logo

@cartcrom cartcrom requested a review from cbachmeier May 16, 2023 20:28
@vercel
Copy link

vercel bot commented May 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
interface ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 18, 2023 7:41pm

@codecov
Copy link

codecov bot commented May 16, 2023

Codecov Report

Patch coverage: 10.00% and project coverage change: -0.15 ⚠️

Comparison is base (fd1aded) 62.62% compared to head (31d764a) 62.47%.

❗ Current head 31d764a differs from pull request most recent head ad9daae. Consider uploading reports for the commit ad9daae to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6584      +/-   ##
==========================================
- Coverage   62.62%   62.47%   -0.15%     
==========================================
  Files         714      714              
  Lines       21039    21044       +5     
  Branches     6956     6956              
==========================================
- Hits        13175    13147      -28     
- Misses       7786     7819      +33     
  Partials       78       78              
Flag Coverage Δ
e2e-tests 59.95% <100.00%> (-0.29%) ⬇️
unit-tests 21.04% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/graphql/data/SearchTokens.ts 0.00% <0.00%> (ø)
src/constants/tokens.ts 88.49% <100.00%> (+0.10%) ⬆️

... and 13 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@cbachmeier cbachmeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to avoid 1 offs whenever possible. MATIC is cross chain, what's the logic we use for this token to show it's native network first and can we re-use it for ARB?
Screen Shot 2023-05-16 at 15 07 11

@cartcrom
Copy link
Contributor Author

I'd like to avoid 1 offs whenever possible. MATIC is cross chain, what's the logic we use for this token to show it's native network first and can we re-use it for ARB? Screen Shot 2023-05-16 at 15 07 11

I completely agree about 1 offs, and suggested using huge volume differences as a metric to override the default behaviour of showing the token on the wallet's current chain, but product wants to keep the scope of this change to just ARB for now. We can't re-use the MATIC logic, because that logic relies on Polygon MATIC being a native token

@cartcrom cartcrom requested a review from cbachmeier May 17, 2023 15:14
// Always priotize natives, and if both tokens are native, prefer native on current chain (i.e. Matic on Polygon over Matic on Mainnet )
if (current.standard === 'NATIVE' && (existing.standard !== 'NATIVE' || current.chain === searchChain)) return true
// Special case: always prefer Arbitrum ARB over Mainnet ARB
if (current.address === ARB.address) return current
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing mainnet ARB over arbitrum ARB in the preview
Screen Shot 2023-05-17 at 08 16 37

Copy link
Contributor

@cbachmeier cbachmeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns expected result, however not sure if second check is necessary

Comment on lines +55 to +56
if (current.address?.toLowerCase() === ARB_ADDRESS) return current
if (existing.address?.toLowerCase() === ARB_ADDRESS) return existing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure both of these are necessary? Having just the first check, if (current.address?.toLowerCase() === ARB_ADDRESS) return current, with the lowercase casting works for mainnet and arbitrum networks
Screen Shot 2023-05-18 at 13 42 25

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on the order the backend returns the two ARB tokens in, if the backend started returning them in the opposite order, only having one check wouldn't work.

@cartcrom cartcrom requested a review from JFrankfurt May 19, 2023 17:02
@@ -87,7 +99,7 @@ export function useSearchTokens(searchQuery: string, chainId: number) {
data?.searchTokens?.forEach((token) => {
if (token.project?.id) {
const existing = selectionMap[token.project.id]
if (isMoreRevelantToken(token, existing, searchChain)) selectionMap[token.project.id] = token
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like there's a behavior change here that might not be intentional--in the old one there were cases where selectionMap[token.project.id] wouldn't be assigned a value here, but now every iteration assigns a value. Is that intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In cases where isMoreRevelantToken would've returned false, dedupeCrosschainTokens returns existing, so this is just a refactor for readability

@JFrankfurt
Copy link
Contributor

smol

@cartcrom cartcrom merged commit f3a80c6 into main May 22, 2023
17 checks passed
@cartcrom cartcrom deleted the arb_search_results branch May 22, 2023 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants