timestamp and log fixes
This commit is contained in:
@@ -4,6 +4,7 @@ import { Select } from ".";
|
|||||||
import state, { ILog, transactionsState } from "../state";
|
import state, { ILog, transactionsState } from "../state";
|
||||||
import { extractJSON } from "../utils/json";
|
import { extractJSON } from "../utils/json";
|
||||||
import LogBox from "./LogBox";
|
import LogBox from "./LogBox";
|
||||||
|
import { parse } from "date-format-parse";
|
||||||
|
|
||||||
interface ISelect<T = string> {
|
interface ISelect<T = string> {
|
||||||
label: string;
|
label: string;
|
||||||
@@ -66,7 +67,6 @@ const DebugStream = () => {
|
|||||||
// deliberately using `proxy` values and not the `useSnapshot` ones to have no dep list
|
// deliberately using `proxy` values and not the `useSnapshot` ones to have no dep list
|
||||||
const acc = streamState.selectedAccount;
|
const acc = streamState.selectedAccount;
|
||||||
const status = streamState.status;
|
const status = streamState.status;
|
||||||
const lst = streamState.logs[streamState.logs.length - 1]?.timestamp;
|
|
||||||
|
|
||||||
if (status === "opened" && acc) {
|
if (status === "opened" && acc) {
|
||||||
// fetch the missing ones
|
// fetch the missing ones
|
||||||
@@ -86,10 +86,12 @@ const DebugStream = () => {
|
|||||||
|
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
|
|
||||||
Object.entries(body.logs)
|
if (!body?.logs.length) return
|
||||||
.filter(([time, log]) => +time >= (lst || Infinity))
|
streamState.logs = [];
|
||||||
.forEach(([time, log]) => pushLog(log));
|
pushLog(`Debug stream opened for account ${acc.value}`, {
|
||||||
|
type: "success",
|
||||||
|
});
|
||||||
|
Object.values(body.logs).forEach(log => pushLog(log));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(error);
|
console.warn(error);
|
||||||
}
|
}
|
||||||
@@ -165,18 +167,19 @@ export default DebugStream;
|
|||||||
|
|
||||||
export const pushLog = (
|
export const pushLog = (
|
||||||
str: any,
|
str: any,
|
||||||
opts: { type?: ILog["type"] } = {}
|
opts: Partial<Pick<ILog, "type">> = {}
|
||||||
): ILog | undefined => {
|
): ILog | undefined => {
|
||||||
if (!str) return;
|
if (!str) return;
|
||||||
if (typeof str !== "string") throw Error("Unrecognized debug log stream!");
|
if (typeof str !== "string") throw Error("Unrecognized debug log stream!");
|
||||||
|
|
||||||
const timestamp = Date.now();
|
|
||||||
|
|
||||||
const match = str.match(/([\s\S]+(?:UTC|ISO|GMT[+|-]\d+))?\ ?([\s\S]*)/m);
|
const match = str.match(/([\s\S]+(?:UTC|ISO|GMT[+|-]\d+))?\ ?([\s\S]*)/m);
|
||||||
const [_, tm, msg] = match || [];
|
const [_, tm, msg] = match || [];
|
||||||
|
|
||||||
const ts = Date.parse(tm || "");
|
const timestamp =
|
||||||
const timestring = isNaN(ts) ? tm : new Date(tm).toLocaleTimeString();
|
Date.parse(tm || "") ||
|
||||||
|
parse(tm, "YYYY-MMM-DD HH:MM:ss.SSSSSSSSS").valueOf() ||
|
||||||
|
Date.now();
|
||||||
|
const timestring = new Date(timestamp).toLocaleTimeString();
|
||||||
|
|
||||||
const extracted = extractJSON(msg);
|
const extracted = extractJSON(msg);
|
||||||
const message = !extracted
|
const message = !extracted
|
||||||
@@ -197,7 +200,6 @@ export const pushLog = (
|
|||||||
message,
|
message,
|
||||||
timestring,
|
timestring,
|
||||||
jsonData,
|
jsonData,
|
||||||
timestamp,
|
|
||||||
defaultCollapsed: true,
|
defaultCollapsed: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
12057
package-lock.json
generated
Normal file
12057
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -23,6 +23,7 @@
|
|||||||
"@radix-ui/react-tooltip": "^0.1.7",
|
"@radix-ui/react-tooltip": "^0.1.7",
|
||||||
"@stitches/react": "^1.2.6-0",
|
"@stitches/react": "^1.2.6-0",
|
||||||
"base64-js": "^1.5.1",
|
"base64-js": "^1.5.1",
|
||||||
|
"date-format-parse": "^0.2.7",
|
||||||
"dinero.js": "^1.9.1",
|
"dinero.js": "^1.9.1",
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
"filesize": "^8.0.7",
|
"filesize": "^8.0.7",
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ export interface IAccount {
|
|||||||
export interface ILog {
|
export interface ILog {
|
||||||
type: "error" | "warning" | "log" | "success";
|
type: "error" | "warning" | "log" | "success";
|
||||||
message: string;
|
message: string;
|
||||||
|
key?: string;
|
||||||
jsonData?: any,
|
jsonData?: any,
|
||||||
timestring?: string;
|
timestring?: string;
|
||||||
timestamp?: number;
|
|
||||||
link?: string;
|
link?: string;
|
||||||
linkText?: string;
|
linkText?: string;
|
||||||
defaultCollapsed?: boolean
|
defaultCollapsed?: boolean
|
||||||
|
|||||||
Reference in New Issue
Block a user