mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 12:51:42 +03:00
Merge pull request #1121 from esteemapp/bugfix/general-transfer
fixed transfer issue for steem and points
This commit is contained in:
commit
f0b7b2690e
@ -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,
|
||||
})
|
||||
);
|
||||
|
@ -42,6 +42,7 @@ const Transfer = ({ navigation }) => (
|
||||
handleOnModalClose={handleOnModalClose}
|
||||
accountType={accountType}
|
||||
currentAccountName={currentAccountName}
|
||||
selectedAccount={selectedAccount}
|
||||
/>
|
||||
);
|
||||
case 'delegate':
|
||||
|
@ -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;
|
||||
}}
|
||||
/>
|
||||
<Modal
|
||||
isOpen={steemConnectTransfer}
|
||||
isFullScreen
|
||||
isCloseButton
|
||||
handleOnModalClose={handleOnModalClose}
|
||||
title={intl.formatMessage({ id: 'transfer.steemconnect_title' })}
|
||||
>
|
||||
<WebView source={{ uri: `${steemConnectOptions.base_url}${path}` }} />
|
||||
</Modal>
|
||||
{path && (
|
||||
<Modal
|
||||
isOpen={steemConnectTransfer}
|
||||
isFullScreen
|
||||
isCloseButton
|
||||
handleOnModalClose={handleOnModalClose}
|
||||
title={intl.formatMessage({ id: 'transfer.steemconnect_title' })}
|
||||
>
|
||||
<WebView source={{ uri: `${steemConnectOptions.base_url}${path}` }} />
|
||||
</Modal>
|
||||
)}
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user