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(wallet): add swap functionality on Polygon with 0x #12382

Merged
merged 1 commit into from
Feb 26, 2022

Conversation

onyb
Copy link
Member

@onyb onyb commented Feb 23, 2022

Overview

This PR integrates 0x API on Polygon aggregating popular liquidity sources such as QuickSwap, SushiSwap, Curve, Dodo, mStable, Dfyn, Cometh and more. Most of the heavy-lifting was already taken care of by the useSwap hook, although this PR brings a few general improvements and bug fixes.

Summary of changes

  • 🧙 Swap tab is now active when Polygon network is selected.

  • 🪙 Preloaded tokens on Polygon. Add Polygon tokens list token-lists#5

  • MATIC, Polygon network, and ERC-20 tokens now use the Polygon logo.

  • 🔧 There's now a makeNetworkAsset utility available to obtain the BlockchainToken corresponding to some EthereumChain type. Hardcoded occurrences of ETH asset have been replaced with a generic native token.

  • 🐞 Handle crash scenario when swap assets list has not been loaded yet into the Redux store.

  • ✨ Refactor create-network-icon and create-placeholder-icon to make sure it works for all EVM networks, and not just Ethereum.

  • 🐞 Fixed a bug in useBalance hook where the following two scenarios were considered equal:

    // Get native asset balance of account
    useBalance(network)(account)
    
    // Get token balance of account, BUT the token variable is currently undefined.
    useBalance(network)(account, undefined)

    We instead now explicitly require callers to make use of makeNetworkAsset() in order to obtain the account balance:

    const getBalance = useBalance(network)
    
    // Before
    getBalance(account)
    
    // After
    const nativeAsset = makeNetworkAsset(network)
    getBalance(account, nativeAsset)

Resolves brave/brave-browser#21264.

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Demo 📹

Transaction 0xb8717f921cd9c252f0a7b94856f23b6eea6544ea45ed3ab46e20431139802a32
screen-recording-2022-02-23-at-105646-pm_O2qbAr8Q.mov

@onyb onyb requested a review from a team as a code owner February 23, 2022 18:37
@onyb onyb self-assigned this Feb 23, 2022
@github-actions github-actions bot added the CI/storybook-url Deploy storybook and provide a unique URL for each build label Feb 23, 2022
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

Copy link
Member

@bbondy bbondy left a comment

Choose a reason for hiding this comment

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

++ for cpp side of things.

@Paraguanads
Copy link

As long 0x services are restricted for several countries, like Venezuela, how this API gonna work on Brave?

@onyb onyb force-pushed the f/wallet/polygon-swap branch from 42a0913 to 8b796e5 Compare February 25, 2022 15:04
@onyb onyb requested a review from Douglashdaniel February 25, 2022 15:05
Copy link
Contributor

@Douglashdaniel Douglashdaniel left a comment

Choose a reason for hiding this comment

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

Good work!
Very exciting! 🙂

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@onyb
Copy link
Member Author

onyb commented Feb 25, 2022

Tested locally the token-lists update using dev goupdater.

Screen.Recording.2022-02-25.at.10.39.52.PM.mov

@onyb onyb merged commit 400c1e7 into master Feb 26, 2022
@onyb onyb deleted the f/wallet/polygon-swap branch February 26, 2022 11:26
@onyb onyb added this to the 1.38.x - Nightly milestone Feb 26, 2022
brave-builds pushed a commit that referenced this pull request Mar 9, 2022
@kjozwiak
Copy link
Member

Verification notes from @srirambv can be found via #12486 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Swap functionality to Polygon network with 0x
6 participants