11import React , { memo , ReactElement , useEffect , useState } from 'react' ;
2- import { StyleSheet , View , Image } from 'react-native' ;
2+ import { StyleSheet , View , Image , ActivityIndicator } from 'react-native' ;
33import { Trans , useTranslation } from 'react-i18next' ;
44
55import { Caption13Up , BodyMB , BodyM } from '../../../styles/text' ;
@@ -33,6 +33,7 @@ const ReceiveConnect = ({
3333 const lightningBalance = useLightningBalance ( true ) ;
3434 const [ feeEstimate , setFeeEstimate ] = useState ( 0 ) ;
3535 const [ isLoading , setIsLoading ] = useState ( false ) ;
36+ const [ isLoadingFee , setIsLoadingFee ] = useState ( false ) ;
3637 const dispatch = useAppDispatch ( ) ;
3738 const blocktank = useAppSelector ( blocktankInfoSelector ) ;
3839 const { amount, message } = useAppSelector ( receiveSelector ) ;
@@ -47,14 +48,22 @@ const ReceiveConnect = ({
4748
4849 useEffect ( ( ) => {
4950 const getFeeEstimation = async ( ) : Promise < void > => {
51+ setIsLoadingFee ( true ) ;
5052 const estimate = await estimateOrderFee ( { lspBalance } ) ;
5153 if ( estimate . isOk ( ) ) {
5254 setFeeEstimate ( estimate . value ) ;
55+ } else {
56+ showToast ( {
57+ type : 'error' ,
58+ title : t ( 'receive_cjit_error' ) ,
59+ description : estimate . error . message ,
60+ } ) ;
5361 }
62+ setIsLoadingFee ( false ) ;
5463 } ;
5564
5665 getFeeEstimation ( ) ;
57- } , [ lspBalance ] ) ;
66+ } , [ t , lspBalance ] ) ;
5867
5968 const onMore = ( ) : void => {
6069 navigation . navigate ( 'Liquidity' , {
@@ -95,34 +104,44 @@ const ReceiveConnect = ({
95104 < View style = { styles . content } >
96105 < AmountToggle amount = { amount } />
97106
98- < BodyM style = { styles . text } color = "secondary" >
99- < Trans
100- t = { t }
101- i18nKey = {
102- isInitial
103- ? 'receive_connect_initial'
104- : 'receive_connect_additional'
105- }
106- components = { { accent : < BodyMB color = "white" /> } }
107- values = { { lspFee : `${ fiatSymbol } ${ displayFee . fiatFormatted } ` } }
108- />
109- </ BodyM >
110-
111- < View style = { styles . payAmount } >
112- < Caption13Up style = { styles . payAmountText } color = "secondary" >
113- { t ( 'receive_will' ) }
114- </ Caption13Up >
115- < Money
116- sats = { payAmount }
117- size = "title"
118- symbol = { true }
119- testID = "AvailableAmount"
120- />
121- </ View >
122-
123- < View style = { styles . imageContainer } >
124- < Image style = { styles . image } source = { imageSrc } />
125- </ View >
107+ { feeEstimate > 0 && (
108+ < >
109+ < BodyM style = { styles . text } color = "secondary" >
110+ < Trans
111+ t = { t }
112+ i18nKey = {
113+ isInitial
114+ ? 'receive_connect_initial'
115+ : 'receive_connect_additional'
116+ }
117+ components = { { accent : < BodyMB color = "white" /> } }
118+ values = { { lspFee : `${ fiatSymbol } ${ displayFee . fiatFormatted } ` } }
119+ />
120+ </ BodyM >
121+
122+ < View style = { styles . payAmount } >
123+ < Caption13Up style = { styles . payAmountText } color = "secondary" >
124+ { t ( 'receive_will' ) }
125+ </ Caption13Up >
126+ < Money
127+ sats = { payAmount }
128+ size = "title"
129+ symbol = { true }
130+ testID = "AvailableAmount"
131+ />
132+ </ View >
133+
134+ < View style = { styles . imageContainer } >
135+ < Image style = { styles . image } source = { imageSrc } />
136+ </ View >
137+ </ >
138+ ) }
139+
140+ { isLoadingFee && (
141+ < View style = { styles . indicator } >
142+ < ActivityIndicator color = "white" size = "large" />
143+ </ View >
144+ ) }
126145
127146 < View style = { styles . buttonContainer } >
128147 < Button
@@ -132,6 +151,7 @@ const ReceiveConnect = ({
132151 variant = "secondary"
133152 testID = "ReceiveConnectMore"
134153 onPress = { onMore }
154+ disabled = { feeEstimate === 0 }
135155 />
136156 < Button
137157 style = { styles . button }
@@ -140,6 +160,7 @@ const ReceiveConnect = ({
140160 loading = { isLoading }
141161 testID = "ReceiveConnectContinue"
142162 onPress = { onContinue }
163+ disabled = { feeEstimate === 0 }
143164 />
144165 </ View >
145166 </ View >
@@ -177,6 +198,10 @@ const styles = StyleSheet.create({
177198 flex : 1 ,
178199 resizeMode : 'contain' ,
179200 } ,
201+ indicator : {
202+ marginTop : 'auto' ,
203+ marginBottom : 'auto' ,
204+ } ,
180205 buttonContainer : {
181206 flexDirection : 'row' ,
182207 justifyContent : 'center' ,
0 commit comments