MetaMask / core

This monorepo is a collection of packages used across multiple MetaMask clients
MIT License
287 stars 183 forks source link

feat: make polling input generic #4752

Open bergeron opened 2 days ago

bergeron commented 2 days ago

Proposal

Allow the polling controllers to accept generic input when starting a poll.

Today they accept:

networkClientId: NetworkClientId,
options: Json

But controllers may want unique polling loops over other data.

This PR allows controllers to use any serializable type as their polling input. Controllers pass their input type as a generic argument to the base class, making it more type safe than then previous options: Json.

An example of how this would be used in the future, is how CurrencyRateController only needs a polling loop for each unique native currency. So it would define:

type CurrencyRatePollingInput = {
  nativeCurrency: string;
};

And you would initiate polling with:

const currencyRateController = new(...);
const token1 = currencyRateController.startPolling({nativeCurrency: 'ETH'});
const token2 = currencyRateController.startPolling({nativeCurrency: 'POL'});