Skip to content

Commit

Permalink
fixing the stake action to handle staking to others properly
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga authored and aaroncox committed Aug 22, 2018
1 parent c6e5864 commit 94b2bfa
Showing 4 changed files with 15 additions and 48 deletions.
43 changes: 0 additions & 43 deletions app/shared/actions/delegations.js

This file was deleted.

18 changes: 13 additions & 5 deletions app/shared/actions/stake.js
Original file line number Diff line number Diff line change
@@ -7,20 +7,25 @@ import { delegatebwParams } from './system/delegatebw';
import { undelegatebwParams } from './system/undelegatebw';

import * as AccountActions from './accounts';
import * as DelegationActions from './delegations';
import * as TableActions from './table';
import eos from './helpers/eos';

export function setStake(accountName, netAmount, cpuAmount) {
return (dispatch: () => void, getState) => {
const {
accounts,
connection,
delegations,
tables,
settings
} = getState();

const currentAccount = accounts[settings.account];

const delegations = tables &&
tables.eosio &&
tables.eosio[settings.account] &&
tables.eosio[settings.account].delband.rows;

const {
increaseInStake,
decreaseInStake
@@ -45,6 +50,8 @@ export function setStake(accountName, netAmount, cpuAmount) {
decreaseInStake.cpuAmount
));
}

debugger
}, {
broadcast: connection.broadcast,
expireInSeconds: connection.expireInSeconds,
@@ -54,7 +61,7 @@ export function setStake(accountName, netAmount, cpuAmount) {
if (accountName === settings.account) {
dispatch(AccountActions.getAccount(accountName));
} else {
dispatch(DelegationActions.getDelegations(settings.account));
dispatch(TableActions.getTable('eosio', settings.account, 'delband'));
}
}, 500);

@@ -64,6 +71,7 @@ export function setStake(accountName, netAmount, cpuAmount) {
});
}).catch((err) => {

debugger
dispatch({
payload: { err },
type: types.SYSTEM_STAKE_FAILURE
@@ -84,12 +92,12 @@ function getStakeChanges(currentAccount, accountName, delegations, nextNetAmount
let accountResources;

if (accountName !== currentAccount.account_name) {
const index = findIndex(delegations, { owner: accountName });
const index = findIndex(delegations, { to: accountName });

if (index === -1) {
accountResources = { cpu_weight: '0 EOS', net_weight: '0 EOS' };
} else {
accountResources = currentAccount.total_resources[index];
accountResources = delegations[index];
}
}

1 change: 1 addition & 0 deletions app/shared/components/Tools/Form/Delegation.js
Original file line number Diff line number Diff line change
@@ -77,6 +77,7 @@ class ToolsFormDelegation extends Component<Props> {
<WalletPanelFormStake
account={account}
accountName={accountName}
actions={actions}
balance={balance}
confirming={confirming}
cpuAmount={cpuAmount}
1 change: 1 addition & 0 deletions app/shared/components/Wallet/Panel/Form/Stake.js
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ class WalletPanelFormStake extends Component<Props> {

this.state = {
accountName: account.account_name,
accountNameValid: true,
EOSbalance: (props.balance && props.balance.EOS) ? props.balance.EOS : 0,
decimalCpuAmount: Decimal(parsedCpuWeight),
cpuOriginal: Decimal(parsedCpuWeight),

0 comments on commit 94b2bfa

Please sign in to comment.