mirror of
https://github.com/RoboSats/robosats.git
synced 2025-09-13 00:56:22 +00:00
Fix federation summary
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import React, { useContext, useMemo } from 'react';
|
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -34,11 +34,20 @@ interface Props {
|
|||||||
|
|
||||||
const ExchangeDialog = ({ open = false, onClose }: Props): JSX.Element => {
|
const ExchangeDialog = ({ open = false, onClose }: Props): JSX.Element => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { federation } = useContext(FederationContext);
|
const { federation, federationUpdatedAt } = useContext(FederationContext);
|
||||||
|
const [loadingProgress, setLoadingProgress] = useState<number>(0);
|
||||||
|
|
||||||
const loadingProgress = useMemo(() => {
|
useEffect(() => federation.updateExchange(), []);
|
||||||
return (federation.exchange.onlineCoordinators / federation.exchange.totalCoordinators) * 100;
|
|
||||||
}, [federation.exchange.onlineCoordinators, federation.exchange.totalCoordinators]);
|
useEffect(() => {
|
||||||
|
setLoadingProgress(
|
||||||
|
(federation.exchange.onlineCoordinators / federation.exchange.totalCoordinators) * 100,
|
||||||
|
);
|
||||||
|
}, [
|
||||||
|
federationUpdatedAt,
|
||||||
|
federation.exchange.onlineCoordinators,
|
||||||
|
federation.exchange.totalCoordinators,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onClose={onClose}>
|
<Dialog open={open} onClose={onClose}>
|
||||||
@ -69,7 +78,7 @@ const ExchangeDialog = ({ open = false, onClose }: Props): JSX.Element => {
|
|||||||
</ListItemIcon>
|
</ListItemIcon>
|
||||||
|
|
||||||
<ListItemText
|
<ListItemText
|
||||||
primary={federation.exchange.totalCoordinators}
|
primary={federation.exchange.enabledCoordinators}
|
||||||
secondary={t('Enabled RoboSats coordinators')}
|
secondary={t('Enabled RoboSats coordinators')}
|
||||||
/>
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
|||||||
@ -12,19 +12,17 @@ interface ExchangeInfo {
|
|||||||
version: Version;
|
version: Version;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultExchangeInfo: ExchangeInfo = {
|
|
||||||
num_public_buy_orders: 0,
|
|
||||||
num_public_sell_orders: 0,
|
|
||||||
book_liquidity: 0,
|
|
||||||
active_robots_today: 0,
|
|
||||||
last_day_nonkyc_btc_premium: 0,
|
|
||||||
last_day_volume: 0,
|
|
||||||
lifetime_volume: 0,
|
|
||||||
version: { major: 0, minor: 0, patch: 0 },
|
|
||||||
};
|
|
||||||
|
|
||||||
export const updateExchangeInfo = (federation: Federation): ExchangeInfo => {
|
export const updateExchangeInfo = (federation: Federation): ExchangeInfo => {
|
||||||
const info: ExchangeInfo = defaultExchangeInfo;
|
const info: ExchangeInfo = {
|
||||||
|
num_public_buy_orders: 0,
|
||||||
|
num_public_sell_orders: 0,
|
||||||
|
book_liquidity: 0,
|
||||||
|
active_robots_today: 0,
|
||||||
|
last_day_nonkyc_btc_premium: 0,
|
||||||
|
last_day_volume: 0,
|
||||||
|
lifetime_volume: 0,
|
||||||
|
version: { major: 0, minor: 0, patch: 0 },
|
||||||
|
};
|
||||||
const premiums: number[] = [];
|
const premiums: number[] = [];
|
||||||
const volumes: number[] = [];
|
const volumes: number[] = [];
|
||||||
let highestVersion: Version = { major: 0, minor: 0, patch: 0 };
|
let highestVersion: Version = { major: 0, minor: 0, patch: 0 };
|
||||||
@ -39,7 +37,7 @@ export const updateExchangeInfo = (federation: Federation): ExchangeInfo => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
Object.values(federation.coordinators).forEach((coordinator, index) => {
|
Object.values(federation.coordinators).forEach((coordinator, index) => {
|
||||||
if (coordinator.info !== undefined && coordinator.enabled === true) {
|
if (coordinator.info !== undefined) {
|
||||||
premiums[index] = coordinator.info.last_day_nonkyc_btc_premium;
|
premiums[index] = coordinator.info.last_day_nonkyc_btc_premium;
|
||||||
volumes[index] = coordinator.info.last_day_volume;
|
volumes[index] = coordinator.info.last_day_volume;
|
||||||
highestVersion = getHigherVer(highestVersion, coordinator.info.version);
|
highestVersion = getHigherVer(highestVersion, coordinator.info.version);
|
||||||
@ -49,7 +47,6 @@ export const updateExchangeInfo = (federation: Federation): ExchangeInfo => {
|
|||||||
info[key] = Number(info[key]) + Number(coordinator.info[key]);
|
info[key] = Number(info[key]) + Number(coordinator.info[key]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
info.last_day_nonkyc_btc_premium = weightedMean(premiums, volumes);
|
info.last_day_nonkyc_btc_premium = weightedMean(premiums, volumes);
|
||||||
@ -68,7 +65,16 @@ export interface Exchange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const defaultExchange: Exchange = {
|
export const defaultExchange: Exchange = {
|
||||||
info: defaultExchangeInfo,
|
info: {
|
||||||
|
num_public_buy_orders: 0,
|
||||||
|
num_public_sell_orders: 0,
|
||||||
|
book_liquidity: 0,
|
||||||
|
active_robots_today: 0,
|
||||||
|
last_day_nonkyc_btc_premium: 0,
|
||||||
|
last_day_volume: 0,
|
||||||
|
lifetime_volume: 0,
|
||||||
|
version: { major: 0, minor: 0, patch: 0 },
|
||||||
|
},
|
||||||
enabledCoordinators: 0,
|
enabledCoordinators: 0,
|
||||||
onlineCoordinators: 0,
|
onlineCoordinators: 0,
|
||||||
loadingCoordinators: 0,
|
loadingCoordinators: 0,
|
||||||
|
|||||||
@ -151,6 +151,7 @@ export class Federation {
|
|||||||
this.exchange.enabledCoordinators = Object.values(this.coordinators).filter(
|
this.exchange.enabledCoordinators = Object.values(this.coordinators).filter(
|
||||||
(c) => c.enabled,
|
(c) => c.enabled,
|
||||||
).length;
|
).length;
|
||||||
|
this.triggerHook('onFederationUpdate');
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
import { type Coordinator } from '../models';
|
|
||||||
|
|
||||||
interface Version {
|
interface Version {
|
||||||
major: number | null;
|
major: number | null;
|
||||||
minor: number | null;
|
minor: number | null;
|
||||||
@ -61,58 +59,4 @@ const getHigherVer = (ver0: Version, ver1: Version): Version => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const aggregateInfo = (federation: Coordinator[]): AggregatedInfo => {
|
export default getHigherVer;
|
||||||
const info = {
|
|
||||||
onlineCoordinators: 0,
|
|
||||||
totalCoordinators: 0,
|
|
||||||
num_public_buy_orders: 0,
|
|
||||||
num_public_sell_orders: 0,
|
|
||||||
book_liquidity: 0,
|
|
||||||
active_robots_today: 0,
|
|
||||||
last_day_nonkyc_btc_premium: 0,
|
|
||||||
last_day_volume: 0,
|
|
||||||
lifetime_volume: 0,
|
|
||||||
version: { major: 0, minor: 0, patch: 0 },
|
|
||||||
};
|
|
||||||
info.totalCoordinators = federation.length;
|
|
||||||
const addUp: toAdd[] = [
|
|
||||||
'num_public_buy_orders',
|
|
||||||
'num_public_sell_orders',
|
|
||||||
'book_liquidity',
|
|
||||||
'active_robots_today',
|
|
||||||
'last_day_volume',
|
|
||||||
'lifetime_volume',
|
|
||||||
];
|
|
||||||
|
|
||||||
addUp.map((key) => {
|
|
||||||
let value = 0;
|
|
||||||
federation.map((coordinator) => {
|
|
||||||
if (coordinator.info != null) {
|
|
||||||
value = value + coordinator.info[key];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
info[key] = value;
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
const premiums: number[] = [];
|
|
||||||
const volumes: number[] = [];
|
|
||||||
let highestVersion = { major: 0, minor: 0, patch: 0 };
|
|
||||||
federation.map((coordinator, index) => {
|
|
||||||
if (coordinator.info != null) {
|
|
||||||
info.onlineCoordinators = info.onlineCoordinators + 1;
|
|
||||||
premiums[index] = coordinator.info.last_day_nonkyc_btc_premium;
|
|
||||||
volumes[index] = coordinator.info.last_day_volume;
|
|
||||||
highestVersion = getHigherVer(highestVersion, coordinator.info.version);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
info.last_day_nonkyc_btc_premium = weightedMean(premiums, volumes);
|
|
||||||
info.version = highestVersion;
|
|
||||||
|
|
||||||
return info;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default aggregateInfo;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user