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

Add GetEthTokenSymbol and GetEthTokenDecimals to JsonRpcService #18254

Merged
merged 4 commits into from
Apr 28, 2023

Conversation

nvonpentz
Copy link
Contributor

@nvonpentz nvonpentz commented Apr 26, 2023

Resolves brave/brave-browser#29983

Exposes two APIs to the frontend, GetEthTokenSymbol and GetEthTokenDecimals, so that this data can be fetched. The first use case is for swaps with unknown tokens, however we can also use this to pre-fetch symbols when users are adding NFTs manually so they do not need to input it themselves.

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 wiki
    • npm run lint, npm run presubmit wiki, 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:

Test Plan:

@nvonpentz nvonpentz requested a review from a team as a code owner April 26, 2023 19:24
@nvonpentz nvonpentz force-pushed the get-eth-token-symbol branch from 2c31d72 to 8c1efdf Compare April 26, 2023 19:29
@nvonpentz nvonpentz marked this pull request as draft April 26, 2023 21:40
@nvonpentz nvonpentz force-pushed the get-eth-token-symbol branch from 91df724 to f9b176b Compare April 27, 2023 15:19
@nvonpentz nvonpentz changed the title Add GetEthTokenSymbol to JsonRpcService Add GetEthTokenSymbol and GetEthTokenDecimals to JsonRpcService Apr 27, 2023
@nvonpentz nvonpentz marked this pull request as ready for review April 27, 2023 16:35
RequestInternal(eth::eth_call("", contract_address, "", "", "", data,
kEthereumBlockTagLatest),
true, network_url, std::move(internal_callback));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note - Jocelyn had asked that GetEthTokenSymbol and GetEthTokenDecimals share the code since they are similar, however because symbol()and decimals() return different types (string and uint8 respectively), their parsing logic is different, so I didn't see much opportunity for reuse.

@nvonpentz nvonpentz requested a review from supermassive April 27, 2023 16:53

// Fetches decimals of an ERC20 or ERC721 token.
GetEthTokenDecimals(string chain_id,
string contract_address) => (string symbol,
Copy link
Collaborator

@supermassive supermassive Apr 28, 2023

Choose a reason for hiding this comment

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

symbol->decimals

auto internal_callback =
base::BindOnce(&JsonRpcService::OnGetEthTokenDecimals,
weak_ptr_factory_.GetWeakPtr(), std::move(callback));
RequestInternal(eth::eth_call("", contract_address, "", "", "", data,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Short form please: eth_call(contract_address, data) for both methods

"result":"$1"
})";

std::string formatJsonRpcResponse(const std::string& value) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

formatJsonRpcResponse->FormatJsonRpcResponse

Copy link
Collaborator

@supermassive supermassive left a comment

Choose a reason for hiding this comment

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

LGTM with minor suggestions

* Rename symbol -> decimals

* Rename formatJsonRpcResponse -> FormatJsonRpcResponse

* Use short form of eth::eth_call
@nvonpentz nvonpentz force-pushed the get-eth-token-symbol branch from f9b176b to 0106405 Compare April 28, 2023 13:46
@nvonpentz nvonpentz enabled auto-merge (squash) April 28, 2023 13:47
@nvonpentz nvonpentz merged commit 117877c into master Apr 28, 2023
@nvonpentz nvonpentz deleted the get-eth-token-symbol branch April 28, 2023 17:46
@github-actions github-actions bot added this to the 1.53.x - Nightly milestone Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add GetEthTokenSymbol and GetEthTokenDecimals core APIs that accept a chain_id and contract_address
2 participants