2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
2018-04-11 16:21:54 +02:00
|
|
|
|
|
|
|
export default class AmountMaxButton extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
balance: PropTypes.string,
|
2019-05-20 18:38:08 +02:00
|
|
|
buttonDataLoading: PropTypes.bool,
|
|
|
|
clearMaxAmount: PropTypes.func,
|
|
|
|
inError: PropTypes.bool,
|
2018-04-27 02:38:14 +02:00
|
|
|
gasTotal: PropTypes.string,
|
|
|
|
maxModeOn: PropTypes.bool,
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: PropTypes.object,
|
2018-04-11 16:21:54 +02:00
|
|
|
setAmountToMax: PropTypes.func,
|
|
|
|
setMaxModeTo: PropTypes.func,
|
2018-04-27 02:38:14 +02:00
|
|
|
tokenBalance: PropTypes.string,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-04-11 16:21:54 +02:00
|
|
|
|
2018-07-02 04:09:28 +02:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2019-05-07 18:12:14 +02:00
|
|
|
metricsEvent: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-02 04:09:28 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
setMaxAmount() {
|
2018-04-11 16:21:54 +02:00
|
|
|
const {
|
|
|
|
balance,
|
|
|
|
gasTotal,
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken,
|
2018-04-11 16:21:54 +02:00
|
|
|
setAmountToMax,
|
2018-04-27 02:38:14 +02:00
|
|
|
tokenBalance,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2018-04-11 16:21:54 +02:00
|
|
|
|
|
|
|
setAmountToMax({
|
2018-04-27 02:38:14 +02:00
|
|
|
balance,
|
2018-04-11 16:21:54 +02:00
|
|
|
gasTotal,
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken,
|
2018-04-27 02:38:14 +02:00
|
|
|
tokenBalance,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-04-11 16:21:54 +02:00
|
|
|
}
|
|
|
|
|
2019-05-20 19:36:28 +02:00
|
|
|
onMaxClick = () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { setMaxModeTo, clearMaxAmount, maxModeOn } = this.props;
|
|
|
|
const { metricsEvent } = this.context;
|
2019-03-05 16:45:01 +01:00
|
|
|
|
2019-05-07 18:12:14 +02:00
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Edit Screen',
|
|
|
|
name: 'Clicked "Amount Max"',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-08-14 13:47:43 +02:00
|
|
|
if (maxModeOn) {
|
2021-02-04 19:15:23 +01:00
|
|
|
setMaxModeTo(false);
|
|
|
|
clearMaxAmount();
|
2020-08-14 13:47:43 +02:00
|
|
|
} else {
|
2021-02-04 19:15:23 +01:00
|
|
|
setMaxModeTo(true);
|
|
|
|
this.setMaxAmount();
|
2019-05-20 18:38:08 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-10-16 01:26:24 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { maxModeOn, buttonDataLoading, inError } = this.props;
|
2019-05-20 18:38:08 +02:00
|
|
|
|
|
|
|
return (
|
2020-11-03 00:41:28 +01:00
|
|
|
<div
|
|
|
|
className="send-v2__amount-max"
|
|
|
|
onClick={buttonDataLoading || inError ? null : this.onMaxClick}
|
|
|
|
>
|
2020-02-06 20:34:23 +01:00
|
|
|
<input type="checkbox" checked={maxModeOn} readOnly />
|
2020-11-03 00:41:28 +01:00
|
|
|
<div
|
|
|
|
className={classnames('send-v2__amount-max__button', {
|
|
|
|
'send-v2__amount-max__button__disabled':
|
|
|
|
buttonDataLoading || inError,
|
|
|
|
})}
|
|
|
|
>
|
2019-07-31 22:17:11 +02:00
|
|
|
{this.context.t('max')}
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-04-11 16:21:54 +02:00
|
|
|
}
|
|
|
|
}
|