Skip to content

Commit 25d96d6

Browse files
committed
settings: Add the ability to see all toast notifications in current session
1 parent 485ea65 commit 25d96d6

5 files changed

Lines changed: 104 additions & 1 deletion

File tree

locales/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,10 @@
897897
"title": "Show startup info notifications",
898898
"subtitle": ""
899899
},
900+
"showNotifications": {
901+
"title": "Show notifications for this session",
902+
"subtitle": ""
903+
},
900904
"helpCencer": {
901905
"title": "LndMobile help center",
902906
"subtitle": ""

src/utils/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,17 @@ export const hexToUint8Array = (hexString: string) => {
7474
return new Uint8Array(hexString.match(/.{1,2}/g)!.map(byte => parseInt(byte, 16)));
7575
};
7676

77+
export const toastEntries: string[] = []
78+
79+
// TODO: maybe make array observable in order trigger re-render for hook
80+
export function useGetToastEntries(): string[] {
81+
return toastEntries;
82+
}
83+
7784
export const toast = (message: string, period = 8000, type: "danger" | "success" | "warning" = "success", button?: string) => {
85+
toastEntries.push(message);
86+
console.log(message);
7887
try {
79-
console.log(message);
8088
if (AppState.currentState === "active") {
8189
Toast.show({
8290
duration: period,

src/windows/Settings/Settings.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,12 @@ ${t("experimental.tor.disabled.msg2")}`;
15551555
<Body><Text>{t("debug.startup.title")}</Text></Body>
15561556
<Right><CheckBox checked={debugShowStartupInfo} onPress={onToggleDebugShowStartupInfo} /></Right>
15571557
</ListItem>
1558+
<ListItem style={style.listItem} button={true} icon={true} onPress={() => navigation.navigate("ToastLog")}>
1559+
<Left><Icon style={style.icon} type="MaterialCommunityIcons" name="format-list-bulleted" /></Left>
1560+
<Body>
1561+
<Text>{t("debug.showNotifications.title")}</Text>
1562+
</Body>
1563+
</ListItem>
15581564
<ListItem style={style.listItem} button={true} icon={true} onPress={onPressRescanWallet}>
15591565
<Left><Icon style={style.icon} type="MaterialCommunityIcons" name="restart" /></Left>
15601566
<Body>

src/windows/Settings/ToastLog.tsx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import React, { useLayoutEffect } from "react";
2+
import { FlatList, StyleSheet } from "react-native";
3+
import { Body, Card, CardItem, Icon, Row, Text } from "native-base";
4+
import { StackNavigationProp } from "@react-navigation/stack";
5+
import { RouteProp } from "@react-navigation/native";
6+
import Clipboard from "@react-native-community/clipboard";
7+
8+
import Container from "../../components/Container";
9+
import { NavigationButton } from "../../components/NavigationButton";
10+
import { SettingsStackParamList } from "./index";
11+
import { toast, useGetToastEntries } from "../../utils";
12+
import { fontFactorNormalized } from "../../utils/scale";
13+
14+
import { useTranslation } from "react-i18next";
15+
import { namespaces } from "../../i18n/i18n.constants";
16+
17+
18+
export interface ISelectListProps {
19+
navigation: StackNavigationProp<SettingsStackParamList, "LightningPeers">;
20+
route: RouteProp<SettingsStackParamList, "LightningPeers">;
21+
}
22+
23+
export default function({ navigation }: ISelectListProps) {
24+
const t = useTranslation(namespaces.settings.lightningPeers).t;
25+
const toastEntries = useGetToastEntries();
26+
27+
useLayoutEffect(() => {
28+
navigation.setOptions({
29+
headerTitle: t("layout.title"),
30+
headerShown: true,
31+
headerRight: () => {
32+
return (
33+
<NavigationButton onPress={onPressCopyAllToasts}>
34+
<Icon type="MaterialCommunityIcons" name="content-copy" style={{ fontSize: 22 }} />
35+
</NavigationButton>
36+
)
37+
}
38+
});
39+
}, [navigation]);
40+
41+
const onCopyToastMessage = (i: number) => {
42+
console.log(toastEntries);
43+
Clipboard.setString(toastEntries[i] ?? "");
44+
toast("Copied to clipboard");
45+
}
46+
47+
const onPressCopyAllToasts = () => {
48+
Clipboard.setString(toastEntries.join("\n") ?? "");
49+
toast("Copied to clipboard");
50+
}
51+
52+
return (
53+
<Container>
54+
<FlatList
55+
contentContainerStyle={{ padding: 14 }}
56+
initialNumToRender={20}
57+
data={toastEntries}
58+
renderItem={({ item: toast, index }) => (
59+
<Card style={style.card} key={index}>
60+
<CardItem>
61+
<Body>
62+
<Row style={{ width: "100%" }}>
63+
<Text style={{marginRight: 28 }}>{toast}</Text>
64+
<Text style={{ position:"absolute", right: 0 }}>
65+
<Icon type="MaterialCommunityIcons" name="content-copy" style={style.icon} onPress={() => onCopyToastMessage(index)} />
66+
</Text>
67+
</Row>
68+
</Body>
69+
</CardItem>
70+
</Card>
71+
)}
72+
keyExtractor={(toast, i) => toast + i}
73+
/>
74+
</Container>
75+
)
76+
}
77+
78+
const style = StyleSheet.create({
79+
icon: {
80+
fontSize: 18 * fontFactorNormalized,
81+
},
82+
});

src/windows/Settings/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import LightningPeers from "./LightningPeers";
1818
import ConnectToLightningPeer from "./ConnectToLightningPeer";
1919
import LndLog from "./LndLog";
2020
import DunderDoctor from "./DunderDoctor";
21+
import ToastLog from "./ToastLog";
2122

2223
const Stack = createStackNavigator();
2324

@@ -41,6 +42,7 @@ export type SettingsStackParamList = {
4142
ChannelProvider: ISelectListNavigationProps<string>;
4243
LndLog: undefined;
4344
DunderDoctor: undefined;
45+
ToastLog: undefined;
4446
}
4547

4648
export default function SettingsIndex() {
@@ -73,6 +75,7 @@ export default function SettingsIndex() {
7375
<Stack.Screen name="ChannelProvider" component={SelectList} />
7476
<Stack.Screen name="LndLog" component={LndLog} />
7577
<Stack.Screen name="DunderDoctor" component={DunderDoctor} />
78+
<Stack.Screen name="ToastLog" component={ToastLog} />
7679
</Stack.Navigator>
7780
);
7881
}

0 commit comments

Comments
 (0)