Push new conversion rate updates to the clients.

This commit is contained in:
softsimon
2021-01-06 23:31:33 +07:00
parent dc63fd9428
commit b91516a1c1
4 changed files with 26 additions and 2 deletions

View File

@@ -1,13 +1,19 @@
import logger from '../logger';
import axios from 'axios';
import { IConversionRates } from '../mempool.interfaces';
class FiatConversion {
private conversionRates = {
private conversionRates: IConversionRates = {
'USD': 0
};
private ratesChangedCallback: ((rates: IConversionRates) => void) | undefined;
constructor() { }
public setProgressChangedCallback(fn: (rates: IConversionRates) => void) {
this.ratesChangedCallback = fn;
}
public startService() {
logger.info('Starting currency rates service');
setInterval(this.updateCurrency.bind(this), 1000 * 60 * 60);
@@ -25,6 +31,9 @@ class FiatConversion {
this.conversionRates = {
'USD': usd.price,
};
if (this.ratesChangedCallback) {
this.ratesChangedCallback(this.conversionRates);
}
} catch (e) {
logger.err('Error updating fiat conversion rates: ' + e);
}