@@ -49,9 +49,8 @@ export default function SyncInfo({}: ISyncInfoProps) {
49
49
const recoverInfo = useStoreState ( ( store ) => store . lightning . recoverInfo ) ;
50
50
const initialKnownBlockheight = useStoreState ( ( store ) => store . lightning . initialKnownBlockheight ) ;
51
51
let bestBlockheight = useStoreState ( ( store ) => store . lightning . bestBlockheight ) ;
52
- const log = useRef ( "" ) ;
53
- const forceUpdate = useForceUpdate ( ) ;
54
52
const [ showLndLog , setShowLndLog ] = useState ( false ) ;
53
+ const [ logs , setLogs ] = useState ( "" ) ;
55
54
const listener = useRef < EmitterSubscription > ( ) ;
56
55
57
56
useEffect ( ( ) => {
@@ -62,23 +61,21 @@ export default function SyncInfo({}: ISyncInfoProps) {
62
61
} ;
63
62
} , [ ] ) ;
64
63
65
- const onPressShowLndLog = async ( ) => {
66
- const tailLog = await NativeModules . LndMobileTools . tailLog ( 100 ) ;
67
- log . current = tailLog
68
- . split ( "\n" )
69
- . map ( ( row ) => row . slice ( 11 ) )
70
- . join ( "\n" ) ;
71
-
72
- listener . current = LndMobileToolsEventEmitter . addListener ( "lndlog" , function ( data : string ) {
73
- log . current = log . current + "\n" + data . slice ( 11 ) ;
74
- forceUpdate ( ) ;
75
- } ) ;
76
-
77
- NativeModules . LndMobileTools . observeLndLogFile ( ) ;
78
- forceUpdate ( ) ;
79
- setShowLndLog ( true ) ;
64
+ const fetchLogs = async ( ) => {
65
+ try {
66
+ const tailLog = await NativeModules . LndMobileTools . tailLog ( 100 ) ;
67
+ setLogs ( tailLog ) ;
68
+ } catch ( error ) {
69
+ console . error ( "Error fetching logs:" , error ) ;
70
+ }
80
71
} ;
81
72
73
+ useEffect ( ( ) => {
74
+ fetchLogs ( ) ;
75
+ const logUpdateTimer = setInterval ( fetchLogs , 1000 ) ;
76
+ return ( ) => clearInterval ( logUpdateTimer ) ;
77
+ } , [ ] ) ;
78
+
82
79
const onPressCopy = ( l : string ) => {
83
80
Clipboard . setString ( l ) ;
84
81
toast ( t ( "msg.clipboardCopy" , { ns : namespaces . common } ) , undefined , "warning" ) ;
@@ -172,16 +169,16 @@ export default function SyncInfo({}: ISyncInfoProps) {
172
169
) }
173
170
{ ! showLndLog && (
174
171
< View style = { { marginTop : 10 , flexDirection : "row" } } >
175
- < Button small onPress = { onPressShowLndLog } >
172
+ < Button small onPress = { ( ) => setShowLndLog ( true ) } >
176
173
< Text > { t ( "lndLog.show" ) } </ Text >
177
174
</ Button >
178
175
</ View >
179
176
) }
180
177
{ showLndLog && (
181
178
< View style = { { marginTop : 10 } } >
182
- < LogBox text = { log . current } style = { { maxHeight : 170 } } />
179
+ < LogBox text = { logs } style = { { maxHeight : 170 } } />
183
180
< View style = { { marginTop : 10 , flexDirection : "row" } } >
184
- < Button small onPress = { ( ) => onPressCopy ( log . current ) } >
181
+ < Button small onPress = { ( ) => onPressCopy ( logs ) } >
185
182
< Text > { t ( "lndLog.copy" ) } </ Text >
186
183
</ Button >
187
184
</ View >
0 commit comments