-
-
Notifications
You must be signed in to change notification settings - Fork 187
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: export exchange rates fct #3657
feat: export exchange rates fct #3657
Conversation
aec12f9
to
584bcef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking care of this! I had a few comments for improvements we can make.
584bcef
to
b40d809
Compare
packages/assets-controllers/src/token-prices-service/codefi-v2.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of comments, one about the change in codefi-v2.ts
, and another for TokenRatesController, but this looks good otherwise!
packages/assets-controllers/src/token-prices-service/codefi-v2.ts
Outdated
Show resolved
Hide resolved
c6b1de6
to
eaa67e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me, thanks! I'll approve it now though I'll keep tabs on it in case #3687 forces more changes.
* The maximum number of token addresses that should be sent to the Price API in | ||
* a single request. | ||
*/ | ||
export const TOKEN_PRICES_BATCH_SIZE = 100; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a package-level export as well? I assume it's only used inside of assets-controllers
, but just wanted to check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had requested that it be moved from TokenRatesController so it wasn't a package-level export, as I didn't think anyone needed to refer to this. But I guess I made an assumption, so that's a fair question — do we anticipate this being used in client code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now i do not expect extension to be using this.
You guys think its fine to keep it in assetsUtil.ts in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't anticipate that we'd need this anywhere else either.
It seems more appropriate for this to be part of the service itself, rather than here or in the controller. This choice in batch size is a recommendation specific to the CodeFi V2 price API in particular. It would be ideal if we could attach this batch size to the service instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This constant exists here because the batching code is outside of the service at the moment. Perhaps we can integrate that better in another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!!
aba4038
to
cca73cc
Compare
* @param args.chainId - The chainId of the tokens. | ||
* @returns The prices for the requested tokens. | ||
*/ | ||
export async function fetchTokenContractExchangeRates({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered incorporating this into the token price service itself? That would let us remove the duplication between here and the controller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry — this was my recommendation to bring over the batching code from the controller. My thought was that we could refactor the controller later to use this function, but at least at the moment, if the batching were in this function too, the behavior would be the same regardless of whether you used this function or the controller. Wondering if we could take care of moving the batching in another PR? That should be a non-breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it might result in breaking changes, depending on how we merge the two. If we move it into the service, the other methods on the serve might no longer be needed, letting us remove those from the API. Though of course we could do that in two steps.
And overall yes I agree, we can merge this and refactor it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just created an issue to track this suggestion: #4117
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I left some suggestions, one of which might require substantial changes but would leave this in a state that is easier to maintain (moving this into the token service). But I don't object to merging this as-is if you'd prefer.
cca73cc
to
6634b1c
Compare
6634b1c
to
6c474eb
Compare
## **Description** The goal of this PR is to fetch user token fiat balance on the import modal confirmation page. There is an ongoing PR on core to enable this: MetaMask/core#3657 ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/MMASSETS-88 also design wise relates to this PR #21704 ## **Manual testing steps** 1. Go to home page 2. Click on import tokens button 3. Select a token 4. Click import 5. Notice the token balance in fiat on the confirmation page ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** ![image](https://github.com/MetaMask/metamask-extension/assets/10994169/a7513ded-2960-4c6d-972d-8bb1d673f0df) ### **After** ![image](https://github.com/MetaMask/metamask-extension/assets/10994169/1232ba09-9769-476d-b4f8-12415ac55f2c) ## **Pre-merge author checklist** - [] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've clearly explained what problem this PR is solving and how it is solved. - [ ] I've linked related issues - [ ] I've included manual testing steps - [ ] I've included screenshots/recordings if applicable - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [ ] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [ ] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
## **Description** The goal of this PR is to fetch user token fiat balance on the import modal confirmation page. There is an ongoing PR on core to enable this: MetaMask/core#3657 ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/MMASSETS-88 also design wise relates to this PR #21704 ## **Manual testing steps** 1. Go to home page 2. Click on import tokens button 3. Select a token 4. Click import 5. Notice the token balance in fiat on the confirmation page ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** ![image](https://github.com/MetaMask/metamask-extension/assets/10994169/a7513ded-2960-4c6d-972d-8bb1d673f0df) ### **After** ![image](https://github.com/MetaMask/metamask-extension/assets/10994169/1232ba09-9769-476d-b4f8-12415ac55f2c) ## **Pre-merge author checklist** - [] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've clearly explained what problem this PR is solving and how it is solved. - [ ] I've linked related issues - [ ] I've included manual testing steps - [ ] I've included screenshots/recordings if applicable - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [ ] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [ ] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
Explanation
Export a function from assets controller to fetch token exchange rates.
This function will be used by extension to compute user token fiat amount and display it on the import token modal confirmation page.
References
Changelog
@metamask/assets-controllers
assetsUtil
file to exportfetchAndMapExchangeRates
functionChecklist