Skip to content

Commit

Permalink
checking that the account name exists on new delegations
Browse files Browse the repository at this point in the history
dafuga authored and aaroncox committed Aug 22, 2018
1 parent e5a1a2f commit 7428e07
Showing 4 changed files with 50 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/renderer/assets/locales/en-US/global.json
Original file line number Diff line number Diff line change
@@ -2,8 +2,9 @@
"account_registered_as_a_proxy_is_not_allowed_to_use_a_proxy": "This account is currently registered as a proxy, and cannot set another proxy without first unregistering as a proxy. To unregister this account, use the Register Voting Proxy tab on the Tools page.",
"account_that_uses_a_proxy_is_not_allowed_to_become_a_proxy": "This account currently has set it's votes to another proxy, and cannot itself register as a proxy. To remove the set proxy, click the Change Voter Proxy button on the Producer Voting page.",
"error": "Error",
"error_accountName_not_unique_in_contacts": "This account name is already in your list of contacts.",
"error_account_does_not_exist": "This account name does not exist.",
"error_account_name_not_available": "This Account Name has already been taken.",
"error_accountName_not_unique_in_contacts": "This account name is already in your list of contacts.",
"error_cannot_transfer_to_self": "Invalid recipient, cannot transfer funds to self.",
"error_eosio_assert_message_exception": "The EOS blockchain returned a generic error based on your request. Please check that the information is valid and try again.",
"error_invalid_accountName": "Invalid Account Name, make sure it is comprised of 1 to 12 letters.",
24 changes: 24 additions & 0 deletions app/shared/actions/accounts.js
Original file line number Diff line number Diff line change
@@ -87,6 +87,29 @@ export function checkAccountAvailability(account = '') {
};
}

export function checkAccountExists(account = '') {
return (dispatch: () => void, getState) => {
dispatch({
type: types.SYSTEM_ACCOUNT_EXISTS_PENDING,
payload: { account_name: account }
});
const {
connection,
settings
} = getState();

if (account && (settings.node || settings.node.length !== 0)) {
eos(connection).getAccount(account).then(() => dispatch({
type: types.SYSTEM_ACCOUNT_EXISTS_SUCCESS,
payload: { account_name: account }
})).catch((err) => dispatch({
type: types.SYSTEM_ACCOUNT_EXISTS_FAILURE,
payload: { err }
}));
}
};
}

export function getAccount(account = '') {
return (dispatch: () => void, getState) => {
dispatch({
@@ -310,6 +333,7 @@ export function clearAccountByKey() {

export default {
checkAccountAvailability,
checkAccountExists,
clearAccountByKey,
clearAccountCache,
getAccount,
3 changes: 3 additions & 0 deletions app/shared/actions/types.js
Original file line number Diff line number Diff line change
@@ -55,6 +55,9 @@ export const SYSTEM_ACCOUNT_BY_KEY_CLEAR = 'SYSTEM_ACCOUNT_BY_KEY_CLEAR';
export const SYSTEM_ACCOUNT_BY_KEY_FAILURE = 'SYSTEM_ACCOUNT_BY_KEY_FAILURE';
export const SYSTEM_ACCOUNT_BY_KEY_PENDING = 'SYSTEM_ACCOUNT_BY_KEY_PENDING';
export const SYSTEM_ACCOUNT_BY_KEY_SUCCESS = 'SYSTEM_ACCOUNT_BY_KEY_SUCCESS';
export const SYSTEM_ACCOUNT_EXISTS_FAILURE = 'SYSTEM_ACCOUNT_EXISTS_FAILURE';
export const SYSTEM_ACCOUNT_EXISTS_PENDING = 'SYSTEM_ACCOUNT_EXISTS_PENDING';
export const SYSTEM_ACCOUNT_EXISTS_SUCCESS = 'SYSTEM_ACCOUNT_EXISTS_SUCCESS';
export const SYSTEM_BLOCKEXPLORERS_FAILURE = 'SYSTEM_BLOCKEXPLORERS_FAILURE';
export const SYSTEM_BLOCKEXPLORERS_PENDING = 'SYSTEM_BLOCKEXPLORERS_PENDING';
export const SYSTEM_BLOCKEXPLORERS_SUCCESS = 'SYSTEM_BLOCKEXPLORERS_SUCCESS';
23 changes: 21 additions & 2 deletions app/shared/components/Wallet/Panel/Form/Stake.js
Original file line number Diff line number Diff line change
@@ -102,13 +102,23 @@ class WalletPanelFormStake extends Component<Props> {
}

onChange = (e, { name, value, valid }) => {
const {
actions
} = this.props;

const {
checkAccountExists
} = actions;

const newState = {
[name]: value,
formError: null,
submitDisabled: false
};

if (name !== 'accountName') {
if (name === 'accountName') {
checkAccountExists(value);
} else {
const decimalFieldName = `decimal${name.charAt(0).toUpperCase()}${name.slice(1)}`;
newState[decimalFieldName] = Decimal(value.split(' ')[0]);
}
@@ -223,6 +233,15 @@ class WalletPanelFormStake extends Component<Props> {
const shouldShowConfirm = this.state.confirming;
const shouldShowForm = !shouldShowConfirm;

let {
formError
} = this.state;

if (system.ACCOUNT_EXISTS === 'FAILURE' &&
system.ACCOUNT_EXISTS_LAST_ACCOUNT === accountName) {
formError = formError || 'account_does_not_exist';
}

return (
<Segment
loading={system.STAKE === 'PENDING'}
@@ -278,7 +297,7 @@ class WalletPanelFormStake extends Component<Props> {
/>
</Form.Group>
<FormMessageError
error={this.state.formError}
error={formError}
/>
<Divider />
<Message

0 comments on commit 7428e07

Please sign in to comment.