Fixed transfer amount issue

This commit is contained in:
Mustafa Buyukcelebi 2019-05-05 16:31:38 +03:00
parent fdb2ff95e6
commit 6015b73987
2 changed files with 24 additions and 15 deletions

View File

@ -29,22 +29,30 @@ class TransferContainer extends Component {
// Component Life Cycle Functions // Component Life Cycle Functions
componentDidMount() { componentDidMount() {
const { currentAccount: { name }, navigation } = this.props; const { currentAccount: { name } } = this.props;
const balance = navigation.getParam('balance', ''); this.fetchBalance(name);
this.setState({ balance });
if (!balance) this.fetchBalance(name);
} }
// Component Functions // Component Functions
fetchBalance = (username) => { fetchBalance = (username) => {
const { navigation } = this.props;
const fundType = navigation.getParam('fundType', '');
getAccount(username) getAccount(username)
.then((account) => { .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) }); this.setState({ balance: Number(balance) });
}); });
@ -108,7 +116,7 @@ class TransferContainer extends Component {
render() { render() {
const { const {
accounts, currentAccount, navigation, fetchBalance, accounts, currentAccount, navigation,
} = this.props; } = this.props;
const { balance } = this.state; const { balance } = this.state;
@ -123,6 +131,7 @@ class TransferContainer extends Component {
transferToAccount={this._transferToAccount} transferToAccount={this._transferToAccount}
handleOnModalClose={this._handleOnModalClose} handleOnModalClose={this._handleOnModalClose}
accountType={currentAccount.local.authType} accountType={currentAccount.local.authType}
currentAccountName={currentAccount.name}
balance={balance} balance={balance}
fundType={fundType} fundType={fundType}
transferType={transferType} transferType={transferType}

View File

@ -101,7 +101,7 @@ class TransferView extends Component {
/> />
); );
_renderDropdown = accounts => ( _renderDropdown = (accounts, currentAccountName) => (
<DropdownButton <DropdownButton
dropdownButtonStyle={styles.dropdownButtonStyle} dropdownButtonStyle={styles.dropdownButtonStyle}
rowTextStyle={styles.rowTextStyle} rowTextStyle={styles.rowTextStyle}
@ -109,8 +109,8 @@ class TransferView extends Component {
dropdownStyle={styles.dropdownStyle} dropdownStyle={styles.dropdownStyle}
textStyle={styles.dropdownText} textStyle={styles.dropdownText}
options={accounts.map(item => item.username)} options={accounts.map(item => item.username)}
defaultText={accounts[0].username} defaultText={currentAccountName}
selectedOptionIndex={0} selectedOptionIndex={accounts.findIndex(item => item.username === currentAccountName)}
onSelect={(index, value) => this._handleOnDropdownChange(value)} onSelect={(index, value) => this._handleOnDropdownChange(value)}
/> />
); );
@ -126,7 +126,7 @@ class TransferView extends Component {
render() { render() {
const { const {
accounts, intl, handleOnModalClose, balance, fundType, transferType, accounts, intl, handleOnModalClose, balance, fundType, transferType, currentAccountName,
} = this.props; } = this.props;
const { const {
destination, isUsernameValid, amount, steemConnectTransfer, memo, isTransfering, from, destination, isUsernameValid, amount, steemConnectTransfer, memo, isTransfering, from,
@ -156,7 +156,7 @@ class TransferView extends Component {
<View style={styles.middleContent}> <View style={styles.middleContent}>
<TransferFormItem <TransferFormItem
label={intl.formatMessage({ id: 'transfer.from' })} label={intl.formatMessage({ id: 'transfer.from' })}
rightComponent={() => this._renderDropdown(accounts)} rightComponent={() => this._renderDropdown(accounts, currentAccountName)}
/> />
<TransferFormItem <TransferFormItem
label={intl.formatMessage({ id: 'transfer.to' })} label={intl.formatMessage({ id: 'transfer.to' })}
@ -211,7 +211,7 @@ class TransferView extends Component {
onPress={() => this.ActionSheet.show()} onPress={() => this.ActionSheet.show()}
isLoading={isTransfering} isLoading={isTransfering}
> >
<Text style={styles.buttonText}>NEXT</Text> <Text style={styles.buttonText}>{intl.formatMessage({ id: 'transfer.next' })}</Text>
</MainButton> </MainButton>
</View> </View>
</ScrollView> </ScrollView>