diff --git a/test/e2e/tests/custom-token-add-approve.spec.js b/test/e2e/tests/custom-token-add-approve.spec.js index f694cd564..2cae7ff50 100644 --- a/test/e2e/tests/custom-token-add-approve.spec.js +++ b/test/e2e/tests/custom-token-add-approve.spec.js @@ -376,7 +376,7 @@ describe('Create token, approve token and approve token without gas', function ( // set max spending cap await driver.clickElement({ - css: '.custom-spending-cap__max', + css: '[data-testid="custom-spending-cap-max-button"]', text: 'Max', }); diff --git a/ui/components/app/app-components.scss b/ui/components/app/app-components.scss index 74f32c8c5..b3a9ed194 100644 --- a/ui/components/app/app-components.scss +++ b/ui/components/app/app-components.scss @@ -20,7 +20,6 @@ @import 'connected-accounts-permissions/index'; @import 'connected-sites-list/index'; @import 'create-new-vault/create-new-vault.scss'; -@import 'custom-spending-cap/index'; @import 'edit-gas-display/index'; @import 'edit-gas-fee-button/index'; @import 'edit-gas-fee-popover/index'; diff --git a/ui/components/app/custom-spending-cap/__snapshots__/custom-spending-cap.test.js.snap b/ui/components/app/custom-spending-cap/__snapshots__/custom-spending-cap.test.js.snap index d39214e16..23ac5400f 100644 --- a/ui/components/app/custom-spending-cap/__snapshots__/custom-spending-cap.test.js.snap +++ b/ui/components/app/custom-spending-cap/__snapshots__/custom-spending-cap.test.js.snap @@ -3,103 +3,84 @@ exports[`CustomSpendingCap should match snapshot 1`] = `
-
`; diff --git a/ui/components/app/custom-spending-cap/custom-spending-cap-tooltip.js b/ui/components/app/custom-spending-cap/custom-spending-cap-tooltip.js index b2bac1b14..40380d594 100644 --- a/ui/components/app/custom-spending-cap/custom-spending-cap-tooltip.js +++ b/ui/components/app/custom-spending-cap/custom-spending-cap-tooltip.js @@ -1,31 +1,26 @@ import React from 'react'; import PropTypes from 'prop-types'; -import Box from '../../ui/box'; import Tooltip from '../../ui/tooltip'; import { TextColor, TextVariant, Display, + AlignItems, + IconColor, } from '../../../helpers/constants/design-system'; -import { Icon, IconName, IconSize, Text } from '../../component-library'; +import { Icon, IconName, IconSize, Text, Box } from '../../component-library'; export const CustomSpendingCapTooltip = ({ tooltipContentText, tooltipIcon, }) => ( - + + {tooltipContentText} } @@ -33,13 +28,16 @@ export const CustomSpendingCapTooltip = ({ {tooltipIcon ? ( ) : ( tooltipIcon !== '' && ( - + ) )} diff --git a/ui/components/app/custom-spending-cap/custom-spending-cap.js b/ui/components/app/custom-spending-cap/custom-spending-cap.js index 570c19963..bcca9ec7e 100644 --- a/ui/components/app/custom-spending-cap/custom-spending-cap.js +++ b/ui/components/app/custom-spending-cap/custom-spending-cap.js @@ -1,25 +1,30 @@ import React, { useState, useContext, useEffect, useRef } from 'react'; import { useDispatch } from 'react-redux'; import PropTypes from 'prop-types'; -import classnames from 'classnames'; import BigNumber from 'bignumber.js'; import { addHexPrefix } from 'ethereumjs-util'; - import { I18nContext } from '../../../contexts/i18n'; -import FormField from '../../ui/form-field'; -import { Text, ButtonLink, Icon, IconName, Box } from '../../component-library'; import { AlignItems, Display, FlexDirection, - TextAlign, TextVariant, - JustifyContent, Size, - BlockSize, BackgroundColor, TextColor, + BlockSize, } from '../../../helpers/constants/design-system'; +import { + Text, + ButtonLink, + Icon, + IconName, + IconSize, + Label, + TextField, + HelpText, + Box, +} from '../../component-library'; import { setCustomTokenAmount } from '../../../ducks/app/app'; import { calcTokenAmount } from '../../../../shared/lib/transactions-controller-utils'; import { hexToDecimal } from '../../../../shared/modules/conversion.utils'; @@ -81,7 +86,6 @@ export default function CustomSpendingCap({ key="custom-spending-cap" variant={TextVariant.bodySmBold} as="span" - className="custom-spending-cap__input-value-and-token-name" > {replaceCommaToDot(inputNumber)} {tokenName} , @@ -198,7 +202,8 @@ export default function CustomSpendingCap({ as="span" color={TextColor.errorDefault} > - {t('beCareful')} + {' '} + {t('beCareful')} , ]) : t('inputLogicEmptyState'); @@ -207,121 +212,103 @@ export default function CustomSpendingCap({ <> - + {t('useSiteSuggestion')} + + )} + handleChange(e.target.value)} + placeholder={t('enterANumber')} + value={customSpendingCap} + endAccessory={ + { + e.preventDefault(); + handleChange(currentTokenBalance); + }} + data-testid="custom-spending-cap-max-button" + > + {t('max')} + + } + width={BlockSize.Full} + /> + + {error || + (replaceCommaToDot(customSpendingCap) + ? customSpendingCapText + : inputLogicEmptyStateText)} + + + {t('learnMoreUpperCase')} + ); diff --git a/ui/components/app/custom-spending-cap/custom-spending-cap.stories.js b/ui/components/app/custom-spending-cap/custom-spending-cap.stories.js index 0e492a43b..81799f551 100644 --- a/ui/components/app/custom-spending-cap/custom-spending-cap.stories.js +++ b/ui/components/app/custom-spending-cap/custom-spending-cap.stories.js @@ -1,21 +1,25 @@ import React from 'react'; +import { useArgs } from '@storybook/client-api'; + import CustomSpendingCap from './custom-spending-cap'; export default { title: 'Components/App/CustomSpendingCap', - argTypes: { + txParams: { + control: 'object', + }, tokenName: { - control: { type: 'text' }, + control: 'text', }, currentTokenBalance: { - control: { type: 'number' }, + control: 'text', }, dappProposedValue: { - control: { type: 'text' }, + control: 'text', }, siteOrigin: { - control: { type: 'text' }, + control: 'text', }, passTheErrorText: { action: 'passTheErrorText', @@ -23,32 +27,55 @@ export default { decimals: { control: 'text', }, + setInputChangeInProgress: { + action: 'setInputChangeInProgress', + }, customSpendingCap: { - control: { type: 'text' }, + control: 'text', + }, + setCustomSpendingCap: { + action: 'setCustomSpendingCap', }, }, args: { tokenName: 'DAI', - currentTokenBalance: 200.12, + currentTokenBalance: '200.12', dappProposedValue: '7', siteOrigin: 'Uniswap.org', decimals: '4', customSpendingCap: '7', + txParams: { + data: '0x095ea7b30000000000000000000000009bc5baf874d2da8d216ae9f137804184ee5afef40000000000000000000000000000000000000000000000000000000000011170', + from: '0x8eeee1781fd885ff5ddef7789486676961873d12', + gas: '0xb41b', + maxFeePerGas: '0x4a817c800', + maxPriorityFeePerGas: '0x4a817c800', + to: '0x665933d73375e385bef40abcccea8b4cccc32d4c', + value: '0x0', + }, }, }; -export const DefaultStory = (args) => { - return ; +const Template = (args) => { + const [{ customSpendingCap }, updateArgs] = useArgs(); + const handleOnChange = (value) => { + updateArgs({ customSpendingCap: value }); + }; + return ( + + ); }; +export const DefaultStory = Template.bind({}); DefaultStory.storyName = 'Default'; -export const CustomSpendingCapStory = (args) => { - return ; -}; -CustomSpendingCapStory.storyName = 'CustomSpendingCapStory'; +export const CustomSpendingCapStory = Template.bind({}); +CustomSpendingCapStory.storyName = 'CustomSpendingCap'; CustomSpendingCapStory.args = { - ...DefaultStory.args, customSpendingCap: '8', }; diff --git a/ui/components/app/custom-spending-cap/index.scss b/ui/components/app/custom-spending-cap/index.scss deleted file mode 100644 index 927c281d2..000000000 --- a/ui/components/app/custom-spending-cap/index.scss +++ /dev/null @@ -1,41 +0,0 @@ -.custom-spending-cap { - &__input-value-and-token-name { - display: contents; - } - - &__max { - position: relative; - margin-top: -30px; - - &--with-error-message { - margin-top: -66px; - } - } - - &__input { - width: 100%; - } - - &__description { - word-break: break-word; - - &--with-error-message { - margin-top: 30px; - } - } - - #custom-spending-cap-input-value { - color: var(--color-error-default); - padding-inline-end: 60px; - } - - #custom-spending-cap { - padding-inline-end: 60px; - } - - input[type='number']::-webkit-inner-spin-button, - input[type='number']:hover::-webkit-inner-spin-button { - -webkit-appearance: none; - display: none; - } -} diff --git a/ui/pages/token-allowance/__snapshots__/token-allowance.test.js.snap b/ui/pages/token-allowance/__snapshots__/token-allowance.test.js.snap index 16971cd5e..84df05840 100644 --- a/ui/pages/token-allowance/__snapshots__/token-allowance.test.js.snap +++ b/ui/pages/token-allowance/__snapshots__/token-allowance.test.js.snap @@ -344,103 +344,84 @@ exports[`TokenAllowancePage should match snapshot 1`] = ` class="box box--margin-4 box--sm:margin-4 box--md:margin-3 box--lg:margin-4 box--flex-direction-row" >
-