asdasd
This commit is contained in:
@@ -321,6 +321,7 @@
|
||||
measurements: Array.isArray(normalized.measurements) ? normalized.measurements : [],
|
||||
targets: Array.isArray(normalized.targets) ? normalized.targets : [],
|
||||
dashboards: Array.isArray(normalized.dashboards) ? normalized.dashboards : [],
|
||||
fx_snapshots: normalized.fx_snapshots && typeof normalized.fx_snapshots === 'object' ? normalized.fx_snapshots : {},
|
||||
summary: normalized.summary || {
|
||||
latest_measurement: null,
|
||||
baseline: normalized.settings || null,
|
||||
@@ -897,28 +898,50 @@
|
||||
return 1;
|
||||
}
|
||||
|
||||
const measurementRates = Array.isArray(currentSettings.measurement_rates) ? currentSettings.measurement_rates : [];
|
||||
const direct = measurementRates.find((row) =>
|
||||
Number(row.measurement_id) === Number(measurementId)
|
||||
&& String(row.base_currency || '').toUpperCase() === from
|
||||
&& String(row.target_currency || row.quote_currency || '').toUpperCase() === to
|
||||
);
|
||||
if (direct) {
|
||||
const value = Number(direct.rate);
|
||||
if (Number.isFinite(value) && value > 0) {
|
||||
return value;
|
||||
const measurement = measurements.find((row) => Number(row.id) === Number(measurementId));
|
||||
const fetchId = measurement && measurement.fx_fetch_id !== null && measurement.fx_fetch_id !== undefined
|
||||
? String(measurement.fx_fetch_id)
|
||||
: '';
|
||||
const snapshots = payload && payload.fx_snapshots && typeof payload.fx_snapshots === 'object'
|
||||
? payload.fx_snapshots
|
||||
: {};
|
||||
const snapshot = fetchId && snapshots[fetchId] && typeof snapshots[fetchId] === 'object'
|
||||
? snapshots[fetchId]
|
||||
: null;
|
||||
|
||||
if (snapshot) {
|
||||
const baseCurrency = String(snapshot.base_currency || '').toUpperCase();
|
||||
const rates = snapshot.rates && typeof snapshot.rates === 'object' ? snapshot.rates : {};
|
||||
const directRate = from === baseCurrency ? rates[to] : null;
|
||||
if (Number.isFinite(Number(directRate)) && Number(directRate) > 0) {
|
||||
return Number(directRate);
|
||||
}
|
||||
|
||||
const inverseRate = to === baseCurrency ? rates[from] : null;
|
||||
if (Number.isFinite(Number(inverseRate)) && Number(inverseRate) > 0) {
|
||||
return 1 / Number(inverseRate);
|
||||
}
|
||||
|
||||
const fromRate = from === baseCurrency ? 1 : Number(rates[from]);
|
||||
const toRate = to === baseCurrency ? 1 : Number(rates[to]);
|
||||
if (Number.isFinite(fromRate) && Number.isFinite(toRate) && fromRate > 0 && toRate > 0) {
|
||||
return toRate / fromRate;
|
||||
}
|
||||
}
|
||||
|
||||
const inverse = measurementRates.find((row) =>
|
||||
Number(row.measurement_id) === Number(measurementId)
|
||||
&& String(row.base_currency || '').toUpperCase() === to
|
||||
&& String(row.target_currency || row.quote_currency || '').toUpperCase() === from
|
||||
);
|
||||
if (inverse) {
|
||||
const value = Number(inverse.rate);
|
||||
if (Number.isFinite(value) && value > 0) {
|
||||
return 1 / value;
|
||||
const priceQuotes = measurement && measurement.price_quotes && typeof measurement.price_quotes === 'object'
|
||||
? measurement.price_quotes
|
||||
: null;
|
||||
if (priceQuotes && from === 'DOGE') {
|
||||
const directQuote = Number(priceQuotes[to]);
|
||||
if (Number.isFinite(directQuote) && directQuote > 0) {
|
||||
return directQuote;
|
||||
}
|
||||
}
|
||||
if (priceQuotes && to === 'DOGE') {
|
||||
const inverseQuote = Number(priceQuotes[from]);
|
||||
if (Number.isFinite(inverseQuote) && inverseQuote > 0) {
|
||||
return 1 / inverseQuote;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user