From 8f59d4a52275221bdd504dd6d53bafa919d9cf2b Mon Sep 17 00:00:00 2001 From: u-e Date: Tue, 5 Feb 2019 12:48:25 +0300 Subject: [PATCH] fixed claim bug if already claimed --- .../wallet/container/walletContainer.js | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/components/wallet/container/walletContainer.js b/src/components/wallet/container/walletContainer.js index 7c47c2b0e..62e9b4ebc 100644 --- a/src/components/wallet/container/walletContainer.js +++ b/src/components/wallet/container/walletContainer.js @@ -8,6 +8,7 @@ import { getAccount, claimRewardBalance } from '../../../providers/steem/dsteem' // Utils import { groomingWalletData } from '../../../utils/wallet'; +import parseToken from '../../../utils/parseToken'; // Component import WalletView from '../view/walletView'; @@ -54,9 +55,14 @@ class WalletContainer extends Component { setEstimatedWalletValue(walletData.estimatedValue); }; + _isHasUnclaimedRewards = account => parseToken(account.reward_steem_balance) > 0 + || parseToken(account.reward_sbd_balance) > 0 + || parseToken(account.reward_vesting_steem) > 0; + _claimRewardBalance = async () => { const { currentAccount, intl, pinCode } = this.props; const { isClaiming } = this.state; + let isHasUnclaimedRewards; if (isClaiming) { return; @@ -66,23 +72,28 @@ class WalletContainer extends Component { getAccount(currentAccount.name) .then((account) => { - const { - reward_steem_balance: steemBal, - reward_sbd_balance: sbdBal, - reward_vesting_balance: vestingBal, - } = account[0]; - - return claimRewardBalance(currentAccount, pinCode, steemBal, sbdBal, vestingBal); + isHasUnclaimedRewards = this._isHasUnclaimedRewards(account[0]); + if (isHasUnclaimedRewards) { + const { + reward_steem_balance: steemBal, + reward_sbd_balance: sbdBal, + reward_vesting_balance: vestingBal, + } = account[0]; + return claimRewardBalance(currentAccount, pinCode, steemBal, sbdBal, vestingBal); + } + this.setState({ isClaiming: false }); }) .then(() => getAccount(currentAccount.name)) .then((account) => { this._getWalletData(account && account[0]); - Alert.alert( - intl.formatMessage({ - id: 'alert.claim_reward_balance_ok', - }), - ); + if (isHasUnclaimedRewards) { + Alert.alert( + intl.formatMessage({ + id: 'alert.claim_reward_balance_ok', + }), + ); + } }) .then((account) => { this._getWalletData(account && account[0]);