-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Embedded Node: add ability to to view LND logs
- Loading branch information
Showing
6 changed files
with
178 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useRef, useState } from 'react'; | ||
import { NativeScrollEvent, ScrollView, Text, ViewStyle } from 'react-native'; | ||
import { themeColor } from '../utils/ThemeUtils'; | ||
|
||
interface ILndLogBoxProps { | ||
text: string; | ||
style?: ViewStyle; | ||
scrollLock?: boolean; | ||
} | ||
export default function LogBox(props: ILndLogBoxProps) { | ||
const logScrollView = useRef<ScrollView>(null); | ||
const [scrollViewAtTheEnd, setScrollViewAtTheEnd] = useState(true); | ||
|
||
const isCloseToBottom = ({ | ||
layoutMeasurement, | ||
contentOffset, | ||
contentSize | ||
}: NativeScrollEvent) => { | ||
if (!props.scrollLock) { | ||
return true; | ||
} | ||
const paddingToBottom = 170; | ||
return ( | ||
layoutMeasurement.height + contentOffset.y >= | ||
contentSize.height - paddingToBottom | ||
); | ||
}; | ||
|
||
return ( | ||
<ScrollView | ||
style={props.style} | ||
ref={logScrollView} | ||
contentContainerStyle={{ padding: 8 }} | ||
onContentSizeChange={() => { | ||
if (scrollViewAtTheEnd) { | ||
logScrollView.current?.scrollToEnd(); | ||
} | ||
}} | ||
onScroll={({ nativeEvent }) => { | ||
setScrollViewAtTheEnd(isCloseToBottom(nativeEvent)); | ||
}} | ||
scrollEventThrottle={450} | ||
removeClippedSubviews={true} | ||
> | ||
<Text | ||
selectable={true} | ||
style={{ fontSize: 13, color: themeColor('text') }} | ||
> | ||
{props.text} | ||
</Text> | ||
</ScrollView> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import * as React from 'react'; | ||
import { NativeModules, View } from 'react-native'; | ||
import { inject, observer } from 'mobx-react'; | ||
|
||
import CopyButton from '../../../components/CopyButton'; | ||
import Screen from '../../../components/Screen'; | ||
import Header from '../../../components/Header'; | ||
import LogBox from '../../../components/LogBox'; | ||
|
||
import SettingsStore from '../../../stores/SettingsStore'; | ||
|
||
import { localeString } from '../../../utils/LocaleUtils'; | ||
import { themeColor } from '../../../utils/ThemeUtils'; | ||
import { LndMobileToolsEventEmitter } from '../../../utils/EventListenerUtils'; | ||
|
||
interface LNDLogsProps { | ||
navigation: any; | ||
SettingsStore: SettingsStore; | ||
} | ||
|
||
interface LNDLogsState { | ||
log: string; | ||
} | ||
|
||
@inject('SettingsStore') | ||
@observer | ||
export default class LNDLogs extends React.Component< | ||
LNDLogsProps, | ||
LNDLogsState | ||
> { | ||
state = { | ||
log: '' | ||
}; | ||
|
||
UNSAFE_componentWillMount(): void { | ||
const { SettingsStore } = this.props; | ||
const { embeddedLndNetwork } = SettingsStore; | ||
(async () => { | ||
const network = | ||
embeddedLndNetwork === 'Testnet' ? 'testnet' : 'mainnet'; | ||
const tailLog = await NativeModules.LndMobileTools.tailLog( | ||
100, | ||
network | ||
); | ||
let log = tailLog | ||
.split('\n') | ||
.map((row) => row.slice(11)) | ||
.join('\n'); | ||
|
||
LndMobileToolsEventEmitter.addListener('lndlog', (data: string) => { | ||
log = log + data.slice(11); | ||
this.setState({ | ||
log | ||
}); | ||
}); | ||
|
||
NativeModules.LndMobileTools.observeLndLogFile(network); | ||
this.setState({ | ||
log | ||
}); | ||
})(); | ||
} | ||
|
||
render() { | ||
const { navigation } = this.props; | ||
const { log } = this.state; | ||
|
||
return ( | ||
<Screen> | ||
<View style={{ flex: 1 }}> | ||
<Header | ||
leftComponent="Back" | ||
centerComponent={{ | ||
text: localeString( | ||
'views.Settings.EmbeddedNode.LNDLogs.title' | ||
), | ||
style: { | ||
color: themeColor('text'), | ||
fontFamily: 'Lato-Regular' | ||
} | ||
}} | ||
navigation={navigation} | ||
/> | ||
<LogBox text={log} scrollLock={false} /> | ||
<CopyButton | ||
title={localeString( | ||
'views.Settings.EmbeddedNode.LNDLogs.copyLogs' | ||
)} | ||
copyValue={log} | ||
/> | ||
</View> | ||
</Screen> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters