Skip to content

Commit 08f780c

Browse files
authored
Merge pull request #401 from getAlby/fix/connection-info-relay-online-status
fix: relay online status in connection info modal
2 parents 6146559 + 4a5da6f commit 08f780c

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

components/ConnectionInfoModal.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,33 @@ type ConnectionInfoModalProps = {
1818
};
1919

2020
function ConnectionInfoModal({ visible, onClose }: ConnectionInfoModalProps) {
21+
const { shadow } = useThemeColor("shadow");
2122
const selectedWalletId = useAppStore((store) => store.selectedWalletId);
2223
const wallets = useAppStore((store) => store.wallets);
2324
const capabilities = wallets[selectedWalletId].nwcCapabilities;
2425
const nwcClient = useAppStore((store) => store.nwcClient);
25-
const { shadow } = useThemeColor("shadow");
26+
const [relayStatuses, setRelayStatuses] = React.useState<boolean[]>([]);
27+
React.useEffect(() => {
28+
if (!nwcClient) {
29+
return;
30+
}
31+
(async () => {
32+
const _relayStatuses = [];
33+
for (const relayUrl of nwcClient.relayUrls) {
34+
try {
35+
await nwcClient.pool.ensureRelay(relayUrl, {
36+
connectionTimeout: 2000,
37+
});
38+
_relayStatuses.push(true);
39+
} catch (error) {
40+
console.error("Failed to connect to relay", { relayUrl, error });
41+
_relayStatuses.push(false);
42+
}
43+
}
44+
setRelayStatuses(_relayStatuses);
45+
})();
46+
}, [nwcClient]);
47+
2648
return (
2749
<Modal
2850
transparent
@@ -82,7 +104,7 @@ function ConnectionInfoModal({ visible, onClose }: ConnectionInfoModalProps) {
82104
>
83105
<View className="flex gap-2">
84106
<Text className="font-semibold2">Relays</Text>
85-
{nwcClient?.relayUrls.map((relayUrl) => (
107+
{nwcClient?.relayUrls.map((relayUrl, index) => (
86108
<View
87109
className="flex flex-row items-center gap-2"
88110
key={relayUrl}
@@ -91,9 +113,7 @@ function ConnectionInfoModal({ visible, onClose }: ConnectionInfoModalProps) {
91113
<View
92114
className={cn(
93115
"rounded-full w-2 h-2",
94-
nwcClient.pool.listConnectionStatus().get(relayUrl)
95-
? "bg-receive"
96-
: "bg-destructive",
116+
relayStatuses[index] ? "bg-receive" : "bg-destructive",
97117
)}
98118
></View>
99119
</View>

0 commit comments

Comments
 (0)