Merge pull request #1121 from esteemapp/bugfix/general-transfer

fixed transfer issue for steem and points
This commit is contained in:
Mustafa Buyukcelebi 2019-08-30 01:37:31 +03:00 committed by GitHub
commit f0b7b2690e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 20 deletions

View File

@ -1,6 +1,7 @@
import { Component } from 'react'; import { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { injectIntl } from 'react-intl'; import { injectIntl } from 'react-intl';
import get from 'lodash/get';
// Services and Actions // Services and Actions
import { import {
@ -17,6 +18,7 @@ import {
} from '../providers/steem/dsteem'; } from '../providers/steem/dsteem';
import { toastNotification } from '../redux/actions/uiAction'; import { toastNotification } from '../redux/actions/uiAction';
import { getUserDataWithUsername } from '../realm/realm'; import { getUserDataWithUsername } from '../realm/realm';
import { getUser } from '../providers/esteem/ePoint';
// Utils // Utils
import { countDecimals } from '../utils/number'; import { countDecimals } from '../utils/number';
@ -47,11 +49,21 @@ class TransferContainer extends Component {
// Component Functions // Component Functions
_getUserPointsBalance = async username => {
await getUser(username)
.then(userPoints => {
const balance = Math.round(get(userPoints, 'points') * 1000) / 1000;
this.setState({ balance });
})
.catch(err => {
if (err) alert(get(err, 'message') || err.toString());
});
};
fetchBalance = username => { fetchBalance = username => {
const { navigation } = this.props;
const { fundType } = this.state; const { fundType } = this.state;
getAccount(username).then(account => { getAccount(username).then(async account => {
let balance; let balance;
switch (fundType) { switch (fundType) {
case 'STEEM': case 'STEEM':
@ -61,7 +73,7 @@ class TransferContainer extends Component {
balance = account[0].sbd_balance.replace(fundType, ''); balance = account[0].sbd_balance.replace(fundType, '');
break; break;
case 'ESTM': case 'ESTM':
balance = navigation.getParam('balance', ''); this._getUserPointsBalance(username);
break; break;
case 'SAVING_STEEM': case 'SAVING_STEEM':
this.setState({ fundType: 'STEEM' }); this.setState({ fundType: 'STEEM' });
@ -73,13 +85,20 @@ class TransferContainer extends Component {
break; break;
case 'STEEM_POWER': case 'STEEM_POWER':
balance = account[0].balance.replace(fundType, ''); balance = account[0].balance.replace(fundType, '');
this.setState({ selectedAccount: account[0] });
break; break;
default: default:
break; break;
} }
const local = await getUserDataWithUsername(username);
if (balance) {
this.setState({ balance: Number(balance) }); this.setState({ balance: Number(balance) });
}
this.setState({
selectedAccount: { ...account[0], local: local[0] },
});
}); });
}; };
@ -195,8 +214,8 @@ class TransferContainer extends Component {
getAccountsWithUsername: this._getAccountsWithUsername, getAccountsWithUsername: this._getAccountsWithUsername,
transferToAccount: this._transferToAccount, transferToAccount: this._transferToAccount,
handleOnModalClose: this._handleOnModalClose, handleOnModalClose: this._handleOnModalClose,
accountType: currentAccount.local.authType, accountType: get(selectedAccount || currentAccount, 'local.authType'),
currentAccountName: currentAccount.name, currentAccountName: get(currentAccount, 'name'),
setWithdrawVestingRoute: this._setWithdrawVestingRoute, setWithdrawVestingRoute: this._setWithdrawVestingRoute,
}) })
); );

View File

@ -42,6 +42,7 @@ const Transfer = ({ navigation }) => (
handleOnModalClose={handleOnModalClose} handleOnModalClose={handleOnModalClose}
accountType={accountType} accountType={accountType}
currentAccountName={currentAccountName} currentAccountName={currentAccountName}
selectedAccount={selectedAccount}
/> />
); );
case 'delegate': case 'delegate':

View File

@ -2,6 +2,7 @@ import React, { Fragment, Component } from 'react';
import { Text, View, WebView, ScrollView, TouchableOpacity } from 'react-native'; import { Text, View, WebView, ScrollView, TouchableOpacity } from 'react-native';
import ActionSheet from 'react-native-actionsheet'; import ActionSheet from 'react-native-actionsheet';
import { injectIntl } from 'react-intl'; import { injectIntl } from 'react-intl';
import get from 'lodash/get';
import { steemConnectOptions } from '../../../constants/steemConnectOptions'; import { steemConnectOptions } from '../../../constants/steemConnectOptions';
import AUTH_TYPE from '../../../constants/authType'; import AUTH_TYPE from '../../../constants/authType';
@ -133,6 +134,7 @@ class TransferView extends Component {
fundType, fundType,
transferType, transferType,
currentAccountName, currentAccountName,
selectedAccount,
} = this.props; } = this.props;
const { const {
destination, destination,
@ -147,14 +149,15 @@ class TransferView extends Component {
if (transferType === 'points') { if (transferType === 'points') {
const json = JSON.stringify({ const json = JSON.stringify({
sender: accounts[0].username, sender: get(selectedAccount, 'name'),
receiver: destination, receiver: destination,
amount: `${Number(amount).toFixed(3)} ${fundType}`, amount: `${Number(amount).toFixed(3)} ${fundType}`,
memo, memo,
}); });
path = `sign/custom-json?required_auths=%5B%22${ path = `sign/custom-json?authority=active&required_auths=%5B%22${get(
accounts[0].username selectedAccount,
}%22%5D&required_posting_auths=%5B%5D&id=esteem_point_transfer&json=${encodeURIComponent( 'name',
)}%22%5D&required_posting_auths=%5B%5D&id=esteem_point_transfer&json=${encodeURIComponent(
json, json,
)}`; )}`;
} else { } else {
@ -253,6 +256,7 @@ class TransferView extends Component {
index === 0 ? this._handleTransferAction() : null; index === 0 ? this._handleTransferAction() : null;
}} }}
/> />
{path && (
<Modal <Modal
isOpen={steemConnectTransfer} isOpen={steemConnectTransfer}
isFullScreen isFullScreen
@ -262,6 +266,7 @@ class TransferView extends Component {
> >
<WebView source={{ uri: `${steemConnectOptions.base_url}${path}` }} /> <WebView source={{ uri: `${steemConnectOptions.base_url}${path}` }} />
</Modal> </Modal>
)}
</Fragment> </Fragment>
); );
} }