Skip to content

Commit

Permalink
Added a message about overwriting delegations within prompts
Browse files Browse the repository at this point in the history
Fixes #57
  • Loading branch information
aaroncox committed Dec 14, 2017
1 parent 301ccdf commit 653c413
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/components/sign/operations/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default class OperationsPrompt extends Component {
case 'delegate_vesting_shares':
return [
<Header attached='top' key='op-header'><Icon name='power' />Delegate Steem Power</Header>,
<OperationsPromptDelegation opData={opData} steem={this.props.steem} />
<OperationsPromptDelegation account={this.props.account} opData={opData} steem={this.props.steem} />
]
case 'transfer':
return [
Expand Down
19 changes: 19 additions & 0 deletions app/components/sign/operations/types/delegation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ export default class OperationsPromptDelegation extends Component {
const totalVestsSteem = parseFloat(this.props.steem.props.total_vesting_fund_steem.split(" ")[0])
const totalVests = parseFloat(this.props.steem.props.total_vesting_shares.split(" ")[0])
const sp = (vests > 0) ? (totalVestsSteem * vests / totalVests).toFixed(3) : 0
let existingDelegation = 0
let existingDelegationWarning = false
if (this.props.account.vestingDelegations && this.props.account.vestingDelegations[opData.delegator]) {
const existingDelegations = this.props.account.vestingDelegations[opData.delegator]
existingDelegation = existingDelegations.reduce((a, b) => (b.delegator === opData.delegator && b.delegatee === opData.delegatee) ? a + parseFloat(b.vesting_shares.split(" ")[0]) : 0, 0)
if(existingDelegation > 0) {
const existingSp = (existingDelegation * vests / totalVests).toFixed(3)
existingDelegationWarning = (
<Grid.Row columns={1}>
<Grid.Column>
<Message info>
A delegation of <strong>{existingSp} SP</strong> ({existingDelegation} VESTS) is already active from <AccountName name={opData.delegator}/> to <AccountName name={opData.delegatee}/>. This new delegation will <strong>overwrite</strong> the existing delegation (not add to it).
</Message>
</Grid.Column>
</Grid.Row>
)
}
}
const numberFormat = {
shortFormat: true,
shortFormatMinValue: 1000
Expand Down Expand Up @@ -67,6 +85,7 @@ export default class OperationsPromptDelegation extends Component {
</Header>
</Grid.Column>
</Grid.Row>
{existingDelegationWarning}
</Grid>
</Segment>
)
Expand Down
3 changes: 2 additions & 1 deletion app/containers/PromptOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ class PromptOperation extends Component {

render() {
const { ops, meta } = this.state
const { keys } = this.props
const { account, keys } = this.props
return (
<OperationsPrompt
account={account}
accounts={keys.names}
accountChange={this.modifyOpsByAccount.bind(this)}
meta={meta}
Expand Down

0 comments on commit 653c413

Please sign in to comment.