FIX: disable create button if total exceeds balance.

This commit is contained in:
Marcos Rodriguez Velez 2024-06-07 16:11:57 -04:00
parent 34fc84cbdc
commit 7b3a6e2e13
No known key found for this signature in database
GPG key ID: 6030B2F48CCE86D7
2 changed files with 11 additions and 2 deletions

View file

@ -1161,6 +1161,12 @@ const SendDetails = () => {
}, },
}); });
const calculateTotalAmount = () => {
const totalAmount = addresses.reduce((total, item) => total + Number(item.amountSats || 0), 0);
const totalWithFee = totalAmount + (feePrecalc.current || 0);
return totalWithFee;
};
const renderFeeSelectionModal = () => { const renderFeeSelectionModal = () => {
const nf = networkTransactionFees; const nf = networkTransactionFees;
const options = [ const options = [
@ -1320,12 +1326,15 @@ const SendDetails = () => {
}; };
const renderCreateButton = () => { const renderCreateButton = () => {
const totalWithFee = calculateTotalAmount();
const isDisabled = totalWithFee === 0 || totalWithFee > balance || balance === 0 || isLoading || addresses.length === 0;
return ( return (
<View style={styles.createButton}> <View style={styles.createButton}>
{isLoading ? ( {isLoading ? (
<ActivityIndicator /> <ActivityIndicator />
) : ( ) : (
<Button onPress={createTransaction} title={loc.send.details_next} testID="CreateTransactionButton" /> <Button onPress={createTransaction} disabled={isDisabled} title={loc.send.details_next} testID="CreateTransactionButton" />
)} )}
</View> </View>
); );

View file

@ -666,7 +666,7 @@ const styles = StyleSheet.create({
}, },
listHeaderTextRow: { listHeaderTextRow: {
flex: 1, flex: 1,
marginHorizontal: 16, margin: 16,
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'space-between', justifyContent: 'space-between',
}, },