From 6015b73987b593f6c83bffbe5cf49a04f87242a1 Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Sun, 5 May 2019 16:31:38 +0300 Subject: [PATCH] Fixed transfer amount issue --- .../transfer/container/transferContainer.js | 27 ++++++++++++------- src/screens/transfer/screen/transferScreen.js | 12 ++++----- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/screens/transfer/container/transferContainer.js b/src/screens/transfer/container/transferContainer.js index a9cc192eb..dd0339378 100644 --- a/src/screens/transfer/container/transferContainer.js +++ b/src/screens/transfer/container/transferContainer.js @@ -29,22 +29,30 @@ class TransferContainer extends Component { // Component Life Cycle Functions componentDidMount() { - const { currentAccount: { name }, navigation } = this.props; + const { currentAccount: { name } } = this.props; - const balance = navigation.getParam('balance', ''); - - this.setState({ balance }); - - - if (!balance) this.fetchBalance(name); + this.fetchBalance(name); } // Component Functions fetchBalance = (username) => { + const { navigation } = this.props; + const fundType = navigation.getParam('fundType', ''); + getAccount(username) .then((account) => { - const balance = account[0].balance.replace('STEEM', ''); + let balance; + switch (fundType) { + case 'STEEM': + balance = account[0].balance.replace(fundType, ''); + break; + case 'SBD': + balance = account[0].sbd_balance.replace(fundType, ''); + break; + default: + break; + } this.setState({ balance: Number(balance) }); }); @@ -108,7 +116,7 @@ class TransferContainer extends Component { render() { const { - accounts, currentAccount, navigation, fetchBalance, + accounts, currentAccount, navigation, } = this.props; const { balance } = this.state; @@ -123,6 +131,7 @@ class TransferContainer extends Component { transferToAccount={this._transferToAccount} handleOnModalClose={this._handleOnModalClose} accountType={currentAccount.local.authType} + currentAccountName={currentAccount.name} balance={balance} fundType={fundType} transferType={transferType} diff --git a/src/screens/transfer/screen/transferScreen.js b/src/screens/transfer/screen/transferScreen.js index 25ce3093e..d49ce93aa 100644 --- a/src/screens/transfer/screen/transferScreen.js +++ b/src/screens/transfer/screen/transferScreen.js @@ -101,7 +101,7 @@ class TransferView extends Component { /> ); - _renderDropdown = accounts => ( + _renderDropdown = (accounts, currentAccountName) => ( item.username)} - defaultText={accounts[0].username} - selectedOptionIndex={0} + defaultText={currentAccountName} + selectedOptionIndex={accounts.findIndex(item => item.username === currentAccountName)} onSelect={(index, value) => this._handleOnDropdownChange(value)} /> ); @@ -126,7 +126,7 @@ class TransferView extends Component { render() { const { - accounts, intl, handleOnModalClose, balance, fundType, transferType, + accounts, intl, handleOnModalClose, balance, fundType, transferType, currentAccountName, } = this.props; const { destination, isUsernameValid, amount, steemConnectTransfer, memo, isTransfering, from, @@ -156,7 +156,7 @@ class TransferView extends Component { this._renderDropdown(accounts)} + rightComponent={() => this._renderDropdown(accounts, currentAccountName)} /> this.ActionSheet.show()} isLoading={isTransfering} > - NEXT + {intl.formatMessage({ id: 'transfer.next' })}