@@ -27,15 +27,12 @@ const Channel = ({
2727} : {
2828 channel : TChannel ;
2929 isEnabled : boolean ;
30- onPress : ( channel : TChannel ) => void ;
30+ onPress : ( ) => void ;
3131} ) : ReactElement => {
3232 const channelName = useLightningChannelName ( channel ) ;
3333
3434 return (
35- < SwitchRow
36- style = { styles . channel }
37- isEnabled = { isEnabled }
38- onPress = { ( ) => onPress ( channel ) } >
35+ < SwitchRow style = { styles . channel } isEnabled = { isEnabled } onPress = { onPress } >
3936 < Caption13Up style = { styles . channelLabel } color = "secondary" >
4037 { channelName }
4138 </ Caption13Up >
@@ -50,27 +47,34 @@ const SavingsAdvanced = ({
5047 const switchUnit = useSwitchUnit ( ) ;
5148 const { t } = useTranslation ( 'lightning' ) ;
5249 const channels = useAppSelector ( openChannelsSelector ) ;
53- const [ selected , setSelected ] = useState < TChannel [ ] > ( channels ) ;
50+ const channelIds = channels . map ( ( channel ) => channel . channel_id ) ;
51+ const [ selected , setSelected ] = useState < string [ ] > ( channelIds ) ;
5452
55- const onToggle = ( channel : TChannel ) : void => {
53+ const selectedChannels = channels . filter ( ( channel ) => {
54+ return selected . includes ( channel . channel_id ) ;
55+ } ) ;
56+
57+ const onToggle = ( channelId : string ) : void => {
5658 setSelected ( ( prev ) => {
57- return prev . includes ( channel )
58- ? prev . filter ( ( c ) => c !== channel )
59- : [ ...prev , channel ] ;
59+ if ( prev . includes ( channelId ) ) {
60+ return prev . filter ( ( id ) => id !== channelId ) ;
61+ } else {
62+ return [ ...prev , channelId ] ;
63+ }
6064 } ) ;
6165 } ;
6266
6367 const onContinue = ( ) : void => {
6468 if ( selected . length === channels . length ) {
6569 navigation . navigate ( 'SavingsConfirm' ) ;
6670 } else {
67- navigation . navigate ( 'SavingsConfirm' , { channels : selected } ) ;
71+ navigation . navigate ( 'SavingsConfirm' , { channels : selectedChannels } ) ;
6872 }
6973 } ;
7074
71- const amount = channels
72- . filter ( ( channel ) => selected . includes ( channel ) )
73- . reduce ( ( acc , channel ) => acc + channel . balance_sat , 0 ) ;
75+ const amount = selectedChannels . reduce ( ( acc , channel ) => {
76+ return acc + channel . balance_sat ;
77+ } , 0 ) ;
7478
7579 return (
7680 < ThemedView style = { styles . root } >
@@ -97,8 +101,8 @@ const SavingsAdvanced = ({
97101 < Channel
98102 key = { channel . channel_id }
99103 channel = { channel }
100- isEnabled = { selected . includes ( channel ) }
101- onPress = { onToggle }
104+ isEnabled = { selected . includes ( channel . channel_id ) }
105+ onPress = { ( ) : void => onToggle ( channel . channel_id ) }
102106 />
103107 ) ) }
104108 </ ScrollView >
0 commit comments