Skip to content

Commit

Permalink
Move CurrencyRateController normalizing logic into state initializa…
Browse files Browse the repository at this point in the history
…tion in constructor
  • Loading branch information
MajorLift committed Nov 19, 2024
1 parent dc2b3e6 commit 9eab5be
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,25 @@ export class Engine {
allowedActions: [`${networkController.name}:getNetworkClientById`],
allowedEvents: [],
}),
state: initialState.CurrencyRateController,
// normalize `null` currencyRate to `0`
// TODO: handle `null` currencyRate by hiding fiat values instead
state: {
...initialState.CurrencyRateController,
currencyRates: Object.fromEntries(
Object.entries(
initialState.CurrencyRateController?.currencyRates ?? {
ETH: {
conversionRate: 0,
conversionDate: 0,
usdConversionRate: null,
},
},
).map(([k, v]) => [
k,
{ ...v, conversionRate: v.conversionRate ?? 0 },
]),
),
},
});

const gasFeeController = new GasFeeController({
Expand Down Expand Up @@ -2399,24 +2417,12 @@ export default {
AccountsController,
} = instance.datamodel.state;

// normalize `null` currencyRate to `0`
// TODO: handle `null` currencyRate by hiding fiat values instead
const modifiedCurrencyRateControllerState = {
...CurrencyRateController,
currencyRates: Object.fromEntries(
Object.entries(CurrencyRateController.currencyRates).map(([k, v]) => [
k,
{ ...v, conversionRate: v.conversionRate ?? 0 },
]),
),
};

return {
AccountTrackerController,
AddressBookController,
NftController,
TokenListController,
CurrencyRateController: modifiedCurrencyRateControllerState,
CurrencyRateController,
KeyringController,
NetworkController,
PhishingController,
Expand Down

0 comments on commit 9eab5be

Please sign in to comment.