From e1218a094aeaa9195a8fe04a7ae43fd478682f7a Mon Sep 17 00:00:00 2001 From: Gonzalo Nardini Date: Thu, 15 Oct 2020 17:19:24 -0300 Subject: [PATCH 01/10] Add fee estimation for withdrawals --- .../mobile/src/components/CeloAmountInput.tsx | 6 +++- .../src/exchange/WithdrawCeloReviewScreen.tsx | 8 +++-- .../src/exchange/WithdrawCeloScreen.tsx | 29 ++++++++++++++++++- .../src/exchange/WithdrawCeloSummary.tsx | 8 ++--- .../ExchangeReview.test.tsx.snap | 20 ++++++++++++- .../WithdrawCeloReviewScreen.test.tsx.snap | 29 ------------------- .../WithdrawCeloSummary.test.tsx.snap | 29 ------------------- packages/mobile/src/fees/CalculateFee.tsx | 15 ++++++++-- packages/mobile/src/navigator/types.tsx | 1 + packages/mobile/src/send/saga.ts | 7 +++-- 10 files changed, 80 insertions(+), 72 deletions(-) diff --git a/packages/mobile/src/components/CeloAmountInput.tsx b/packages/mobile/src/components/CeloAmountInput.tsx index 597ced81e5f..721cf40f690 100644 --- a/packages/mobile/src/components/CeloAmountInput.tsx +++ b/packages/mobile/src/components/CeloAmountInput.tsx @@ -1,6 +1,7 @@ import TextInputWithButtons from '@celo/react-components/components/TextInputWithButtons' import colors from '@celo/react-components/styles/colors' import fontStyles from '@celo/react-components/styles/fonts' +import BigNumber from 'bignumber.js' import React from 'react' import { useTranslation } from 'react-i18next' import { StyleSheet, Text, TextInputProps, TouchableOpacity, ViewStyle } from 'react-native' @@ -14,6 +15,7 @@ interface Props { celo: string onCeloChanged: (address: string) => void color?: string + feeEstimate: BigNumber } export default function CeloAmountInput({ @@ -22,13 +24,15 @@ export default function CeloAmountInput({ celo, onCeloChanged, color = colors.goldUI, + feeEstimate, }: Props) { const { t } = useTranslation(Namespaces.exchangeFlow9) const goldBalance = useSelector((state: RootState) => state.goldToken.balance) const setMaxAmount = () => { if (goldBalance) { - onCeloChanged(goldBalance) + const maxValue = new BigNumber(goldBalance).minus(feeEstimate).toString() + onCeloChanged(maxValue) } } diff --git a/packages/mobile/src/exchange/WithdrawCeloReviewScreen.tsx b/packages/mobile/src/exchange/WithdrawCeloReviewScreen.tsx index 270d3a8d4fc..010cad5c09e 100644 --- a/packages/mobile/src/exchange/WithdrawCeloReviewScreen.tsx +++ b/packages/mobile/src/exchange/WithdrawCeloReviewScreen.tsx @@ -31,7 +31,7 @@ import DisconnectBanner from 'src/shared/DisconnectBanner' type Props = StackScreenProps function WithdrawCeloReviewScreen({ route }: Props) { - const { amount, recipientAddress } = route.params + const { amount, recipientAddress, feeEstimate } = route.params const { t } = useTranslation(Namespaces.exchangeFlow9) // loading is never set to false, when the withdrawal is complete or after a short while, // withdrawCelo saga will navigate to |ExchangeHomeScreen|. @@ -56,7 +56,11 @@ function WithdrawCeloReviewScreen({ route }: Props) { amount={} /> - +