1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00
metamask-extension/ui/pages/send/send-content/send-row-wrapper/send-row-wrapper.component.js

69 lines
1.9 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import SendRowErrorMessage from './send-row-error-message';
2018-04-07 00:29:51 +02:00
export default class SendRowWrapper extends Component {
static propTypes = {
children: PropTypes.node,
errorType: PropTypes.string,
label: PropTypes.string,
showError: PropTypes.bool,
};
2018-04-07 00:29:51 +02:00
static contextTypes = {
t: PropTypes.func,
};
2020-11-03 00:41:28 +01:00
renderAmountFormRow() {
const { children, errorType = '', label, showError = false } = this.props;
2020-11-03 00:41:28 +01:00
const formField = Array.isArray(children)
? children[1] || children[0]
: children;
const customLabelContent = children.length > 1 ? children[0] : null;
2018-04-11 16:21:54 +02:00
2018-04-07 00:29:51 +02:00
return (
<div className="send-v2__form-row">
<div className="send-v2__form-label">
{label}
{customLabelContent}
</div>
<div className="send-v2__form-field-container">
2020-11-03 00:41:28 +01:00
<div className="send-v2__form-field">{formField}</div>
<div>
{showError && <SendRowErrorMessage errorType={errorType} />}
</div>
</div>
</div>
);
}
2020-11-03 00:41:28 +01:00
renderFormRow() {
const { children, errorType = '', label, showError = false } = this.props;
2020-11-03 00:41:28 +01:00
const formField = Array.isArray(children)
? children[1] || children[0]
: children;
2020-11-03 00:41:28 +01:00
const customLabelContent =
(Array.isArray(children) && children.length) > 1 ? children[0] : null;
return (
<div className="send-v2__form-row">
<div className="send-v2__form-label">
{label}
{showError && <SendRowErrorMessage errorType={errorType} />}
{customLabelContent}
2018-04-07 00:29:51 +02:00
</div>
2020-11-03 00:41:28 +01:00
<div className="send-v2__form-field">{formField}</div>
2018-04-07 00:29:51 +02:00
</div>
);
2018-04-07 00:29:51 +02:00
}
2020-11-03 00:41:28 +01:00
render() {
const { errorType = '' } = this.props;
2020-11-03 00:41:28 +01:00
return errorType === 'amount'
? this.renderAmountFormRow()
: this.renderFormRow();
}
2018-04-07 00:29:51 +02:00
}