mirror of
https://github.com/RoboSats/robosats.git
synced 2025-07-17 16:23:13 +00:00
Better code
This commit is contained in:
@ -4,7 +4,6 @@ import FederationTable from '../../components/FederationTable';
|
|||||||
import { t } from 'i18next';
|
import { t } from 'i18next';
|
||||||
import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
|
import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
|
||||||
import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
|
import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
|
||||||
import { Garage } from '../../models';
|
|
||||||
import { Origin, Origins } from '../../models/Coordinator.model';
|
import { Origin, Origins } from '../../models/Coordinator.model';
|
||||||
import { AppContext, UseAppStoreType } from '../../contexts/AppContext';
|
import { AppContext, UseAppStoreType } from '../../contexts/AppContext';
|
||||||
|
|
||||||
@ -20,11 +19,7 @@ const Coordinators = (): React.JSX.Element => {
|
|||||||
// Regular expression to match a valid .onion URL
|
// Regular expression to match a valid .onion URL
|
||||||
const onionUrlPattern = /^((http|https):\/\/)?[a-zA-Z2-7]{16,56}\.onion$\/?/;
|
const onionUrlPattern = /^((http|https):\/\/)?[a-zA-Z2-7]{16,56}\.onion$\/?/;
|
||||||
|
|
||||||
const addNewCoordinator: (alias: string, garage: Garage, url: string) => void = (
|
const addNewCoordinator: (alias: string, url: string) => void = (alias, url) => {
|
||||||
alias,
|
|
||||||
garage,
|
|
||||||
url,
|
|
||||||
) => {
|
|
||||||
if (!federation.getCoordinator(alias)) {
|
if (!federation.getCoordinator(alias)) {
|
||||||
const attributes: object = {
|
const attributes: object = {
|
||||||
longAlias: alias,
|
longAlias: alias,
|
||||||
@ -57,7 +52,7 @@ const Coordinators = (): React.JSX.Element => {
|
|||||||
if (!/^((http|https):\/\/)/.test(fullNewUrl)) {
|
if (!/^((http|https):\/\/)/.test(fullNewUrl)) {
|
||||||
fullNewUrl = `http://${newUrl}`;
|
fullNewUrl = `http://${newUrl}`;
|
||||||
}
|
}
|
||||||
addNewCoordinator(newAlias, garage, fullNewUrl);
|
addNewCoordinator(newAlias, fullNewUrl);
|
||||||
garage.syncCoordinator(federation, newAlias);
|
garage.syncCoordinator(federation, newAlias);
|
||||||
setNewAlias('');
|
setNewAlias('');
|
||||||
setNewUrl('');
|
setNewUrl('');
|
||||||
|
@ -69,7 +69,7 @@ const DepthChart: React.FC<DepthChartProps> = ({
|
|||||||
if (Object.values(federation.book).length > 0) {
|
if (Object.values(federation.book).length > 0) {
|
||||||
const enriched = Object.values(federation.book).map((order) => {
|
const enriched = Object.values(federation.book).map((order) => {
|
||||||
if (order?.currency) {
|
if (order?.currency) {
|
||||||
const limits = federation.getCoordinators()[0]?.limits;
|
const limits = federation.getLimits();
|
||||||
|
|
||||||
const originalPrice =
|
const originalPrice =
|
||||||
(limits[order.currency]?.price ?? 0) * (1 + parseFloat(order.premium) / 100);
|
(limits[order.currency]?.price ?? 0) * (1 + parseFloat(order.premium) / 100);
|
||||||
|
@ -216,15 +216,11 @@ export class Federation {
|
|||||||
this.triggerHook('onFederationUpdate');
|
this.triggerHook('onFederationUpdate');
|
||||||
};
|
};
|
||||||
|
|
||||||
getLimits = (shortAlias: string): LimitList => {
|
getLimits = (shortAlias?: string): LimitList => {
|
||||||
console.log('shortAlias', shortAlias);
|
let limits = shortAlias ? this.coordinators[shortAlias]?.limits || {} : {};
|
||||||
let limits = this.coordinators[shortAlias]?.limits || {};
|
|
||||||
|
|
||||||
console.log('limits pre', Object.keys(limits).length);
|
|
||||||
if (Object.keys(limits).length === 0) {
|
if (Object.keys(limits).length === 0) {
|
||||||
limits = this.getCoordinators()[0]?.limits;
|
limits = this.getCoordinators()[0]?.limits;
|
||||||
}
|
}
|
||||||
console.log('limits', Object.keys(limits).length);
|
|
||||||
return limits;
|
return limits;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user