Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/components/UI/Card/Views/CardHome/CardHome.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ const createStyles = (theme: Theme) =>
halfWidthButton: {
width: '50%',
},
halfWidthButtonDisabled: {
width: '50%',
opacity: 0.5,
},
shouldBeHidden: {
display: 'none',
},
Expand Down
82 changes: 82 additions & 0 deletions app/components/UI/Card/Views/CardHome/CardHome.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
selectCardholderAccounts,
selectIsAuthenticatedCard,
} from '../../../../../core/redux/slices/card';
import { useIsSwapEnabledForPriorityToken } from '../../hooks/useIsSwapEnabledForPriorityToken';

const mockNavigate = jest.fn();
const mockGoBack = jest.fn();
Expand Down Expand Up @@ -175,6 +176,10 @@ jest.mock('../../hooks/useOpenSwaps', () => ({
useOpenSwaps: jest.fn(),
}));

jest.mock('../../hooks/useIsSwapEnabledForPriorityToken', () => ({
useIsSwapEnabledForPriorityToken: jest.fn(),
}));

jest.mock('../../../../hooks/useMetrics', () => ({
useMetrics: jest.fn(),
MetaMetricsEvents: {
Expand Down Expand Up @@ -464,6 +469,8 @@ describe('CardHome Component', () => {
error: null,
});

(useIsSwapEnabledForPriorityToken as jest.Mock).mockReturnValue(true);

// Setup default selectors
setupMockSelectors();
});
Expand Down Expand Up @@ -1076,6 +1083,81 @@ describe('CardHome Component', () => {
);
});

describe('Swap Enabled for Priority Token', () => {
it('disables add funds button when swap is not enabled for priority token', () => {
// Given: swap is not enabled for the priority token
(useIsSwapEnabledForPriorityToken as jest.Mock).mockReturnValueOnce(
false,
);

// When: component renders
render();

// Then: add funds button should exist and be disabled
const addFundsButton = screen.getByTestId(
CardHomeSelectors.ADD_FUNDS_BUTTON,
);
expect(addFundsButton).toBeTruthy();
// Button should have disabled styling applied
expect(addFundsButton.props.disabled).toBe(true);
});

it('enables add funds button when swap is enabled for priority token', () => {
// Given: swap is enabled for the priority token
(useIsSwapEnabledForPriorityToken as jest.Mock).mockReturnValueOnce(true);

// When: component renders
render();

// Then: add funds button should be enabled
const addFundsButton = screen.getByTestId(
CardHomeSelectors.ADD_FUNDS_BUTTON,
);
expect(addFundsButton).toBeTruthy();
expect(addFundsButton.props.disabled).toBe(false);
});

it('applies disabled styling when swap is not enabled', () => {
// Given: swap is not enabled for the priority token
(useIsSwapEnabledForPriorityToken as jest.Mock).mockReturnValueOnce(
false,
);

// When: component renders
render();

// Then: button should have disabled prop set to true
const addFundsButton = screen.getByTestId(
CardHomeSelectors.ADD_FUNDS_BUTTON,
);
expect(addFundsButton).toBeTruthy();
expect(addFundsButton.props.disabled).toBe(true);
});

it('does not disable button when swap is enabled for priority token', async () => {
// Given: swap is enabled for the priority token
(useIsSwapEnabledForPriorityToken as jest.Mock).mockReturnValueOnce(true);

// When: component renders
render();

// Then: add funds button should be enabled and callable
const addFundsButton = screen.getByTestId(
CardHomeSelectors.ADD_FUNDS_BUTTON,
);
expect(addFundsButton.props.disabled).toBe(false);

mockTrackEvent.mockClear();
fireEvent.press(addFundsButton);

// When: user presses add funds button
// Then: should track event
await waitFor(() => {
expect(mockTrackEvent).toHaveBeenCalled();
});
});
});

describe('Baanx Login Features', () => {
it('shows change asset button when Baanx login is enabled', () => {
// Given: Baanx login is enabled (default)
Expand Down
18 changes: 16 additions & 2 deletions app/components/UI/Card/Views/CardHome/CardHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import useIsBaanxLoginEnabled from '../../hooks/isBaanxLoginEnabled';
import useCardDetails from '../../hooks/useCardDetails';
import CardWarningBox from '../../components/CardWarningBox/CardWarningBox';
import { selectIsAuthenticatedCard } from '../../../../../core/redux/slices/card';
import { useIsSwapEnabledForPriorityToken } from '../../hooks/useIsSwapEnabledForPriorityToken';

/**
* CardHome Component
Expand Down Expand Up @@ -105,6 +106,9 @@ const CardHome = () => {
const { openSwaps } = useOpenSwaps({
priorityToken,
});
const isSwapEnabledForPriorityToken = useIsSwapEnabledForPriorityToken(
priorityToken?.walletAddress,
);

const toggleIsBalanceAndAssetsHidden = useCallback(
(value: boolean) => {
Expand Down Expand Up @@ -274,11 +278,16 @@ const CardHome = () => {
<View style={styles.buttonsContainer}>
<Button
variant={ButtonVariants.Primary}
style={styles.halfWidthButton}
style={
!isSwapEnabledForPriorityToken
? styles.halfWidthButtonDisabled
: styles.halfWidthButton
}
label={strings('card.card_home.add_funds')}
size={ButtonSize.Lg}
onPress={addFundsAction}
width={ButtonWidthTypes.Full}
disabled={!isSwapEnabledForPriorityToken}
loading={isLoading}
testID={CardHomeSelectors.ADD_FUNDS_BUTTON}
/>
Expand Down Expand Up @@ -309,7 +318,12 @@ const CardHome = () => {
);
// eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [addFundsAction, priorityTokenWarning, isLoading]);
}, [
addFundsAction,
priorityTokenWarning,
isLoading,
isSwapEnabledForPriorityToken,
]);

const error = useMemo(
() => priorityTokenError || cardDetailsError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ exports[`CardHome Component renders correctly and matches snapshot 1`] = `
accessibilityRole="button"
accessible={true}
activeOpacity={1}
disabled={false}
loading={false}
onPress={[Function]}
onPressIn={[Function]}
Expand Down Expand Up @@ -1191,6 +1192,7 @@ exports[`CardHome Component renders correctly with privacy mode enabled 1`] = `
accessibilityRole="button"
accessible={true}
activeOpacity={1}
disabled={false}
loading={false}
onPress={[Function]}
onPressIn={[Function]}
Expand Down
Loading
Loading