mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-10-22 19:26:13 +02:00
We want to convert NetworkController to TypeScript in order to be able to compare differences in the controller between in this repo and the core repo. To do this, however, we need to convert the dependencies of the controller to TypeScript. As a part of this effort, this commit converts `shared/constants/metametrics` to TypeScript. Note that simple objects have been largely replaced with enums. There are some cases where I even split up some of these objects into multiple enums. Co-authored-by: Mark Stacey <markjstacey@gmail.com>
119 lines
3.5 KiB
JavaScript
119 lines
3.5 KiB
JavaScript
import React, { Component } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import classnames from 'classnames';
|
|
import Button from '../../components/ui/button';
|
|
import {
|
|
MetaMetricsEventAccountType,
|
|
MetaMetricsEventCategory,
|
|
MetaMetricsEventName,
|
|
} from '../../../shared/constants/metametrics';
|
|
import { getAccountNameErrorMessage } from '../../helpers/utils/accounts';
|
|
|
|
export default class NewAccountCreateForm extends Component {
|
|
static defaultProps = {
|
|
newAccountNumber: 0,
|
|
};
|
|
|
|
state = {
|
|
newAccountName: '',
|
|
defaultAccountName: this.context.t('newAccountNumberName', [
|
|
this.props.newAccountNumber,
|
|
]),
|
|
};
|
|
|
|
render() {
|
|
const { newAccountName, defaultAccountName } = this.state;
|
|
const { history, createAccount, mostRecentOverviewPage, accounts } =
|
|
this.props;
|
|
|
|
const createClick = (event) => {
|
|
event.preventDefault();
|
|
createAccount(newAccountName || defaultAccountName)
|
|
.then(() => {
|
|
this.context.trackEvent({
|
|
category: MetaMetricsEventCategory.Accounts,
|
|
event: MetaMetricsEventName.AccountAdded,
|
|
properties: {
|
|
account_type: MetaMetricsEventAccountType.Default,
|
|
},
|
|
});
|
|
history.push(mostRecentOverviewPage);
|
|
})
|
|
.catch((e) => {
|
|
this.context.trackEvent({
|
|
category: MetaMetricsEventCategory.Accounts,
|
|
event: MetaMetricsEventName.AccountAddFailed,
|
|
properties: {
|
|
account_type: MetaMetricsEventAccountType.Default,
|
|
error: e.message,
|
|
},
|
|
});
|
|
});
|
|
};
|
|
|
|
const { isValidAccountName, errorMessage } = getAccountNameErrorMessage(
|
|
accounts,
|
|
this.context,
|
|
newAccountName,
|
|
defaultAccountName,
|
|
);
|
|
|
|
return (
|
|
<div className="new-account-create-form">
|
|
<div className="new-account-create-form__input-label">
|
|
{this.context.t('accountName')}
|
|
</div>
|
|
<div>
|
|
<input
|
|
className={classnames({
|
|
'new-account-create-form__input': true,
|
|
'new-account-create-form__input__error': !isValidAccountName,
|
|
})}
|
|
value={newAccountName}
|
|
placeholder={defaultAccountName}
|
|
onChange={(event) =>
|
|
this.setState({ newAccountName: event.target.value })
|
|
}
|
|
autoFocus
|
|
/>
|
|
<div className="new-account-create-form__error new-account-create-form__error-amount">
|
|
{errorMessage}
|
|
</div>
|
|
<div className="new-account-create-form__buttons">
|
|
<Button
|
|
type="secondary"
|
|
large
|
|
className="new-account-create-form__button"
|
|
onClick={() => history.push(mostRecentOverviewPage)}
|
|
>
|
|
{this.context.t('cancel')}
|
|
</Button>
|
|
<Button
|
|
type="primary"
|
|
large
|
|
className="new-account-create-form__button"
|
|
onClick={createClick}
|
|
disabled={!isValidAccountName}
|
|
>
|
|
{this.context.t('create')}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
NewAccountCreateForm.propTypes = {
|
|
createAccount: PropTypes.func,
|
|
newAccountNumber: PropTypes.number,
|
|
history: PropTypes.object,
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
|
accounts: PropTypes.array,
|
|
};
|
|
|
|
NewAccountCreateForm.contextTypes = {
|
|
t: PropTypes.func,
|
|
trackEvent: PropTypes.func,
|
|
};
|