diff --git a/src/screens/Transfer/SavingsAdvanced.tsx b/src/screens/Transfer/SavingsAdvanced.tsx index d4c709502..840668dd3 100644 --- a/src/screens/Transfer/SavingsAdvanced.tsx +++ b/src/screens/Transfer/SavingsAdvanced.tsx @@ -27,15 +27,12 @@ const Channel = ({ }: { channel: TChannel; isEnabled: boolean; - onPress: (channel: TChannel) => void; + onPress: () => void; }): ReactElement => { const channelName = useLightningChannelName(channel); return ( - onPress(channel)}> + {channelName} @@ -49,27 +46,33 @@ const SavingsAdvanced = ({ }: TransferScreenProps<'SavingsAdvanced'>): ReactElement => { const switchUnit = useSwitchUnit(); const { t } = useTranslation('lightning'); - const channels = useAppSelector(openChannelsSelector); - const [selected, setSelected] = useState(channels); + const openChannels = useAppSelector(openChannelsSelector); + const channelIds = openChannels.map((channel) => channel.channel_id); + const [selected, setSelected] = useState(channelIds); - const onToggle = (channel: TChannel): void => { + const onToggle = (channelId: string): void => { setSelected((prev) => { - return prev.includes(channel) - ? prev.filter((c) => c !== channel) - : [...prev, channel]; + if (prev.includes(channelId)) { + return prev.filter((id) => id !== channelId); + } else { + return [...prev, channelId]; + } }); }; const onContinue = (): void => { - if (selected.length === channels.length) { + if (selected.length === openChannels.length) { navigation.navigate('SavingsConfirm'); } else { - navigation.navigate('SavingsConfirm', { channels: selected }); + const channels = openChannels.filter((channel) => { + return selected.includes(channel.channel_id); + }); + navigation.navigate('SavingsConfirm', { channels }); } }; - const amount = channels - .filter((channel) => selected.includes(channel)) + const amount = openChannels + .filter((channel) => selected.includes(channel.channel_id)) .reduce((acc, channel) => acc + channel.balance_sat, 0); return ( @@ -93,12 +96,12 @@ const SavingsAdvanced = ({ - {Object.values(channels).map((channel) => ( + {Object.values(openChannels).map((channel) => ( onToggle(channel.channel_id)} /> ))}