Skip to content

Commit

Permalink
polishing up the delegations section
Browse files Browse the repository at this point in the history
dafuga authored and aaroncox committed Aug 22, 2018
1 parent 9aa3a57 commit a007ea0
Showing 7 changed files with 37 additions and 16 deletions.
1 change: 0 additions & 1 deletion app/renderer/assets/locales/en-US/stake.json
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@
"stake_button_cta": "Update Staked EOS",
"stake_confirming_header_one": "About to change delegation of: ",
"stake_cpu_amount": "CPU Amount",
"stake_modal_delegation_header": "Stake",
"stake_modal_title":"Update Staked EOS Amounts",
"stake_net_amount": "Bandwidth Amount",
"stake_success":"You have successfully staked additional EOS.",
1 change: 1 addition & 0 deletions app/renderer/assets/locales/en-US/tools.json
Original file line number Diff line number Diff line change
@@ -109,6 +109,7 @@
"tools_menu_wallet_header": "Wallet Tools",
"tools_menu_wallets": "Manage Wallets",
"tools_modal_contact_header_text": "Contact",
"tools_modal_delegation_header": "Delegate",
"tools_modal_permissions_auth_create_button": "New Permission",
"tools_modal_permissions_auth_edit_button": "Modify",
"tools_modal_permissions_auth_header": "Update Permission",
12 changes: 10 additions & 2 deletions app/shared/components/Tools/Form/Delegation.js
Original file line number Diff line number Diff line change
@@ -38,14 +38,18 @@ class ToolsFormDelegation extends Component<Props> {
});
} else if (delegationToRemove) {
const {
to: accountName
to: accountName,
cpu_weight,
net_weight
} = delegationToRemove;

this.setState({
accountName,
confirming: true,
cpuAmount: Decimal(0),
netAmount: Decimal(0)
cpuOriginal: Decimal(cpu_weight.split(' ')[0]),
netAmount: Decimal(0),
netOriginal: Decimal(net_weight.split(' ')[0])
});
}
}
@@ -66,8 +70,10 @@ class ToolsFormDelegation extends Component<Props> {
const {
accountName,
cpuAmount,
cpuOriginal,
confirming,
netAmount,
netOriginal
} = this.state;

return ((keys && keys.key) || settings.walletMode === 'watch')
@@ -79,7 +85,9 @@ class ToolsFormDelegation extends Component<Props> {
balance={balance}
confirming={confirming}
cpuAmount={cpuAmount}
cpuOriginal={cpuOriginal}
netAmount={netAmount}
netOriginal={netOriginal}
onBack={this.onBack}
onClose={onClose}
onConfirm={this.onConfirm}
2 changes: 1 addition & 1 deletion app/shared/components/Tools/Modal/Delegation.js
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ class ToolsModalDelegation extends Component<Props> {
openModal={openModal}
settings={settings}
system={system}
title={t('stake_modal_delegation_header')}
title={t('tools_modal_delegation_header')}
/>
);
}
21 changes: 16 additions & 5 deletions app/shared/components/Wallet/Panel/Button/Stake.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import React, { Component } from 'react';
import { translate } from 'react-i18next';
import { Decimal } from 'decimal.js';

import GlobalTransactionModal from '../../../Global/Transaction/Modal';
import WalletPanelFormStake from '../Form/Stake';
@@ -33,6 +34,13 @@ class WalletPanelButtonStake extends Component<Props> {
t
} = this.props;

const account = accounts[settings.account];

const {
cpu_weight,
net_weight
} = account.self_delegated_bandwidth;

return (
<GlobalTransactionModal
actionName="STAKE"
@@ -46,14 +54,17 @@ class WalletPanelButtonStake extends Component<Props> {
}}
content={(
<WalletPanelFormStake
account={accounts[settings.account]}
key="StakeForm"
settings={settings}
account={account}
accountName={settings.account}
actions={actions}
onClose={this.onClose}
validate={validate}
balance={balances[settings.account]}
cpuAmount={Decimal(cpu_weight.split(' ')[0])}
key="StakeForm"
netAmount={Decimal(net_weight.split(' ')[0])}
onClose={this.onClose}
settings={settings}
system={system}
validate={validate}
/>
)}
icon="microchip"
8 changes: 5 additions & 3 deletions app/shared/components/Wallet/Panel/Form/Stake.js
Original file line number Diff line number Diff line change
@@ -52,16 +52,18 @@ class WalletPanelFormStake extends Component<Props> {
accountName,
confirming,
cpuAmount,
netAmount
cpuOriginal,
netAmount,
netOriginal
} = this.props;

this.setState({
accountName: accountName || '',
confirming,
cpuOriginal: cpuAmount || Decimal(0),
cpuOriginal: cpuOriginal || cpuAmount || Decimal(0),
decimalCpuAmount: cpuAmount || Decimal(0),
decimalNetAmount: netAmount || Decimal(0),
netOriginal: netAmount || Decimal(0)
netOriginal: netOriginal || netAmount || Decimal(0)
});
}

8 changes: 4 additions & 4 deletions app/shared/components/Wallet/Panel/Form/Stake/Confirming.js
Original file line number Diff line number Diff line change
@@ -28,11 +28,11 @@ class WalletPanelFormStakeConfirming extends Component<Props> {
t
} = this.props;

const cpuAmount = parseFloat(decimalCpuAmount);
const netAmount = parseFloat(decimalNetAmount);
const cpuAmount = decimalCpuAmount.toNumber();
const netAmount = decimalNetAmount.toNumber();

const cpuDifference = cpuAmount - cpuOriginal;
const netDifference = netAmount - netOriginal;
const cpuDifference = cpuAmount - cpuOriginal.toNumber();
const netDifference = netAmount - netOriginal.toNumber();

const lessThanOneEosStaked = (decimalNetAmount < 1 || decimalCpuAmount < 1);

0 comments on commit a007ea0

Please sign in to comment.