mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-05 07:24:56 +01:00
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
import React, { useContext } from 'react';
|
|
import classnames from 'classnames';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import {
|
|
getSendMaxModeState,
|
|
isSendFormInvalid,
|
|
toggleSendMaxMode,
|
|
} from '../../../../../ducks/send';
|
|
import { useI18nContext } from '../../../../../hooks/useI18nContext';
|
|
import { MetaMetricsContext } from '../../../../../contexts/metametrics.new';
|
|
|
|
export default function AmountMaxButton() {
|
|
const isDraftTransactionInvalid = useSelector(isSendFormInvalid);
|
|
const maxModeOn = useSelector(getSendMaxModeState);
|
|
const dispatch = useDispatch();
|
|
const trackEvent = useContext(MetaMetricsContext);
|
|
const t = useI18nContext();
|
|
|
|
const onMaxClick = () => {
|
|
trackEvent({
|
|
event: 'Clicked "Amount Max"',
|
|
category: 'Transactions',
|
|
properties: {
|
|
action: 'Edit Screen',
|
|
legacy_event: true,
|
|
},
|
|
});
|
|
dispatch(toggleSendMaxMode());
|
|
};
|
|
|
|
const disabled = isDraftTransactionInvalid;
|
|
|
|
return (
|
|
<button
|
|
className="send-v2__amount-max"
|
|
disabled={disabled}
|
|
onClick={onMaxClick}
|
|
>
|
|
<input type="checkbox" checked={maxModeOn} readOnly />
|
|
<div
|
|
className={classnames('send-v2__amount-max__button', {
|
|
'send-v2__amount-max__button__disabled': disabled,
|
|
})}
|
|
>
|
|
{t('max')}
|
|
</div>
|
|
</button>
|
|
);
|
|
}
|