-
-
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
Integrate PollingController
into TokenRatesController
#2015
Integrate PollingController
into TokenRatesController
#2015
Conversation
…p-1025/multichain-v1-currency-rate-controller # Conflicts: # packages/network-controller/src/NetworkController.ts # packages/network-controller/tests/NetworkController.test.ts
…p-1025/multichain-v1-currency-rate-controller
* should be used to query token exchange rates. | ||
* @param tokenAddresses - The addresses for the token contracts. | ||
* @returns An object with conversion rates for each token | ||
* related to the network's native currency. | ||
*/ | ||
async fetchAndMapExchangeRates( |
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.
Can this be made private? I'm not seeing it used by either of the clients or other controllers?
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.
typescript wouldn't be happy with that since these methods are tested directly in spec
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'm not seeing this one in the test file?
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.
describe('fetchAndMapExchangeRates', () => { |
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.
Ok lets make this private in a subsequent PR per @mcmire 's suggestion
* @param vsCurrency - Query according to tokens in tokenList and native currency. | ||
* @param chainSlug - The chain string identifier. | ||
* @param vsCurrency - The currency used to generate pairs against the tokens. | ||
* @param tokenAddresses - The addresses for the token contracts. | ||
* @returns The exchange rates for the given pairs. | ||
*/ | ||
async fetchExchangeRate( |
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.
Also can this be made private? Helps to keep track of what changes should be considered and breaking and how to think about the method signatures
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 one is stubbed out a few times but we should be able to test the public methods without referring to it. I know its kindof annoying but it will make our tests better and this controller better if we make it private.
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.
had to do this because i couldn't get nock/fetch to play nicely with fake timers, I can take another look at this again though
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.
Ok lets make this private in a subsequent PR per @mcmire 's suggestion
*/ | ||
async getChainSlug(): Promise<string | null> { | ||
const { threshold, chainId } = this.config; | ||
async getChainSlug( |
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.
Another one we can make private.
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 also don't see this one referenced in the test file
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.
describe('getChainSlug', () => { |
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.
Oh you're adding them in your PR... I was looking on main
... so yea I'm sorry cuz you put in the effort to create tests for these but really they are essentially private methods that just weren't marked as such and I feel like we should mark them as private now. Lets see what @mcmire and @Gudahtt think?
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.
Less API surface area generally sounds good to me!
Alternatively, if we did want proper test coverage of an internal method we could pull it out into a separate module, and test it that way. Then it can still be private (in that it's not exported by the package), but will follow our convention of reducing API surface area and not testing private things.
The guideline of not testing private methods is really a nudge to organize code into more cohesive chunks.
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.
Lets make this private in a subsequent PR per @mcmire 's suggestion
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 great. Just a few small changes requested.
Co-authored-by: Alex Donesky <adonesky@gmail.com>
Co-authored-by: Alex Donesky <adonesky@gmail.com>
Co-authored-by: Alex Donesky <adonesky@gmail.com>
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!
Tracking remaining cleanup for marking methods private and updating specs in this issue |
FYI I've added this PR to the next release: #2063. |
Explanation
Integrates
PollingController
intoTokensRatesController
, keeping as much of the current method interfaces intact. Needed for eventual multichain support.References
Fixes: https://github.com/MetaMask/MetaMask-planning/issues/1122
Changelog
@metamask/assets-controllers
TokenRatesController
constructor params now requiresgetNetworkClientById
TokenRatesController
state now hascontractExchangeRatesByChainId
property which an object keyed bychainId
andnativeCurrency
tokenRatesController.state.contractExchangeRatesByChainId[chainId][nativeCurrency]
TokenRatesController
constructor params now accepts optionalinterval
andthreshold
updateExchangeRatesByChainId
,_executePoll
,startPollingByNetworkClientId
,stopAllPolling
, andstopPollingByPollingToken
methods toTokenRatesController
TokenRatesController.fetchExchangeRate()
now accepts an optionaltokenAddresses
as the last parameterTokenRatesController.getChainSlug()
now accepts an optionaltokenAddresses
parameterTokenRatesController.fetchAndMapExchangeRates()
now accepts an optionaltokenAddresses
as the last parameterChecklist