Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.

Commit fe72f20

Browse files
jakeolsTbaut
authored andcommitted
fix duplicate account names (#575)
* remove ability to create accounts with same account name * add error message * Update packages/fether-react/src/Accounts/CreateAccount/AccountName/AccountName.js Co-Authored-By: Thibaut Sardan <[email protected]>
1 parent 4cd2cfc commit fe72f20

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

packages/fether-react/src/Accounts/CreateAccount/AccountName/AccountName.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import { inject, observer } from 'mobx-react';
1010

1111
import i18n, { packageNS } from '../../../i18n';
1212
import loading from '../../../assets/img/icons/loading.svg';
13+
import withAccountsInfo from '../../../utils/withAccountsInfo';
1314

15+
@withAccountsInfo
1416
@inject('createAccountStore')
1517
@observer
1618
class AccountName extends Component {
@@ -115,9 +117,14 @@ class AccountName extends Component {
115117
createAccountStore: { address, name },
116118
error,
117119
history,
118-
location: { pathname }
120+
location: { pathname },
121+
accountsInfo
119122
} = this.props;
123+
120124
const currentStep = pathname.slice(-1);
125+
const accountNameExists = !!Object.values(accountsInfo).find(
126+
info => info.name.toLowerCase() === name.toLowerCase()
127+
);
121128

122129
return (
123130
<form key='createAccount' noValidate onSubmit={this.handleSubmit}>
@@ -133,6 +140,11 @@ class AccountName extends Component {
133140
value={name}
134141
/>
135142
{error && <p>{error}</p>}
143+
{accountNameExists && (
144+
<p>
145+
{i18n.t(`${packageNS}:account.create.error_msg_duplicate_name`)}
146+
</p>
147+
)}
136148
<nav className='form-nav -space-around'>
137149
{currentStep > 1 && (
138150
<button
@@ -143,7 +155,7 @@ class AccountName extends Component {
143155
{i18n.t(`${packageNS}:navigation.back`)}
144156
</button>
145157
)}
146-
{name && address ? (
158+
{name && address && !accountNameExists ? (
147159
<button className='button'>
148160
{i18n.t(`${packageNS}:navigation.next`)}
149161
</button>

packages/fether-react/src/i18n/locales/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"label_name_msg": "Bitte geben Sie diesem Konto einen Namen:",
66
"label_name": "Name",
77
"title": "Ein neues Konto erstellen",
8+
"error_msg_duplicate_name": "Ein Konto mit diesem Namen existiert.",
89
"copy_phrase": {
910
"msg1": "Bitte schreibe deinen geheimen Satz auf ein Blatt Papier:",
1011
"msg2": "Behalte es sicher und geheim.",

packages/fether-react/src/i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"label_name_msg": "Please give this account a name:",
66
"label_name": "Name",
77
"title": "Create a new account",
8+
"error_msg_duplicate_name": "An account already exists with this name.",
89
"copy_phrase": {
910
"msg1": "Please write your secret phrase on a piece of paper:",
1011
"msg2": "Keep it secure and secret.",

0 commit comments

Comments
 (0)