Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable wallet buttons for accounts that cannot sign transactions #11330

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1a0ac3d
parent fb86c8355dfc0269ed868d9a669882ae2f7254f3
Matt561 Sep 24, 2024
a2c1fca
feat: rename 'WalletActionStrings' to 'Details'
k-g-j Sep 24, 2024
f311f4b
feat: moved disabled descriptions into asset_overview
k-g-j Sep 24, 2024
4405795
feat: memoize 'selectedAccount' in WalletActions
k-g-j Sep 24, 2024
703ecd7
feat: memoize 'selectedAccount' in WalletActions and revert changes i…
k-g-j Sep 24, 2024
698c2d4
revert: changes in NotificationsManager"
k-g-j Sep 24, 2024
e536653
feat: made 'actionType' for WalletAction.types non-optional
k-g-j Sep 26, 2024
c9d0159
chore: update snapshots
k-g-j Sep 26, 2024
2809632
feat: update AssetDetailsActions.test to use IDs for buttons
k-g-j Sep 26, 2024
9b9470a
feat: updated computed styles in AssetDetailsActions, WalletActions, …
k-g-j Sep 27, 2024
e82786b
feat: remove render function from AssetDetailsActions
k-g-j Sep 27, 2024
e56b156
feat: undo changes in ios/MetaMask.xcodeproj/project.pbxproj
k-g-j Sep 27, 2024
7d62792
feat: made 'actionType' optional prop
k-g-j Oct 9, 2024
64ed760
chore: update snapshots
k-g-j Oct 9, 2024
267e93f
fix: app/components/Views/AssetDetails/AssetDetailsActions/AssetDetai…
k-g-j Oct 9, 2024
7a2b2e1
feat: disabled buttons in AssetDetails view
k-g-j Oct 10, 2024
7203cec
feat: removed string function from label rendering and removed label …
k-g-j Oct 16, 2024
daf1c05
chore: strings cleanup
k-g-j Oct 17, 2024
90d2e51
Revert "chore: strings cleanup"
k-g-j Oct 17, 2024
29bdaea
Revert "feat: removed string function from label rendering and remove…
k-g-j Oct 17, 2024
51a91b3
feat: fix merge conflicts with accounts controller selectors
k-g-j Oct 18, 2024
ab171e4
chore: rebase with main
k-g-j Oct 18, 2024
c0b725b
Merge branch 'main' into feat/disable-signing-buttons
k-g-j Oct 22, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ exports[`AssetOverview should render correctly 1`] = `
}
>
<TouchableOpacity
disabled={false}
onPress={[Function]}
style={
{
Expand Down Expand Up @@ -448,7 +449,11 @@ exports[`AssetOverview should render correctly 1`] = `
accessibilityRole="text"
style={
{
"color": "#6a737d",
"0": {
"color": "#6a737d",
},
"1": undefined,
"color": "#141618",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
Expand Down Expand Up @@ -485,6 +490,7 @@ exports[`AssetOverview should render correctly 1`] = `
}
>
<TouchableOpacity
disabled={false}
onPress={[Function]}
style={
{
Expand Down Expand Up @@ -543,7 +549,11 @@ exports[`AssetOverview should render correctly 1`] = `
accessibilityRole="text"
style={
{
"color": "#6a737d",
"0": {
"color": "#6a737d",
},
"1": undefined,
"color": "#141618",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
Expand Down Expand Up @@ -580,6 +590,7 @@ exports[`AssetOverview should render correctly 1`] = `
}
>
<TouchableOpacity
disabled={false}
onPress={[Function]}
style={
{
Expand Down Expand Up @@ -638,7 +649,11 @@ exports[`AssetOverview should render correctly 1`] = `
accessibilityRole="text"
style={
{
"color": "#6a737d",
"0": {
"color": "#6a737d",
},
"1": undefined,
"color": "#141618",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
Expand Down Expand Up @@ -675,6 +690,7 @@ exports[`AssetOverview should render correctly 1`] = `
}
>
<TouchableOpacity
disabled={false}
onPress={[Function]}
style={
{
Expand Down Expand Up @@ -733,7 +749,11 @@ exports[`AssetOverview should render correctly 1`] = `
accessibilityRole="text"
style={
{
"color": "#6a737d",
"0": {
"color": "#6a737d",
},
"1": undefined,
"color": "#141618",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
Expand Down Expand Up @@ -770,6 +790,7 @@ exports[`AssetOverview should render correctly 1`] = `
}
>
<TouchableOpacity
disabled={false}
onPress={[Function]}
style={
{
Expand Down Expand Up @@ -828,7 +849,11 @@ exports[`AssetOverview should render correctly 1`] = `
accessibilityRole="text"
style={
{
"color": "#6a737d",
"0": {
"color": "#6a737d",
},
"1": undefined,
"color": "#141618",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
Expand Down
48 changes: 39 additions & 9 deletions app/components/UI/WalletAction/WalletAction.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,81 @@
// Third party dependencies.
import React from 'react';
import { View, TouchableOpacity } from 'react-native';
import React, { useMemo } from 'react';
import { TouchableOpacity, View } from 'react-native';
import { lightTheme } from '@metamask/design-tokens';

// External dependencies.
import Text, {
TextVariant,
} from '../../../component-library/components/Texts/Text';
import { useStyles } from '../../../component-library/hooks';

// Internal dependencies.
import { WalletActionProps } from './WalletAction.types';
import { walletActionDetails, WalletActionProps } from './WalletAction.types';
import styleSheet from './WalletAction.styles';
import Avatar, {
AvatarVariant,
} from '../../../component-library/components/Avatars/Avatar';

const WalletAction = ({
actionTitle,
actionDescription,
actionType,
iconName,
iconSize,
onPress,
containerStyle,
iconStyle,
actionID,
disabled,
...props
}: WalletActionProps) => {
const actionStrings = actionType ? walletActionDetails[actionType] : null;
const actionTitle = actionStrings?.title ?? '';
const actionDescription = disabled
? actionStrings?.disabledDescription
: actionStrings?.description;
const { colors } = lightTheme;
const { styles } = useStyles(styleSheet, {});

const avatarStyle = useMemo(
() => ({
...iconStyle,
backgroundColor: disabled ? colors.primary.muted : colors.primary.default,
}),
[disabled, colors, iconStyle],
);

const titleStyle = useMemo(
() => (disabled ? { color: colors.text.muted } : undefined),
[disabled, colors],
);

const descriptionStyle = useMemo(
() => [
styles.descriptionLabel,
disabled ? { color: colors.text.muted } : undefined,
],
[styles, disabled, colors],
);

return (
<TouchableOpacity
style={{ ...styles.base, ...containerStyle }}
onPress={onPress}
testID={actionID}
disabled={disabled}
{...props}
>
<Avatar
variant={AvatarVariant.Icon}
style={iconStyle}
style={avatarStyle}
size={iconSize}
name={iconName}
backgroundColor={colors.primary.default}
iconColor={colors.background.default}
/>
<View>
<Text variant={TextVariant.BodyLGMedium}>{actionTitle}</Text>
<Text variant={TextVariant.BodyMD} style={styles.descriptionLabel}>
<Text variant={TextVariant.BodyLGMedium} style={titleStyle}>
{actionTitle}
</Text>
<Text variant={TextVariant.BodyMD} style={descriptionStyle}>
{actionDescription}
</Text>
</View>
Expand Down
54 changes: 52 additions & 2 deletions app/components/UI/WalletAction/WalletAction.types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,64 @@
import { ImageStyle, ViewStyle } from 'react-native';
import { IconName } from '../../../component-library/components/Icons/Icon';
import { AvatarSize } from '../../../component-library/components/Avatars/Avatar';
import { strings } from '../../../../locales/i18n';

export enum WalletActionType {
Buy = 'Buy',
Sell = 'Sell',
Swap = 'Swap',
Bridge = 'Bridge',
Send = 'Send',
Receive = 'Receive',
}

export interface WalletActionDetail {
title: string;
description: string;
disabledDescription: string;
}

export const walletActionDetails: Record<WalletActionType, WalletActionDetail> =
k-g-j marked this conversation as resolved.
Show resolved Hide resolved
{
[WalletActionType.Buy]: {
title: strings('asset_overview.buy_button'),
description: strings('asset_overview.buy_description'),
disabledDescription: strings('asset_overview.disabled_button.buy'),
},
[WalletActionType.Sell]: {
title: strings('asset_overview.sell_button'),
description: strings('asset_overview.sell_description'),
disabledDescription: strings('asset_overview.disabled_button.sell'),
},
[WalletActionType.Swap]: {
title: strings('asset_overview.swap'),
description: strings('asset_overview.swap_description'),
disabledDescription: strings('asset_overview.disabled_button.swap'),
},
[WalletActionType.Bridge]: {
title: strings('asset_overview.bridge'),
description: strings('asset_overview.bridge_description'),
disabledDescription: strings('asset_overview.disabled_button.bridge'),
},
[WalletActionType.Send]: {
title: strings('asset_overview.send_button'),
description: strings('asset_overview.send_description'),
disabledDescription: strings('asset_overview.disabled_button.send'),
},
[WalletActionType.Receive]: {
title: strings('asset_overview.receive_button'),
description: strings('asset_overview.receive_description'),
disabledDescription: strings('asset_overview.disabled_button.receive'),
},
};

export interface WalletActionProps {
actionTitle?: string;
actionDescription?: string;
actionType?: WalletActionType;
k-g-j marked this conversation as resolved.
Show resolved Hide resolved
iconName: IconName;
iconSize: AvatarSize;
onPress: () => void;
containerStyle?: ViewStyle;
iconStyle?: ImageStyle;
actionID?: string;
disabled?: boolean;
}
Loading
Loading