Skip to content

Commit 1f0b7e4

Browse files
committed
fix: add error handling durin CJIT flow
1 parent ff1cb6b commit 1f0b7e4

File tree

2 files changed

+66
-32
lines changed

2 files changed

+66
-32
lines changed

src/screens/Wallets/Receive/ReceiveAmount.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { updateInvoice } from '../../../store/slices/receive';
2323
import { receiveSelector } from '../../../store/reselect/receive';
2424
import { estimateOrderFee } from '../../../utils/blocktank';
2525
import { getNumberPadText } from '../../../utils/numberpad';
26+
import { showToast } from '../../../utils/notifications';
2627
import { blocktankInfoSelector } from '../../../store/reselect/blocktank';
2728
import { refreshBlocktankInfo } from '../../../store/utils/blocktank';
2829
import {
@@ -63,11 +64,17 @@ const ReceiveAmount = ({
6364
// add 10% buffer and round up to the nearest 1000 to avoid fee fluctuations
6465
const minimum = Math.ceil((feeResult.value * 1.1) / 1000) * 1000;
6566
setMinimumAmount(minimum);
67+
} else {
68+
showToast({
69+
type: 'error',
70+
title: t('receive_cjit_error'),
71+
description: feeResult.error.message,
72+
});
6673
}
6774
};
6875

6976
getFeeEstimation();
70-
}, [channelSize]);
77+
}, [t, channelSize]);
7178

7279
const onMinimum = (): void => {
7380
const result = getNumberPadText(minimumAmount, denomination, unit);
@@ -89,7 +96,9 @@ const ReceiveAmount = ({
8996
};
9097

9198
const continueDisabled =
92-
invoice.amount < minimumAmount || invoice.amount > channelSize;
99+
invoice.amount < minimumAmount ||
100+
invoice.amount > channelSize ||
101+
minimumAmount === 0;
93102

94103
return (
95104
<GradientView style={styles.container}>

src/screens/Wallets/Receive/ReceiveConnect.tsx

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { memo, ReactElement, useEffect, useState } from 'react';
2-
import { StyleSheet, View, Image } from 'react-native';
2+
import { StyleSheet, View, Image, ActivityIndicator } from 'react-native';
33
import { Trans, useTranslation } from 'react-i18next';
44

55
import { 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

Comments
 (0)