Skip to content

Commit

Permalink
tailing fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Nitesh Balusu <[email protected]>
  • Loading branch information
niteshbalusu11 committed Sep 4, 2024
1 parent e36cac7 commit ab48802
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/windows/Settings/LndLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,31 @@ import { NativeModules } from "react-native";
import { StackNavigationProp } from "@react-navigation/stack";
import { Icon } from "native-base";
import Clipboard from "@react-native-clipboard/clipboard";

import { SettingsStackParamList } from "./index";
import Container from "../../components/Container";
import { NavigationButton } from "../../components/NavigationButton";
import { toast } from "../../utils";
import LogBox from "../../components/LogBox";

import { useTranslation } from "react-i18next";
import { namespaces } from "../../i18n/i18n.constants";

export interface ILndLogProps {
navigation: StackNavigationProp<SettingsStackParamList, "LndLog">;
}

export default function LndLog({ navigation }: ILndLogProps) {
const t = useTranslation(namespaces.settings.lndLog).t;
const [logs, setLogs] = useState("");
const lastLogRef = useRef("");

const fetchLogs = async () => {
try {
const tailLog = await NativeModules.LndMobileTools.tailLog(100);
setLogs(tailLog);
setLogs((prevLogs) => {
const newLogs = tailLog.replace(lastLogRef.current, "").trim();
lastLogRef.current = tailLog;
return prevLogs + (prevLogs ? "\n" : "") + newLogs;
});
} catch (error) {
console.error("Error fetching logs:", error);
}
Expand Down
9 changes: 7 additions & 2 deletions src/windows/SyncInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useRef, useState } from "react";
import { EmitterSubscription, NativeModules, StyleSheet, View, ScrollView } from "react-native";
import { NativeModules, StyleSheet, View, ScrollView } from "react-native";
import { Card, Text, CardItem, H1, Button } from "native-base";
import Clipboard from "@react-native-clipboard/clipboard";
import Bar from "../components/ProgressBar";
Expand Down Expand Up @@ -49,11 +49,16 @@ export default function SyncInfo({}: ISyncInfoProps) {
let bestBlockheight = useStoreState((store) => store.lightning.bestBlockheight);
const [showLndLog, setShowLndLog] = useState(false);
const [logs, setLogs] = useState("");
const lastLogRef = useRef("");

const fetchLogs = async () => {
try {
const tailLog = await NativeModules.LndMobileTools.tailLog(100);
setLogs(tailLog);
setLogs((prevLogs) => {
const newLogs = tailLog.replace(lastLogRef.current, "").trim();
lastLogRef.current = tailLog;
return prevLogs + (prevLogs ? "\n" : "") + newLogs;
});
} catch (error) {
console.error("Error fetching logs:", error);
}
Expand Down

0 comments on commit ab48802

Please sign in to comment.