Skip to content
Draft
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
113 changes: 84 additions & 29 deletions app/components/UI/ActionModal/ActionContent/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, View } from 'react-native';
import StyledButton from '../../StyledButton';
import { strings } from '../../../../../locales/i18n';
import { usePureBlack } from '@metamask/design-system-twrnc-preset';
import { useTheme } from '../../../../util/theme';
import { getElevatedSurfaceColor } from '../../../../util/theme/themeUtils';
import {
Button,
ButtonVariant,
ButtonSize,
} from '@metamask/design-system-react-native';

export const createStyles = (theme, isPureBlack = false) =>
StyleSheet.create({
Expand Down Expand Up @@ -77,6 +81,43 @@
const isPureBlack = usePureBlack();
const styles = createStyles(theme, isPureBlack);

// Map legacy StyledButton modes to MMDS Button props
const mapModeToProps = (mode, { isCancel } = { isCancel: false }) => {

Check warning on line 85 in app/components/UI/ActionModal/ActionContent/index.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not use an object literal as default.

See more on https://sonarcloud.io/project/issues?id=MetaMask_metamask-mobile&issues=AZ9NzrP-5aPV8wEOEG6W&open=AZ9NzrP-5aPV8wEOEG6W&pullRequest=33147
// Normalize mode string
const normalized = String(mode || '').toLowerCase();

// Link-style buttons
if (
normalized === 'transparent' ||
normalized === 'transparent-blue' ||
normalized === 'warning-empty' ||
normalized === 'info'
) {
return { variant: ButtonVariant.Link, isDanger: normalized.includes('warning') };
}

// Secondary for cancel or explicit neutral/secondary/cancel
if (
isCancel ||
normalized === 'neutral' ||
normalized === 'secondary' ||
normalized === 'cancel' ||
normalized === 'rounded-normal' ||
normalized === 'normal'
) {
return { variant: ButtonVariant.Secondary, isDanger: false };
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cancel flag ignores explicit button modes

Medium Severity

mapModeToProps treats every cancel button as MMDS Secondary because isCancel is checked before legacy modes like warning, sign, and confirm. Callers that put the primary or destructive action on the cancel side lose the intended variant and danger styling.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3408c86. Configure here.


// Primary destructive
if (normalized === 'warning' || normalized === 'danger') {
return { variant: ButtonVariant.Primary, isDanger: true };
}

// Default primary confirm
// includes: 'confirm', 'blue', 'sign', 'inverse', etc.
return { variant: ButtonVariant.Primary, isDanger: false };
};

return (
<View style={[styles.viewWrapper, viewWrapperStyle]}>
<View style={[styles.viewContainer, viewContainerStyle]}>
Expand All @@ -91,34 +132,48 @@
actionContainerStyle,
]}
>
{displayCancelButton && (
<StyledButton
disabled={cancelButtonDisabled}
testID={cancelTestID}
type={cancelButtonMode}
onPress={onCancelPress}
containerStyle={[
styles.button,
!verticalButtons && styles.buttonHorizontal,
]}
>
{cancelText}
</StyledButton>
)}
{displayConfirmButton && (
<StyledButton
testID={confirmTestID}
type={confirmButtonMode}
onPress={onConfirmPress}
containerStyle={[
styles.button,
!verticalButtons && styles.buttonHorizontal,
]}
disabled={confirmDisabled}
>
{confirmText}
</StyledButton>
)}
{displayCancelButton && (() => {
const { variant, isDanger } = mapModeToProps(cancelButtonMode, {
isCancel: true,
});
return (
<Button
testID={cancelTestID}
variant={variant}
isDanger={isDanger}
onPress={onCancelPress}
isDisabled={cancelButtonDisabled}
size={ButtonSize.Lg}
style={[
styles.button,
!verticalButtons && styles.buttonHorizontal,
]}
>
{cancelText}
</Button>
);
})()}
{displayConfirmButton && (() => {
const { variant, isDanger } = mapModeToProps(confirmButtonMode, {
isCancel: false,
});
return (
<Button
testID={confirmTestID}
variant={variant}
isDanger={isDanger}
onPress={onConfirmPress}
isDisabled={confirmDisabled}
size={ButtonSize.Lg}
style={[
styles.button,
!verticalButtons && styles.buttonHorizontal,
]}
>
{confirmText}
</Button>
);
})()}
</View>
</View>
</View>
Expand Down
Loading