diff --git a/src/containers/transferContainer.js b/src/containers/transferContainer.js
index 7d995b94a..e4562c6b0 100644
--- a/src/containers/transferContainer.js
+++ b/src/containers/transferContainer.js
@@ -1,6 +1,7 @@
import { Component } from 'react';
import { connect } from 'react-redux';
import { injectIntl } from 'react-intl';
+import get from 'lodash/get';
// Services and Actions
import {
@@ -17,6 +18,7 @@ import {
} from '../providers/steem/dsteem';
import { toastNotification } from '../redux/actions/uiAction';
import { getUserDataWithUsername } from '../realm/realm';
+import { getUser } from '../providers/esteem/ePoint';
// Utils
import { countDecimals } from '../utils/number';
@@ -47,11 +49,21 @@ class TransferContainer extends Component {
// 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 => {
- const { navigation } = this.props;
const { fundType } = this.state;
- getAccount(username).then(account => {
+ getAccount(username).then(async account => {
let balance;
switch (fundType) {
case 'STEEM':
@@ -61,7 +73,7 @@ class TransferContainer extends Component {
balance = account[0].sbd_balance.replace(fundType, '');
break;
case 'ESTM':
- balance = navigation.getParam('balance', '');
+ this._getUserPointsBalance(username);
break;
case 'SAVING_STEEM':
this.setState({ fundType: 'STEEM' });
@@ -73,13 +85,20 @@ class TransferContainer extends Component {
break;
case 'STEEM_POWER':
balance = account[0].balance.replace(fundType, '');
- this.setState({ selectedAccount: account[0] });
break;
default:
break;
}
- this.setState({ balance: Number(balance) });
+ const local = await getUserDataWithUsername(username);
+
+ if (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,
transferToAccount: this._transferToAccount,
handleOnModalClose: this._handleOnModalClose,
- accountType: currentAccount.local.authType,
- currentAccountName: currentAccount.name,
+ accountType: get(selectedAccount || currentAccount, 'local.authType'),
+ currentAccountName: get(currentAccount, 'name'),
setWithdrawVestingRoute: this._setWithdrawVestingRoute,
})
);
diff --git a/src/screens/transfer/index.js b/src/screens/transfer/index.js
index e27a32480..26219f5d9 100644
--- a/src/screens/transfer/index.js
+++ b/src/screens/transfer/index.js
@@ -42,6 +42,7 @@ const Transfer = ({ navigation }) => (
handleOnModalClose={handleOnModalClose}
accountType={accountType}
currentAccountName={currentAccountName}
+ selectedAccount={selectedAccount}
/>
);
case 'delegate':
diff --git a/src/screens/transfer/screen/transferScreen.js b/src/screens/transfer/screen/transferScreen.js
index 963db2df2..068b958f9 100644
--- a/src/screens/transfer/screen/transferScreen.js
+++ b/src/screens/transfer/screen/transferScreen.js
@@ -2,6 +2,7 @@ import React, { Fragment, Component } from 'react';
import { Text, View, WebView, ScrollView, TouchableOpacity } from 'react-native';
import ActionSheet from 'react-native-actionsheet';
import { injectIntl } from 'react-intl';
+import get from 'lodash/get';
import { steemConnectOptions } from '../../../constants/steemConnectOptions';
import AUTH_TYPE from '../../../constants/authType';
@@ -133,6 +134,7 @@ class TransferView extends Component {
fundType,
transferType,
currentAccountName,
+ selectedAccount,
} = this.props;
const {
destination,
@@ -147,14 +149,15 @@ class TransferView extends Component {
if (transferType === 'points') {
const json = JSON.stringify({
- sender: accounts[0].username,
+ sender: get(selectedAccount, 'name'),
receiver: destination,
amount: `${Number(amount).toFixed(3)} ${fundType}`,
memo,
});
- path = `sign/custom-json?required_auths=%5B%22${
- accounts[0].username
- }%22%5D&required_posting_auths=%5B%5D&id=esteem_point_transfer&json=${encodeURIComponent(
+ path = `sign/custom-json?authority=active&required_auths=%5B%22${get(
+ selectedAccount,
+ 'name',
+ )}%22%5D&required_posting_auths=%5B%5D&id=esteem_point_transfer&json=${encodeURIComponent(
json,
)}`;
} else {
@@ -253,15 +256,17 @@ class TransferView extends Component {
index === 0 ? this._handleTransferAction() : null;
}}
/>
-
-
-
+ {path && (
+
+
+
+ )}
);
}