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: adding tooltip to signature decoding state changes #28430

Merged
merged 46 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
03b89d8
UI changes to show decoding data for permits
jpuri Nov 5, 2024
75026e4
Merge branch 'develop' into decoding_ui_changes
jpuri Nov 7, 2024
7fed6fa
Display ERC20 and ERC721 token details returns by decoding api
jpuri Nov 7, 2024
cac71e1
Merge branch 'decoding_ui_changes' into decoded_token_display
jpuri Nov 7, 2024
8457fd3
Display native values returned from decoding api
jpuri Nov 8, 2024
569abbc
Display native values returned from decoding api
jpuri Nov 8, 2024
4810bdd
Display native values returned from decoding api
jpuri Nov 8, 2024
399086b
Display native values returned from decoding api
jpuri Nov 8, 2024
602fb20
Update signature controller and integrate decoding api
jpuri Nov 11, 2024
fc6ab5e
Update signature controller and integrate decoding api
jpuri Nov 11, 2024
228796c
Update LavaMoat policies
metamaskbot Nov 11, 2024
2943ebf
update
jpuri Nov 11, 2024
4b04930
Merge branch 'decoding_api_int' of github.com:MetaMask/metamask-exten…
jpuri Nov 11, 2024
25e9a00
UI changes to show decoding data for permits
jpuri Nov 5, 2024
fbfdfa3
Merge branch 'decoding_ui_changes' of github.com:MetaMask/metamask-ex…
jpuri Nov 11, 2024
cdbfe3b
Merge branch 'decoding_ui_changes' into decoded_token_display
jpuri Nov 11, 2024
45f64fe
update
jpuri Nov 11, 2024
dcc66cc
Merge branch 'decoded_token_display' of github.com:MetaMask/metamask-…
jpuri Nov 11, 2024
b4347bf
update
jpuri Nov 11, 2024
c9fed99
update
jpuri Nov 11, 2024
494fb15
Merge branch 'decoded_token_display' into native_value_display
jpuri Nov 11, 2024
8671d56
update
jpuri Nov 11, 2024
82f42b0
update
jpuri Nov 11, 2024
a24d06c
update
jpuri Nov 11, 2024
8de0e98
update
jpuri Nov 11, 2024
4100431
Adding tooltip to signature decoding state changes
jpuri Nov 13, 2024
a54859d
Adding tooltip to signature decoding state changes
jpuri Nov 13, 2024
4600859
Adding tooltip to signature decoding state changes
jpuri Nov 13, 2024
bb6d9de
update
jpuri Nov 13, 2024
f3b4938
merge
jpuri Nov 15, 2024
9ffc37f
Merge branch 'develop' into decoded_token_display
jpuri Nov 15, 2024
0a87bf1
update
jpuri Nov 16, 2024
49e1019
Merge branch 'decoded_token_display' into native_value_display
jpuri Nov 16, 2024
d4b7eb5
update
jpuri Nov 16, 2024
7cc5d0b
Merge branch 'native_value_display' of github.com:MetaMask/metamask-e…
jpuri Nov 16, 2024
ed4aba6
update
jpuri Nov 16, 2024
e437a1b
update
jpuri Nov 16, 2024
6e4de16
Merge branch 'native_value_display' into state_change_tooltips
jpuri Nov 16, 2024
571b540
Merge branch 'state_change_tooltips' of github.com:MetaMask/metamask-…
jpuri Nov 16, 2024
6debf04
update
jpuri Nov 16, 2024
d969a07
update
jpuri Nov 22, 2024
dda245a
update
jpuri Nov 22, 2024
cc65aee
update
jpuri Nov 22, 2024
1666356
update
jpuri Nov 22, 2024
dc8f1b9
update
jpuri Nov 22, 2024
bc0f21f
Merge branch 'develop' into state_change_tooltips
jpuri Nov 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
6 changes: 6 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import configureMockStore from 'redux-mock-store';
import {
DecodingData,
DecodingDataChangeType,
DecodingDataStateChanges,
} from '@metamask/signature-controller';

import { getMockTypedSignConfirmStateForRequest } from '../../../../../../../../../test/data/confirmations/helper';
import { renderWithConfirmContextProvider } from '../../../../../../../../../test/lib/confirmations/render-helpers';
import { permitSignatureMsg } from '../../../../../../../../../test/data/confirmations/typed_sign';
import PermitSimulation from './decoded-simulation';
import PermitSimulation, { getStateChangeToolip } from './decoded-simulation';

const decodingData: DecodingData = {
stateChanges: [
Expand All @@ -22,6 +23,42 @@ const decodingData: DecodingData = {
],
};

const decodingDataListing: DecodingDataStateChanges = [
{
assetType: 'NATIVE',
changeType: DecodingDataChangeType.Receive,
address: '',
amount: '900000000000000000',
contractAddress: '',
},
{
assetType: 'ERC721',
changeType: DecodingDataChangeType.Listing,
address: '',
amount: '',
contractAddress: '0xafd4896984CA60d2feF66136e57f958dCe9482d5',
tokenID: '2101',
},
];

const decodingDataBidding: DecodingDataStateChanges = [
{
assetType: 'ERC721',
changeType: DecodingDataChangeType.Receive,
address: '',
amount: '900000000000000000',
contractAddress: '',
},
{
assetType: 'Native',
changeType: DecodingDataChangeType.Bidding,
address: '',
amount: '',
contractAddress: '0xafd4896984CA60d2feF66136e57f958dCe9482d5',
tokenID: '2101',
},
];

describe('DecodedSimulation', () => {
it('renders component correctly', async () => {
const state = getMockTypedSignConfirmStateForRequest({
Expand All @@ -38,4 +75,24 @@ describe('DecodedSimulation', () => {

expect(container).toMatchSnapshot();
});

describe('getStateChangeToolip', () => {
it('return correct tooltip when permit is for listing NFT', async () => {
const tooltip = getStateChangeToolip(
decodingDataListing,
decodingDataListing?.[0],
(str: string) => str,
);
expect(tooltip).toBe('signature_decoding_list_nft_tooltip');
});
});

it('return correct tooltip when permit is for bidding NFT', async () => {
const tooltip = getStateChangeToolip(
decodingDataBidding,
decodingDataBidding?.[0],
(str: string) => str,
);
expect(tooltip).toBe('signature_decoding_bid_nft_tooltip');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import {
DecodingDataChangeType,
DecodingDataStateChange,
DecodingDataStateChanges,
} from '@metamask/signature-controller';
import { Hex } from '@metamask/utils';

Expand All @@ -11,8 +12,35 @@ import { useI18nContext } from '../../../../../../../../hooks/useI18nContext';
import { SignatureRequestType } from '../../../../../../types/confirm';
import { useConfirmContext } from '../../../../../../context/confirm';
import StaticSimulation from '../../../shared/static-simulation/static-simulation';
import NativeValueDisplay from '../native-value-display/native-value-display';
import TokenValueDisplay from '../value-display/value-display';
import NativeValueDisplay from '../native-value-display/native-value-display';

export const getStateChangeToolip = (
stateChangeList: DecodingDataStateChanges | null,
stateChange: DecodingDataStateChange,
t: ReturnType<typeof useI18nContext>,
): string | undefined => {
if (stateChange.changeType === DecodingDataChangeType.Receive) {
if (
stateChangeList?.some(
(change) =>
change.changeType === DecodingDataChangeType.Listing &&
change.assetType === TokenStandard.ERC721,
)
) {
return t('signature_decoding_list_nft_tooltip');
}
if (
stateChange.assetType === TokenStandard.ERC721 &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Q:

we check the assetType on stateChange here and the assetType on the change of the list item above. Did we want to keep this as is or update to be consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Above is filter applied to whole list of state changes, and here we are checking seet of single state change.

Copy link
Contributor

Choose a reason for hiding this comment

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

right. Thanks for confirming this is expected!

stateChangeList?.some(
(change) => change.changeType === DecodingDataChangeType.Bidding,
)
) {
return t('signature_decoding_bid_nft_tooltip');
}
}
return undefined;
};

const getStateChangeLabelMap = (
t: ReturnType<typeof useI18nContext>,
Expand All @@ -28,17 +56,23 @@ const getStateChangeLabelMap = (
}[changeType]);

const StateChangeRow = ({
stateChangeList,
stateChange,
chainId,
}: {
stateChangeList: DecodingDataStateChanges | null;
stateChange: DecodingDataStateChange;
chainId: Hex;
}) => {
const t = useI18nContext();
const { assetType, changeType, amount, contractAddress, tokenID } =
stateChange;
const tooltip = getStateChangeToolip(stateChangeList, stateChange, t);
return (
<ConfirmInfoRow label={getStateChangeLabelMap(t, changeType)}>
<ConfirmInfoRow
label={getStateChangeLabelMap(t, changeType)}
tooltip={tooltip}
>
{(assetType === TokenStandard.ERC20 ||
assetType === TokenStandard.ERC721) && (
<TokenValueDisplay
Expand Down Expand Up @@ -70,7 +104,11 @@ const DecodedSimulation: React.FC<object> = () => {

const stateChangeFragment = (decodingData?.stateChanges ?? []).map(
(change: DecodingDataStateChange) => (
<StateChangeRow stateChange={change} chainId={chainId} />
<StateChangeRow
stateChangeList={decodingData?.stateChanges ?? []}
stateChange={change}
chainId={chainId}
/>
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const PermitSimulation: React.FC<object> = () => {

if (
decodingData?.error ||
(decodingData === undefined && decodingLoading !== true)
(decodingData?.stateChanges === undefined && decodingLoading !== true)
) {
return <DefaultSimulation />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ import {
} from '../../../../../../../../components/component-library';
import Tooltip from '../../../../../../../../components/ui/tooltip';
import {
BackgroundColor,
BlockSize,
BorderRadius,
Display,
JustifyContent,
TextAlign,
TextColor,
} from '../../../../../../../../helpers/constants/design-system';
import Name from '../../../../../../../../components/app/name/name';
import { TokenDetailsERC20 } from '../../../../../../utils/token';
import { getAmountColors } from '../../../utils';

type PermitSimulationValueDisplayParams = {
/** ID of the associated chain. */
Expand Down Expand Up @@ -112,16 +111,7 @@ const PermitSimulationValueDisplay: React.FC<
return null;
}

let valueColor = TextColor.textDefault;
let valueBackgroundColor = BackgroundColor.backgroundAlternative;

if (credit) {
valueColor = TextColor.successDefault;
valueBackgroundColor = BackgroundColor.successMuted;
} else if (debit) {
valueColor = TextColor.errorDefault;
valueBackgroundColor = BackgroundColor.errorMuted;
}
const { color, backgroundColor } = getAmountColors(credit, debit);

return (
<Box marginLeft="auto" style={{ maxWidth: '100%' }}>
Expand All @@ -139,9 +129,9 @@ const PermitSimulationValueDisplay: React.FC<
>
<Text
data-testid="simulation-token-value"
backgroundColor={valueBackgroundColor}
backgroundColor={backgroundColor}
borderRadius={BorderRadius.XL}
color={valueColor}
color={color}
paddingInline={2}
style={{ paddingTop: '1px', paddingBottom: '1px' }}
textAlign={TextAlign.Center}
Expand Down
Loading