From 68ac5f594509be2b09aa931c445500e7683b516a Mon Sep 17 00:00:00 2001 From: Gabriel Date: Thu, 7 Dec 2023 16:39:05 -0300 Subject: [PATCH] [FEAT] adding high fee warning on paypro confirm view --- .../screens/send/confirm/PayProConfirm.tsx | 72 +++++++++++++++++-- 1 file changed, 65 insertions(+), 7 deletions(-) diff --git a/src/navigation/wallet/screens/send/confirm/PayProConfirm.tsx b/src/navigation/wallet/screens/send/confirm/PayProConfirm.tsx index 61362f53d..c7c786ca2 100644 --- a/src/navigation/wallet/screens/send/confirm/PayProConfirm.tsx +++ b/src/navigation/wallet/screens/send/confirm/PayProConfirm.tsx @@ -9,6 +9,7 @@ import { Recipient, TransactionProposal, TxDetails, + TxDetailsFee, Wallet, } from '../../../../../store/wallet/wallet.models'; import SwipeButton from '../../../../../components/swipe-button/SwipeButton'; @@ -25,6 +26,17 @@ import {sleep} from '../../../../../utils/helper-methods'; import {startOnGoingProcessModal} from '../../../../../store/app/app.effects'; import {dismissOnGoingProcessModal} from '../../../../../store/app/app.actions'; import {BuildPayProWalletSelectorList} from '../../../../../store/wallet/utils/wallet'; +import {GetFeeUnits} from '../../../../../store/wallet/utils/currency'; +import { + InfoDescription, + InfoHeader, + InfoTitle, +} from '../../../../../components/styled/Text'; +import { + Info, + InfoImageContainer, + InfoTriangle, +} from '../../../../../components/styled/Containers'; import { Amount, ConfirmContainer, @@ -42,7 +54,10 @@ import {AppActions} from '../../../../../store/app'; import {CustomErrorMessage} from '../../../components/ErrorMessages'; import {Analytics} from '../../../../../store/analytics/analytics.effects'; import {PayProOptions} from '../../../../../store/wallet/effects/paypro/paypro'; -import {GetFeeOptions} from '../../../../../store/wallet/effects/fee/fee'; +import { + GetFeeOptions, + getFeeRatePerKb, +} from '../../../../../store/wallet/effects/fee/fee'; import {WalletRowProps} from '../../../../../components/list/WalletRow'; import {Invoice} from '../../../../../store/shop/shop.models'; import {startGetRates} from '../../../../../store/wallet/effects'; @@ -52,6 +67,8 @@ import { } from '../../../../../api/coinbase/coinbase.types'; import {coinbasePayInvoice} from '../../../../../store/coinbase'; import {Memo} from './Memo'; +import {HIGH_FEE_LIMIT} from '../../../../../constants/wallet'; +import WarningSvg from '../../../../../../assets/img/warning.svg'; export interface PayProConfirmParamList { wallet?: Wallet; @@ -92,6 +109,9 @@ const PayProConfirm = () => { const {fee, sendingFrom, subTotal, total} = txDetails || {}; const [resetSwipeButton, setResetSwipeButton] = useState(false); const [disableSwipeSendButton, setDisableSwipeSendButton] = useState(false); + const [showHighFeeWarningMessage, setShowHighFeeWarningMessage] = + useState(false); + const payProHost = payProOptions.payProUrl .replace('https://', '') .split('/')[0]; @@ -136,6 +156,7 @@ const PayProConfirm = () => { setRecipient({address: newTxDetails.sendingTo.recipientAddress} as { address: string; }); + checkHighFees(selectedWallet, newTxp, fee); dispatch( Analytics.track('BitPay App - Start Merchant Purchase', { merchantBrand: invoice.merchantName, @@ -310,6 +331,20 @@ const PayProConfirm = () => { ); }; + const checkHighFees = async (wallet: Wallet, txp: any, fee: TxDetailsFee) => { + const {feeUnitAmount} = GetFeeUnits(wallet.chain); + let feePerKb: number; + if (txp.feePerKb) { + feePerKb = txp.feePerKb; + } else { + feePerKb = await getFeeRatePerKb({wallet, feeLevel: fee.feeLevel}); + } + setShowHighFeeWarningMessage( + feePerKb / feeUnitAmount >= HIGH_FEE_LIMIT[wallet.chain] && + txp.amount !== 0, + ); + }; + return ( { }} /> {wallet && fee ? ( - + <> + + {showHighFeeWarningMessage ? ( + <> + + + + + + + + + {t('Transaction fees are currently high')} + + + + {t( + 'Due to high demand, miner fees are high. Fees are paid to miners who process transactions and are not paid to BitPay.', + )} + + + + ) : null} + ) : null}