mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* MegaETH: uptime dashboard Fixes #2906 * basic implementation of mini-blocks * update socket url and time format * update mega eth preset * customize flashblocks name * clean up * update color theme variable for mega eth * [skip ci] don't show alert "scanning new mini-blocks"
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { decompress } from 'brotli-compress/js';
|
|
|
|
import type { FlashblockItemApiMegaEth, FlashblockItemApiOptimism } from 'types/api/flashblocks';
|
|
|
|
export async function parseSocketEventDataOptimism(event: MessageEvent) {
|
|
try {
|
|
const textData = await event.data.text();
|
|
if (textData.trim().startsWith('{')) {
|
|
return JSON.parse(textData) as FlashblockItemApiOptimism;
|
|
} else {
|
|
const arrayBuffer = await event.data.arrayBuffer();
|
|
const u8Data = new Uint8Array(arrayBuffer);
|
|
const decompressedData = Buffer.from(await decompress(u8Data)).toString('utf-8');
|
|
return JSON.parse(decompressedData) as FlashblockItemApiOptimism;
|
|
}
|
|
} catch (error) {
|
|
// eslint-disable-next-line no-console
|
|
console.error(error);
|
|
return;
|
|
}
|
|
}
|
|
|
|
export function parseSocketEventDataMegaEth(event: MessageEvent) {
|
|
try {
|
|
const parsedMessage = JSON.parse(event.data) as { method: string; params: { result: FlashblockItemApiMegaEth } };
|
|
if (parsedMessage.method === 'eth_subscription') {
|
|
return parsedMessage.params.result;
|
|
}
|
|
} catch (error) {
|
|
// eslint-disable-next-line no-console
|
|
console.error(error);
|
|
return;
|
|
}
|
|
}
|