mirror of
https://github.com/RoboSats/robosats.git
synced 2025-07-17 08:13:19 +00:00
Fix update coordinators urls on network change
This commit is contained in:
@ -9,7 +9,7 @@ self.addEventListener('message', async (event) => {
|
||||
const avatarB64 = await async_generate_robohash(hash, size == 'small' ? 80 : 256);
|
||||
const imageUrl = `data:image/png;base64,${avatarB64}`;
|
||||
const t1 = performance.now();
|
||||
console.log(`Worker ${workerIndex} :: Time to generate avatar: ${t1 - t0} ms`);
|
||||
console.log(`Avatar generated in: ${t1 - t0} ms`);
|
||||
// Send the result back to the main thread
|
||||
self.postMessage({ cacheKey, imageUrl });
|
||||
});
|
||||
|
@ -29,13 +29,16 @@ import {
|
||||
} from '@mui/icons-material';
|
||||
import { systemClient } from '../../services/System';
|
||||
import SwapCalls from '@mui/icons-material/SwapCalls';
|
||||
import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext';
|
||||
|
||||
interface SettingsFormProps {
|
||||
dense?: boolean;
|
||||
}
|
||||
|
||||
const SettingsForm = ({ dense = false }: SettingsFormProps): JSX.Element => {
|
||||
const { fav, setFav, settings, setSettings } = useContext<UseAppStoreType>(AppContext);
|
||||
const { fav, setFav, origin, hostUrl, settings, setSettings } =
|
||||
useContext<UseAppStoreType>(AppContext);
|
||||
const { federation } = useContext<UseFederationStoreType>(FederationContext);
|
||||
const theme = useTheme();
|
||||
const { t } = useTranslation();
|
||||
const fontSizes = [
|
||||
@ -223,6 +226,7 @@ const SettingsForm = ({ dense = false }: SettingsFormProps): JSX.Element => {
|
||||
value={settings.network}
|
||||
onChange={(e, network) => {
|
||||
setSettings({ ...settings, network });
|
||||
federation.updateUrls(origin, { ...settings, network }, hostUrl);
|
||||
systemClient.setItem('settings_network', network);
|
||||
}}
|
||||
>
|
||||
|
@ -133,7 +133,13 @@ export class Coordinator {
|
||||
onStarted: (shortAlias: string) => void = () => {},
|
||||
): Promise<void> => {
|
||||
if (this.enabled !== true) return;
|
||||
void this.updateUrl(settings, origin, hostUrl);
|
||||
void this.update(() => {
|
||||
onStarted(this.shortAlias);
|
||||
});
|
||||
};
|
||||
|
||||
updateUrl = async (settings: Settings, origin: Origin, hostUrl: string): Promise<void> => {
|
||||
if (settings.selfhostedClient && this.shortAlias !== 'local') {
|
||||
this.url = hostUrl;
|
||||
this.basePath = `/${settings.network}/${this.shortAlias}`;
|
||||
@ -141,9 +147,6 @@ export class Coordinator {
|
||||
this.url = String(this[settings.network][origin]);
|
||||
this.basePath = '';
|
||||
}
|
||||
void this.update(() => {
|
||||
onStarted(this.shortAlias);
|
||||
});
|
||||
};
|
||||
|
||||
update = async (onUpdate: (shortAlias: string) => void = () => {}): Promise<void> => {
|
||||
@ -170,6 +173,7 @@ export class Coordinator {
|
||||
|
||||
loadBook = (onDataLoad: () => void = () => {}): void => {
|
||||
if (!this.enabled) return;
|
||||
if (this.url === '') return;
|
||||
if (this.loadingBook) return;
|
||||
|
||||
this.loadingBook = true;
|
||||
@ -196,6 +200,7 @@ export class Coordinator {
|
||||
|
||||
loadLimits = (onDataLoad: () => void = () => {}): void => {
|
||||
if (!this.enabled) return;
|
||||
if (this.url === '') return;
|
||||
if (this.loadingLimits) return;
|
||||
|
||||
this.loadingLimits = true;
|
||||
@ -224,6 +229,7 @@ export class Coordinator {
|
||||
|
||||
loadInfo = (onDataLoad: () => void = () => {}): void => {
|
||||
if (!this.enabled) return;
|
||||
if (this.url === '') return;
|
||||
if (this.loadingInfo) return;
|
||||
|
||||
this.loadingInfo = true;
|
||||
|
@ -81,6 +81,14 @@ export class Federation {
|
||||
}
|
||||
};
|
||||
|
||||
// On Testnet/Mainnet change
|
||||
updateUrls = async (origin: Origin, settings: Settings, hostUrl: string): Promise<void> => {
|
||||
this.loading = true;
|
||||
for (const coor of Object.values(this.coordinators)) {
|
||||
await coor.updateUrl(settings, origin, hostUrl);
|
||||
}
|
||||
};
|
||||
|
||||
update = async (): Promise<void> => {
|
||||
this.loading = false;
|
||||
for (const coor of Object.values(this.coordinators)) {
|
||||
|
Reference in New Issue
Block a user