Skip to content

Commit

Permalink
Fix transfer fee not getting set properly fix bitshares#409
Browse files Browse the repository at this point in the history
  • Loading branch information
svk31 committed Sep 15, 2017
1 parent 37f631c commit bd63b81
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions app/components/Transfer/Transfer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Transfer extends React.Component {
componentWillMount() {
this.nestedRef = null;
this._updateFee();
this._checkFeeStatus();
}

shouldComponentUpdate(np, ns) {
Expand Down Expand Up @@ -117,7 +118,7 @@ class Transfer extends React.Component {
let balanceObject = ChainStore.getObject(balanceID);
let feeBalanceObject = feeBalanceID ? ChainStore.getObject(feeBalanceID) : null;
if (!feeBalanceObject || feeBalanceObject.get("balance") === 0) {
this._updateFee("1.3.0");
this.setState({fee_asset_id: "1.3.0"}, this._updateFee);
}
const hasBalance = checkBalance(amount, asset, feeAmount, balanceObject);
if (hasBalance === null) return;
Expand All @@ -127,7 +128,7 @@ class Transfer extends React.Component {
_checkFeeStatus(account = this.state.from_account) {
if (!account) return;

const assets = Object.keys(this.state.from_account.get("balances").toJS()).sort(utils.sortID);
const assets = Object.keys(account.get("balances").toJS()).sort(utils.sortID);
let feeStatus = {};
let p = [];
assets.forEach(a => {
Expand Down Expand Up @@ -156,15 +157,20 @@ class Transfer extends React.Component {
});
}

_updateFee(fee_asset_id = this.state.fee_asset_id) {
if (!this.state.from_account) return null;
_updateFee(state = this.state) {
let { fee_asset_id, from_account } = state;
const { fee_asset_types } = this._getAvailableAssets(state);
if ( fee_asset_types.length === 1 && fee_asset_types[0] !== fee_asset_id) {
fee_asset_id = fee_asset_types[0];
}
if (!from_account) return null;
checkFeeStatusAsync({
accountID: this.state.from_account.get("id"),
accountID: from_account.get("id"),
feeID: fee_asset_id,
options: ["price_per_kbyte"],
data: {
type: "memo",
content: this.state.memo
content: state.memo
}
})
.then(({fee, hasBalance, hasPoolBalance}) => {
Expand All @@ -174,7 +180,7 @@ class Transfer extends React.Component {
hasBalance,
hasPoolBalance,
error: (!hasBalance || !hasPoolBalance)
}, this._checkFeeStatus);
});
});
}

Expand All @@ -188,7 +194,7 @@ class Transfer extends React.Component {
}

onFromAccountChanged(from_account) {
this.setState({from_account, error: null}, this._updateFee);
this.setState({from_account, error: null}, () => {this._updateFee(); this._checkFeeStatus();});
}

onToAccountChanged(to_account) {
Expand Down

0 comments on commit bd63b81

Please sign in to comment.