Merge branch 'master' into mononaut/accelerator-audit-pools
This commit is contained in:
31 files changed
+996
-101
No files matched your search
@@ -405,7 +405,7 @@ export class ApiService {
|
||||
);
|
||||
}
|
||||
|
||||
getHistoricalPrice$(timestamp: number | undefined): Observable<Conversion> {
|
||||
getHistoricalPrice$(timestamp: number | undefined, currency?: string): Observable<Conversion> {
|
||||
if (this.stateService.isAnyTestnet()) {
|
||||
return of({
|
||||
prices: [],
|
||||
@@ -416,12 +416,47 @@ export class ApiService {
|
||||
USDCHF: 0,
|
||||
USDAUD: 0,
|
||||
USDJPY: 0,
|
||||
USDBGN: 0,
|
||||
USDBRL: 0,
|
||||
USDCNY: 0,
|
||||
USDCZK: 0,
|
||||
USDDKK: 0,
|
||||
USDHKD: 0,
|
||||
USDHRK: 0,
|
||||
USDHUF: 0,
|
||||
USDIDR: 0,
|
||||
USDILS: 0,
|
||||
USDINR: 0,
|
||||
USDISK: 0,
|
||||
USDKRW: 0,
|
||||
USDMXN: 0,
|
||||
USDMYR: 0,
|
||||
USDNOK: 0,
|
||||
USDNZD: 0,
|
||||
USDPHP: 0,
|
||||
USDPLN: 0,
|
||||
USDRON: 0,
|
||||
USDRUB: 0,
|
||||
USDSEK: 0,
|
||||
USDSGD: 0,
|
||||
USDTHB: 0,
|
||||
USDTRY: 0,
|
||||
USDZAR: 0,
|
||||
}
|
||||
});
|
||||
}
|
||||
const queryParams = [];
|
||||
|
||||
if (timestamp) {
|
||||
queryParams.push(`timestamp=${timestamp}`);
|
||||
}
|
||||
|
||||
if (currency) {
|
||||
queryParams.push(`currency=${currency}`);
|
||||
}
|
||||
return this.httpClient.get<Conversion>(
|
||||
this.apiBaseUrl + this.apiBasePath + '/api/v1/historical-price' +
|
||||
(timestamp ? `?timestamp=${timestamp}` : '')
|
||||
`${this.apiBaseUrl}${this.apiBasePath}/api/v1/historical-price` +
|
||||
(queryParams.length > 0 ? `?${queryParams.join('&')}` : '')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,32 @@ export interface ApiPrice {
|
||||
CHF: number,
|
||||
AUD: number,
|
||||
JPY: number,
|
||||
BGN?: number,
|
||||
BRL?: number,
|
||||
CNY?: number,
|
||||
CZK?: number,
|
||||
DKK?: number,
|
||||
HKD?: number,
|
||||
HRK?: number,
|
||||
HUF?: number,
|
||||
IDR?: number,
|
||||
ILS?: number,
|
||||
INR?: number,
|
||||
ISK?: number,
|
||||
KRW?: number,
|
||||
MXN?: number,
|
||||
MYR?: number,
|
||||
NOK?: number,
|
||||
NZD?: number,
|
||||
PHP?: number,
|
||||
PLN?: number,
|
||||
RON?: number,
|
||||
RUB?: number,
|
||||
SEK?: number,
|
||||
SGD?: number,
|
||||
THB?: number,
|
||||
TRY?: number,
|
||||
ZAR?: number,
|
||||
}
|
||||
export interface ExchangeRates {
|
||||
USDEUR: number,
|
||||
@@ -21,6 +47,32 @@ export interface ExchangeRates {
|
||||
USDCHF: number,
|
||||
USDAUD: number,
|
||||
USDJPY: number,
|
||||
USDBGN?: number,
|
||||
USDBRL?: number,
|
||||
USDCNY?: number,
|
||||
USDCZK?: number,
|
||||
USDDKK?: number,
|
||||
USDHKD?: number,
|
||||
USDHRK?: number,
|
||||
USDHUF?: number,
|
||||
USDIDR?: number,
|
||||
USDILS?: number,
|
||||
USDINR?: number,
|
||||
USDISK?: number,
|
||||
USDKRW?: number,
|
||||
USDMXN?: number,
|
||||
USDMYR?: number,
|
||||
USDNOK?: number,
|
||||
USDNZD?: number,
|
||||
USDPHP?: number,
|
||||
USDPLN?: number,
|
||||
USDRON?: number,
|
||||
USDRUB?: number,
|
||||
USDSEK?: number,
|
||||
USDSGD?: number,
|
||||
USDTHB?: number,
|
||||
USDTRY?: number,
|
||||
USDZAR?: number,
|
||||
}
|
||||
export interface Conversion {
|
||||
prices: ApiPrice[],
|
||||
@@ -46,6 +98,8 @@ export class PriceService {
|
||||
|
||||
lastQueriedTimestamp: number;
|
||||
lastPriceHistoryUpdate: number;
|
||||
lastQueriedCurrency: string;
|
||||
lastQueriedHistoricalCurrency: string;
|
||||
|
||||
historicalPrice: ConversionDict = {
|
||||
prices: null,
|
||||
@@ -60,16 +114,25 @@ export class PriceService {
|
||||
|
||||
getEmptyPrice(): Price {
|
||||
return {
|
||||
price: {
|
||||
price: this.stateService.env.ADDITIONAL_CURRENCIES ? {
|
||||
USD: 0, EUR: 0, GBP: 0, CAD: 0, CHF: 0, AUD: 0, JPY: 0, BGN: 0, BRL: 0, CNY: 0, CZK: 0, DKK: 0, HKD: 0, HRK: 0, HUF: 0, IDR: 0,
|
||||
ILS: 0, INR: 0, ISK: 0, KRW: 0, MXN: 0, MYR: 0, NOK: 0, NZD: 0, PHP: 0, PLN: 0, RON: 0, RUB: 0, SEK: 0, SGD: 0, THB: 0, TRY: 0,
|
||||
ZAR: 0
|
||||
} :
|
||||
{
|
||||
USD: 0, EUR: 0, GBP: 0, CAD: 0, CHF: 0, AUD: 0, JPY: 0,
|
||||
},
|
||||
exchangeRates: {
|
||||
exchangeRates: this.stateService.env.ADDITIONAL_CURRENCIES ? {
|
||||
USDEUR: 0, USDGBP: 0, USDCAD: 0, USDCHF: 0, USDAUD: 0, USDJPY: 0, USDBGN: 0, USDBRL: 0, USDCNY: 0, USDCZK: 0, USDDKK: 0, USDHKD: 0,
|
||||
USDHRK: 0, USDHUF: 0, USDIDR: 0, USDILS: 0, USDINR: 0, USDISK: 0, USDKRW: 0, USDMXN: 0, USDMYR: 0, USDNOK: 0, USDNZD: 0, USDPHP: 0,
|
||||
USDPLN: 0, USDRON: 0, USDRUB: 0, USDSEK: 0, USDSGD: 0, USDTHB: 0, USDTRY: 0, USDZAR: 0
|
||||
} : {
|
||||
USDEUR: 0, USDGBP: 0, USDCAD: 0, USDCHF: 0, USDAUD: 0, USDJPY: 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
getBlockPrice$(blockTimestamp: number, singlePrice = false): Observable<Price | undefined> {
|
||||
getBlockPrice$(blockTimestamp: number, singlePrice = false, currency: string): Observable<Price | undefined> {
|
||||
if (this.stateService.env.BASE_MODULE !== 'mempool' || !this.stateService.env.HISTORICAL_PRICE) {
|
||||
return of(undefined);
|
||||
}
|
||||
@@ -81,9 +144,10 @@ export class PriceService {
|
||||
* query a different timestamp than the last one
|
||||
*/
|
||||
if (singlePrice) {
|
||||
if (!this.singlePriceObservable$ || (this.singlePriceObservable$ && blockTimestamp !== this.lastQueriedTimestamp)) {
|
||||
this.singlePriceObservable$ = this.apiService.getHistoricalPrice$(blockTimestamp).pipe(shareReplay());
|
||||
if (!this.singlePriceObservable$ || (this.singlePriceObservable$ && (blockTimestamp !== this.lastQueriedTimestamp || currency !== this.lastQueriedCurrency))) {
|
||||
this.singlePriceObservable$ = this.apiService.getHistoricalPrice$(blockTimestamp, currency).pipe(shareReplay());
|
||||
this.lastQueriedTimestamp = blockTimestamp;
|
||||
this.lastQueriedCurrency = currency;
|
||||
}
|
||||
|
||||
return this.singlePriceObservable$.pipe(
|
||||
@@ -92,7 +156,17 @@ export class PriceService {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
price: {
|
||||
price: this.stateService.env.ADDITIONAL_CURRENCIES ? {
|
||||
USD: conversion.prices[0].USD, EUR: conversion.prices[0].EUR, GBP: conversion.prices[0].GBP, CAD: conversion.prices[0].CAD,
|
||||
CHF: conversion.prices[0].CHF, AUD: conversion.prices[0].AUD, JPY: conversion.prices[0].JPY, BGN: conversion.prices[0].BGN,
|
||||
BRL: conversion.prices[0].BRL, CNY: conversion.prices[0].CNY, CZK: conversion.prices[0].CZK, DKK: conversion.prices[0].DKK,
|
||||
HKD: conversion.prices[0].HKD, HRK: conversion.prices[0].HRK, HUF: conversion.prices[0].HUF, IDR: conversion.prices[0].IDR,
|
||||
ILS: conversion.prices[0].ILS, INR: conversion.prices[0].INR, ISK: conversion.prices[0].ISK, KRW: conversion.prices[0].KRW,
|
||||
MXN: conversion.prices[0].MXN, MYR: conversion.prices[0].MYR, NOK: conversion.prices[0].NOK, NZD: conversion.prices[0].NZD,
|
||||
PHP: conversion.prices[0].PHP, PLN: conversion.prices[0].PLN, RON: conversion.prices[0].RON, RUB: conversion.prices[0].RUB,
|
||||
SEK: conversion.prices[0].SEK, SGD: conversion.prices[0].SGD, THB: conversion.prices[0].THB, TRY: conversion.prices[0].TRY,
|
||||
ZAR: conversion.prices[0].ZAR
|
||||
} : {
|
||||
USD: conversion.prices[0].USD, EUR: conversion.prices[0].EUR, GBP: conversion.prices[0].GBP, CAD: conversion.prices[0].CAD,
|
||||
CHF: conversion.prices[0].CHF, AUD: conversion.prices[0].AUD, JPY: conversion.prices[0].JPY
|
||||
},
|
||||
@@ -106,9 +180,10 @@ export class PriceService {
|
||||
* Query all price history only once. The observable is invalidated after 1 hour
|
||||
*/
|
||||
else {
|
||||
if (!this.priceObservable$ || (this.priceObservable$ && (now - this.lastPriceHistoryUpdate > 3600))) {
|
||||
this.priceObservable$ = this.apiService.getHistoricalPrice$(undefined).pipe(shareReplay());
|
||||
if (!this.priceObservable$ || (this.priceObservable$ && (now - this.lastPriceHistoryUpdate > 3600 || currency !== this.lastQueriedHistoricalCurrency))) {
|
||||
this.priceObservable$ = this.apiService.getHistoricalPrice$(undefined, currency).pipe(shareReplay());
|
||||
this.lastPriceHistoryUpdate = new Date().getTime() / 1000;
|
||||
this.lastQueriedHistoricalCurrency = currency;
|
||||
}
|
||||
|
||||
return this.priceObservable$.pipe(
|
||||
@@ -122,9 +197,15 @@ export class PriceService {
|
||||
exchangeRates: conversion.exchangeRates,
|
||||
};
|
||||
for (const price of conversion.prices) {
|
||||
historicalPrice.prices[price.time] = {
|
||||
USD: price.USD, EUR: price.EUR, GBP: price.GBP, CAD: price.CAD,
|
||||
CHF: price.CHF, AUD: price.AUD, JPY: price.JPY
|
||||
historicalPrice.prices[price.time] = this.stateService.env.ADDITIONAL_CURRENCIES ? {
|
||||
USD: price.USD, EUR: price.EUR, GBP: price.GBP, CAD: price.CAD, CHF: price.CHF, AUD: price.AUD,
|
||||
JPY: price.JPY, BGN: price.BGN, BRL: price.BRL, CNY: price.CNY, CZK: price.CZK, DKK: price.DKK,
|
||||
HKD: price.HKD, HRK: price.HRK, HUF: price.HUF, IDR: price.IDR, ILS: price.ILS, INR: price.INR,
|
||||
ISK: price.ISK, KRW: price.KRW, MXN: price.MXN, MYR: price.MYR, NOK: price.NOK, NZD: price.NZD,
|
||||
PHP: price.PHP, PLN: price.PLN, RON: price.RON, RUB: price.RUB, SEK: price.SEK, SGD: price.SGD,
|
||||
THB: price.THB, TRY: price.TRY, ZAR: price.ZAR
|
||||
} : {
|
||||
USD: price.USD, EUR: price.EUR, GBP: price.GBP, CAD: price.CAD, CHF: price.CHF, AUD: price.AUD, JPY: price.JPY
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ export interface Env {
|
||||
SIGNET_BLOCK_AUDIT_START_HEIGHT: number;
|
||||
HISTORICAL_PRICE: boolean;
|
||||
ACCELERATOR: boolean;
|
||||
ADDITIONAL_CURRENCIES: boolean;
|
||||
GIT_COMMIT_HASH_MEMPOOL_SPACE?: string;
|
||||
PACKAGE_JSON_VERSION_MEMPOOL_SPACE?: string;
|
||||
}
|
||||
@@ -82,6 +83,7 @@ const defaultEnv: Env = {
|
||||
'SIGNET_BLOCK_AUDIT_START_HEIGHT': 0,
|
||||
'HISTORICAL_PRICE': true,
|
||||
'ACCELERATOR': false,
|
||||
'ADDITIONAL_CURRENCIES': false,
|
||||
};
|
||||
|
||||
@Injectable({
|
||||
|
||||
@@ -330,8 +330,8 @@ export class WebsocketService {
|
||||
this.stateService.rbfLatest$.next(response.rbfLatest);
|
||||
}
|
||||
|
||||
if (response.rbfLatestSummary) {
|
||||
this.stateService.rbfLatestSummary$.next(response.rbfLatestSummary);
|
||||
if (response.rbfLatestSummary !== undefined) {
|
||||
this.stateService.rbfLatestSummary$.next(response.rbfLatestSummary || []);
|
||||
}
|
||||
|
||||
if (response.txReplaced) {
|
||||
|
||||
Reference in new issue
Block a user