Skip to content

Commit

Permalink
move cta function
Browse files Browse the repository at this point in the history
  • Loading branch information
finnian0826 committed Jan 3, 2025
1 parent 85dc50a commit 9b9c466
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/components/GasFeeWarning.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ describe('GasFeeWarning', () => {
'renders error correctly when $scenario',
({ flow, prepareTransactionsResult, feeCurrencyTokenId, title, description, ctaLabel }) => {
const store = createMockStore()
const onPressCta = jest.fn()
const changeInputValueFn = jest.fn()
const { getByTestId, getByText } = render(
<Provider store={store}>
<GasFeeWarning
flow={flow}
testIdPrefix={'test'}
prepareTransactionsResult={prepareTransactionsResult}
onPressCta={ctaLabel ? onPressCta : undefined}
changeInputValueFn={changeInputValueFn}
/>
</Provider>
)
Expand All @@ -118,7 +118,7 @@ describe('GasFeeWarning', () => {
fireEvent.press(getByText(ctaLabel))
}
expect(ctaLabel ? getByText(ctaLabel) : true).toBeTruthy()
expect(onPressCta).toHaveBeenCalledTimes(ctaLabel ? 1 : 0)
expect(changeInputValueFn).toHaveBeenCalledTimes(ctaLabel ? 1 : 0)
}
)
})
19 changes: 17 additions & 2 deletions src/components/GasFeeWarning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { StyleSheet } from 'react-native'
import AppAnalytics from 'src/analytics/AppAnalytics'
import { AppEvents } from 'src/analytics/Events'
import InLineNotification, { NotificationVariant } from 'src/components/InLineNotification'
import { CICOFlow } from 'src/fiatExchanges/types'
import { navigate } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
import { Spacing } from 'src/styles/styles'
import { PreparedTransactionsResult } from 'src/viem/prepareTransactions'

Expand All @@ -12,12 +15,12 @@ export type GasFeeWarningFlow = 'Send' | 'Swap' | 'Withdraw' | 'Deposit' | 'Dapp
function GasFeeWarning({
prepareTransactionsResult,
flow,
onPressCta,
changeInputValueFn,
testIdPrefix,
}: {
prepareTransactionsResult?: PreparedTransactionsResult
flow: GasFeeWarningFlow
onPressCta?: () => void
changeInputValueFn?: (amount: string) => void
testIdPrefix?: string
}) {
const { t } = useTranslation()
Expand Down Expand Up @@ -63,6 +66,18 @@ function GasFeeWarning({
: prepareTransactionsResult.type === 'not-enough-balance-for-gas'
? t('gasFeeWarning.cta', { tokenSymbol: feeCurrency.symbol })
: t('gasFeeWarning.ctaGasToken', { context: flow })

const onPressCta = () => {
prepareTransactionsResult.type === 'not-enough-balance-for-gas'
? navigate(Screens.FiatExchangeAmount, {
tokenId: prepareTransactionsResult.feeCurrencies[0].tokenId,
flow: CICOFlow.CashIn,
tokenSymbol: prepareTransactionsResult.feeCurrencies[0].symbol,
})
: changeInputValueFn
? changeInputValueFn(prepareTransactionsResult.decreasedSpendAmount.toString())
: null
}
return (
<InLineNotification
variant={NotificationVariant.Warning}
Expand Down
20 changes: 1 addition & 19 deletions src/earn/EarnEnterAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import EarnDepositBottomSheet from 'src/earn/EarnDepositBottomSheet'
import { usePrepareEnterAmountTransactionsCallback } from 'src/earn/hooks'
import { depositStatusSelector } from 'src/earn/selectors'
import { getSwapToAmountInDecimals } from 'src/earn/utils'
import { CICOFlow } from 'src/fiatExchanges/types'
import ArrowRightThick from 'src/icons/ArrowRightThick'
import { navigate } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
Expand Down Expand Up @@ -404,24 +403,7 @@ export default function EarnEnterAmount({ route }: Props) {
<GasFeeWarning
prepareTransactionsResult={prepareTransactionsResult}
flow={'Deposit'}
onPressCta={() => {
AppAnalytics.track(EarnEvents.earn_deposit_add_gas_press, {
gasTokenId: feeCurrencies[0].tokenId,
depositTokenId: pool.dataProps.depositTokenId,
networkId: pool.networkId,
providerId: pool.appId,
poolId: pool.positionId,
})
if (prepareTransactionsResult && prepareTransactionsResult.type !== 'possible') {
prepareTransactionsResult.type === 'not-enough-balance-for-gas'
? navigate(Screens.FiatExchangeAmount, {
tokenId: prepareTransactionsResult.feeCurrencies[0].tokenId,
flow: CICOFlow.CashIn,
tokenSymbol: prepareTransactionsResult.feeCurrencies[0].symbol,
})
: handleAmountInputChange(prepareTransactionsResult.decreasedSpendAmount.toString())
}
}}
changeInputValueFn={handleAmountInputChange}
testIdPrefix={'EarnEnterAmount'}
/>
{showLowerAmountError && (
Expand Down

0 comments on commit 9b9c466

Please sign in to comment.