diff --git a/app/components/UI/Bridge/Views/BridgeView/index.tsx b/app/components/UI/Bridge/Views/BridgeView/index.tsx index 5db33c83da9..17eba7f81ec 100644 --- a/app/components/UI/Bridge/Views/BridgeView/index.tsx +++ b/app/components/UI/Bridge/Views/BridgeView/index.tsx @@ -228,7 +228,7 @@ const BridgeView = () => { ]); const isSubmitDisabled = - isLoading || + (isLoading && !activeQuote) || hasInsufficientBalance || isSubmittingTx || (isHardwareAddress && isSolanaSourced) || diff --git a/app/components/UI/Card/components/CardButton/CardButton.test.tsx b/app/components/UI/Card/components/CardButton/CardButton.test.tsx index ad0fba01664..22fb7ebc377 100644 --- a/app/components/UI/Card/components/CardButton/CardButton.test.tsx +++ b/app/components/UI/Card/components/CardButton/CardButton.test.tsx @@ -4,6 +4,7 @@ import CardButton from './CardButton'; import { renderScreen } from '../../../../../util/test/renderWithProvider'; import { backgroundState } from '../../../../../util/test/initial-root-state'; import { WalletViewSelectorsIDs } from '../../../../../../e2e/selectors/wallet/WalletView.selectors'; + jest.mock('../../../../hooks/useMetrics', () => { const actual = jest.requireActual('../../../../hooks/useMetrics'); return { @@ -19,14 +20,7 @@ jest.mock('../../../../hooks/useMetrics', () => { }; }); -interface PartialCardState { - hasViewedCardButton?: boolean; -} - -function renderWithProvider( - component: React.ComponentType, - stateOverride: PartialCardState = {}, -) { +function renderWithProvider(component: React.ComponentType) { return renderScreen( component, { name: 'CardButton' }, @@ -39,7 +33,6 @@ function renderWithProvider( lastFetchedByAddress: {}, hasViewedCardButton: false, isLoaded: false, - ...stateOverride, }, }, }, @@ -53,7 +46,7 @@ describe('CardButton Component', () => { jest.clearAllMocks(); }); - it('renders with badge (not yet viewed) and matches snapshot', () => { + it('renders and matches snapshot', () => { const { toJSON, getByTestId } = renderWithProvider(() => ( { /> )); - expect(getByTestId(WalletViewSelectorsIDs.CARD_BUTTON_BADGE)).toBeTruthy(); + expect(getByTestId(WalletViewSelectorsIDs.CARD_BUTTON)).toBeTruthy(); expect(toJSON()).toMatchSnapshot(); }); - it('dispatches setHasViewedCardButton(true) and hides badge on first press', () => { - const { getByTestId, store, queryByTestId } = renderWithProvider(() => ( + it('calls onPress when button is pressed', () => { + const { getByTestId } = renderWithProvider(() => ( { fireEvent.press(button); expect(mockOnPress).toHaveBeenCalledTimes(1); - expect(store.getState().card.hasViewedCardButton).toBe(true); - expect(queryByTestId(WalletViewSelectorsIDs.CARD_BUTTON_BADGE)).toBeNull(); - }); - - it('does not dispatch setHasViewedCardButton again if already viewed', () => { - const { getByTestId, store } = renderWithProvider( - () => ( - - ), - { hasViewedCardButton: true }, - ); - - const button = getByTestId(WalletViewSelectorsIDs.CARD_BUTTON); - fireEvent.press(button); - - expect(mockOnPress).toHaveBeenCalledTimes(1); - expect(store.getState().card.hasViewedCardButton).toBe(true); - }); - - it('renders without badge when already viewed', () => { - const { toJSON, queryByTestId } = renderWithProvider( - () => ( - - ), - { hasViewedCardButton: true }, - ); - - expect(queryByTestId(WalletViewSelectorsIDs.CARD_BUTTON_BADGE)).toBeNull(); - expect(toJSON()).toMatchSnapshot(); }); }); diff --git a/app/components/UI/Card/components/CardButton/CardButton.tsx b/app/components/UI/Card/components/CardButton/CardButton.tsx index ce9039a6cdb..11a2d179a3a 100644 --- a/app/components/UI/Card/components/CardButton/CardButton.tsx +++ b/app/components/UI/Card/components/CardButton/CardButton.tsx @@ -1,9 +1,4 @@ import { - BadgeStatus, - BadgeStatusStatus, - BadgeWrapper, - BadgeWrapperPosition, - BadgeWrapperPositionAnchorShape, ButtonIcon, ButtonIconSize, IconName, @@ -13,11 +8,6 @@ import { import React, { useEffect } from 'react'; import { WalletViewSelectorsIDs } from '../../../../../../e2e/selectors/wallet/WalletView.selectors'; import { MetaMetricsEvents, useMetrics } from '../../../../hooks/useMetrics'; -import { useDispatch, useSelector } from 'react-redux'; -import { - selectHasViewedCardButton, - setHasViewedCardButton, -} from '../../../../../core/redux/slices/card'; interface CardButtonProps { onPress: () => void; @@ -30,8 +20,6 @@ interface CardButtonProps { } const CardButton: React.FC = ({ onPress, touchAreaSlop }) => { - const dispatch = useDispatch(); - const hasViewedCardButton = useSelector(selectHasViewedCardButton); const { trackEvent, createEventBuilder } = useMetrics(); useEffect(() => { @@ -40,35 +28,15 @@ const CardButton: React.FC = ({ onPress, touchAreaSlop }) => { ); }, [trackEvent, createEventBuilder]); - const onPressHandler = () => { - if (!hasViewedCardButton) { - dispatch(setHasViewedCardButton(true)); - } - onPress(); - }; - return ( - - ) : null - } - > - - + ); }; diff --git a/app/components/UI/Card/components/CardButton/__snapshots__/CardButton.test.tsx.snap b/app/components/UI/Card/components/CardButton/__snapshots__/CardButton.test.tsx.snap index db9adbd1c57..a737e364376 100644 --- a/app/components/UI/Card/components/CardButton/__snapshots__/CardButton.test.tsx.snap +++ b/app/components/UI/Card/components/CardButton/__snapshots__/CardButton.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`CardButton Component renders with badge (not yet viewed) and matches snapshot 1`] = ` +exports[`CardButton Component renders and matches snapshot 1`] = ` - - - - - - - - - - - - - - - - - - - - - - -`; - -exports[`CardButton Component renders without badge when already viewed 1`] = ` - - - - - - - - - - - - - CardButton - - - - - - - - - - - - - - - - - - - - - - - + /> - diff --git a/app/components/Views/confirmations/components/modals/multiple-alert-modal/multiple-alert-modal.test.tsx b/app/components/Views/confirmations/components/modals/multiple-alert-modal/multiple-alert-modal.test.tsx index 8a0a9130236..fb1adf8df63 100644 --- a/app/components/Views/confirmations/components/modals/multiple-alert-modal/multiple-alert-modal.test.tsx +++ b/app/components/Views/confirmations/components/modals/multiple-alert-modal/multiple-alert-modal.test.tsx @@ -153,4 +153,27 @@ describe('MultipleAlertModal', () => { const { queryByText } = render(); expect(queryByText('Test Alert')).toBeNull(); }); + + it('syncs selectedIndex with alertKey when alertKey changes', () => { + const setAlertKey = jest.fn(); + (useAlerts as jest.Mock).mockReturnValue({ + ...baseMockUseAlerts, + setAlertKey, + alertKey: 'alert2', + }); + + const { getByText, rerender } = render(); + + expect(getByText('Test Alert 2')).toBeOnTheScreen(); + + (useAlerts as jest.Mock).mockReturnValue({ + ...baseMockUseAlerts, + setAlertKey, + alertKey: 'alert1', + }); + + rerender(); + + expect(getByText('Test Alert')).toBeOnTheScreen(); + }); }); diff --git a/app/components/Views/confirmations/components/modals/multiple-alert-modal/multiple-alert-modal.tsx b/app/components/Views/confirmations/components/modals/multiple-alert-modal/multiple-alert-modal.tsx index e836eeec040..b36cf4e4e43 100644 --- a/app/components/Views/confirmations/components/modals/multiple-alert-modal/multiple-alert-modal.tsx +++ b/app/components/Views/confirmations/components/modals/multiple-alert-modal/multiple-alert-modal.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useState } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import { View } from 'react-native'; import { useAlerts } from '../../../context/alert-system-context'; import { Alert, AlertSeverity, Severity } from '../../../types/alerts'; @@ -140,6 +140,17 @@ const MultipleAlertModal: React.FC = () => { initialAlertIndex === -1 ? 0 : initialAlertIndex, ); + // syncs selectedIndex with alertKey when the modal is reopened which + // ensures the correct styling is applied + useEffect(() => { + const alertKeyIndex = fieldAlerts.findIndex( + (alert: Alert) => alert.key === alertKey, + ); + if (alertKeyIndex !== -1 && alertKeyIndex !== selectedIndex) { + setSelectedIndex(alertKeyIndex); + } + }, [alertKey, fieldAlerts, selectedIndex]); + const handleBackButtonClick = useCallback(() => { setSelectedIndex((prevIndex: number) => prevIndex > 0 ? prevIndex - 1 : prevIndex, diff --git a/e2e/pages/wallet/WalletView.ts b/e2e/pages/wallet/WalletView.ts index 57fde5c228e..d4133fa3c58 100644 --- a/e2e/pages/wallet/WalletView.ts +++ b/e2e/pages/wallet/WalletView.ts @@ -77,10 +77,6 @@ class WalletView { return Matchers.getElementByID(WalletViewSelectorsIDs.CARD_BUTTON); } - get navbarCardButtonBadge(): DetoxElement { - return Matchers.getElementByID(WalletViewSelectorsIDs.CARD_BUTTON_BADGE); - } - get nftTab(): DetoxElement { return Matchers.getElementByText(WalletViewSelectorsText.NFTS_TAB); } diff --git a/e2e/selectors/wallet/WalletView.selectors.ts b/e2e/selectors/wallet/WalletView.selectors.ts index eb4a67864c4..5f2671c5660 100644 --- a/e2e/selectors/wallet/WalletView.selectors.ts +++ b/e2e/selectors/wallet/WalletView.selectors.ts @@ -10,7 +10,6 @@ export const WalletViewSelectorsIDs = { WALLET_TOKEN_DETECTION_LINK_BUTTON: 'wallet-token-detection-link-button', TOTAL_BALANCE_TEXT: 'total-balance-text', CARD_BUTTON: 'card-button', - CARD_BUTTON_BADGE: 'card-button-badge', STAKE_BUTTON: 'stake-button', EARN_EARNINGS_HISTORY_BUTTON: 'earn-earnings-history-button', UNSTAKE_BUTTON: 'unstake-button', diff --git a/e2e/specs/card/card-button.spec.ts b/e2e/specs/card/card-button.spec.ts index 08094ec71ac..784e3b9f8fc 100644 --- a/e2e/specs/card/card-button.spec.ts +++ b/e2e/specs/card/card-button.spec.ts @@ -51,12 +51,9 @@ describe.skip(SmokeCard('Card NavBar Button'), () => { jest.setTimeout(150000); }); - it('should open Card Home when pressing card navbar button', async () => { + it('opens Card Home when pressing card navbar button', async () => { await setupCardTest(async () => { await Assertions.expectElementToBeVisible(WalletView.navbarCardButton); - await Assertions.expectElementToBeVisible( - WalletView.navbarCardButtonBadge, - ); await WalletView.tapNavbarCardButton(); await Assertions.expectElementToBeVisible(CardHomeView.cardViewTitle); });