-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2add199
commit a638f62
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
app/core/Engine/controllers/RatesController/subscriptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { | ||
RatesController, | ||
CurrencyRateState, | ||
CurrencyRateController, | ||
} from '@metamask/assets-controllers'; | ||
import Logger from '../../../../util/Logger'; | ||
|
||
/** | ||
* Sets up subscription to sync CurrencyRateController changes with RatesController | ||
* @param controllerMessenger - The main controller messenger | ||
* @param ratesController - The RatesController instance to sync with | ||
*/ | ||
export const setupCurrencyRateSync = ( | ||
controllerMessenger: { | ||
subscribe: ( | ||
eventName: string, | ||
handler: (state: CurrencyRateState) => void, | ||
) => void; | ||
}, | ||
ratesController: RatesController, | ||
): void => { | ||
controllerMessenger.subscribe( | ||
`${CurrencyRateController.name}:stateChange`, | ||
(state: CurrencyRateState) => { | ||
if (state.currentCurrency) { | ||
ratesController | ||
.setFiatCurrency(state.currentCurrency) | ||
.catch((error) => { | ||
Logger.error( | ||
error as Error, | ||
'RatesController: Failed to sync fiat currency with CurrencyRateController', | ||
); | ||
}); | ||
} | ||
}, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters