mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-24 13:53:23 +03:00
updated getUser and getPoints implemenation with getPointsSummary and getPointsHistory
This commit is contained in:
parent
7444a17d47
commit
6d5926d60a
@ -25,7 +25,7 @@ import { useIntl } from 'react-intl';
|
|||||||
import { useAppSelector } from '../../../hooks';
|
import { useAppSelector } from '../../../hooks';
|
||||||
import { getUnreadNotificationCount } from '../../../providers/ecency/ecency';
|
import { getUnreadNotificationCount } from '../../../providers/ecency/ecency';
|
||||||
import { decryptKey } from '../../../utils/crypto';
|
import { decryptKey } from '../../../utils/crypto';
|
||||||
import { getUser as getEcencyUser} from '../../../providers/ecency/ePoint';
|
import { getPointsSummary} from '../../../providers/ecency/ePoint';
|
||||||
import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAction';
|
import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAction';
|
||||||
|
|
||||||
const AccountsBottomSheetContainer = ({ navigation }) => {
|
const AccountsBottomSheetContainer = ({ navigation }) => {
|
||||||
@ -104,11 +104,11 @@ const AccountsBottomSheetContainer = ({ navigation }) => {
|
|||||||
|
|
||||||
_currentAccount.local.accessToken = encryptedAccessToken;
|
_currentAccount.local.accessToken = encryptedAccessToken;
|
||||||
|
|
||||||
_currentAccount.unread_activity_count = await getUnreadNotificationCount(
|
const accessToken = decryptKey(encryptedAccessToken, getDigitPinCode(pinHash));
|
||||||
decryptKey(encryptedAccessToken, getDigitPinCode(pinHash))
|
_currentAccount.unread_activity_count = await getUnreadNotificationCount(accessToken);
|
||||||
);
|
_currentAccount.pointsSummary = await getPointsSummary(_currentAccount.username);
|
||||||
_currentAccount.mutes = await getMutes(_currentAccount.username);
|
_currentAccount.mutes = await getMutes(_currentAccount.username);
|
||||||
_currentAccount.ecencyUserData = await getEcencyUser(_currentAccount.username);
|
|
||||||
dispatch(updateCurrentAccount(_currentAccount));
|
dispatch(updateCurrentAccount(_currentAccount));
|
||||||
dispatch(fetchSubscribedCommunities(_currentAccount.username))
|
dispatch(fetchSubscribedCommunities(_currentAccount.username))
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import { Icon, TextInput } from '..';
|
|||||||
import { hsOptions } from '../../constants/hsOptions';
|
import { hsOptions } from '../../constants/hsOptions';
|
||||||
|
|
||||||
// Services and Actions
|
// Services and Actions
|
||||||
import { getUser } from '../../providers/ecency/ePoint';
|
import { getPointsSummary } from '../../providers/ecency/ePoint';
|
||||||
import { searchPath } from '../../providers/ecency/ecency';
|
import { searchPath } from '../../providers/ecency/ecency';
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
@ -92,7 +92,7 @@ class BoostPostScreen extends PureComponent {
|
|||||||
);
|
);
|
||||||
|
|
||||||
_getUserBalance = async (username) => {
|
_getUserBalance = async (username) => {
|
||||||
await getUser(username)
|
await getPointsSummary(username)
|
||||||
.then((userPoints) => {
|
.then((userPoints) => {
|
||||||
const balance = Math.round(get(userPoints, 'points') * 1000) / 1000;
|
const balance = Math.round(get(userPoints, 'points') * 1000) / 1000;
|
||||||
this.setState({ balance });
|
this.setState({ balance });
|
||||||
|
@ -8,7 +8,7 @@ import { ScaleSlider, TextInput } from '..';
|
|||||||
import { hsOptions } from '../../constants/hsOptions';
|
import { hsOptions } from '../../constants/hsOptions';
|
||||||
|
|
||||||
// Services and Actions
|
// Services and Actions
|
||||||
import { getUser } from '../../providers/ecency/ePoint';
|
import { getPointsSummary } from '../../providers/ecency/ePoint';
|
||||||
import { searchPath } from '../../providers/ecency/ecency';
|
import { searchPath } from '../../providers/ecency/ecency';
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
@ -111,7 +111,7 @@ const PromoteView = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const _getUserBalance = async (username) => {
|
const _getUserBalance = async (username) => {
|
||||||
await getUser(username)
|
await getPointsSummary(username)
|
||||||
.then((userPoints) => {
|
.then((userPoints) => {
|
||||||
const balance = Math.round(get(userPoints, 'points') * 1000) / 1000;
|
const balance = Math.round(get(userPoints, 'points') * 1000) / 1000;
|
||||||
setBalance(balance);
|
setBalance(balance);
|
||||||
|
@ -6,7 +6,7 @@ import { useIntl } from 'react-intl';
|
|||||||
import { withNavigation } from 'react-navigation';
|
import { withNavigation } from 'react-navigation';
|
||||||
|
|
||||||
// Services and Actions
|
// Services and Actions
|
||||||
import { getUser, getUserPoints, claimPoints } from '../providers/ecency/ePoint';
|
import { getPointsSummary, claimPoints, getPointsHistory } from '../providers/ecency/ePoint';
|
||||||
import { openPinCodeModal } from '../redux/actions/applicationActions';
|
import { openPinCodeModal } from '../redux/actions/applicationActions';
|
||||||
import { getAccount, boost } from '../providers/hive/dhive';
|
import { getAccount, boost } from '../providers/hive/dhive';
|
||||||
import { getUserDataWithUsername } from '../realm/realm';
|
import { getUserDataWithUsername } from '../realm/realm';
|
||||||
@ -130,7 +130,7 @@ const PointsContainer = ({
|
|||||||
}
|
}
|
||||||
setRefreshing(true);
|
setRefreshing(true);
|
||||||
|
|
||||||
await getUser(_username)
|
await getPointsSummary(_username)
|
||||||
.then(async (userPointsP) => {
|
.then(async (userPointsP) => {
|
||||||
const _balance = Math.round(get(userPointsP, 'points') * 1000) / 1000;
|
const _balance = Math.round(get(userPointsP, 'points') * 1000) / 1000;
|
||||||
setUserPoints(userPointsP);
|
setUserPoints(userPointsP);
|
||||||
@ -141,7 +141,7 @@ const PointsContainer = ({
|
|||||||
Alert.alert(get(err, 'message', 'Error'));
|
Alert.alert(get(err, 'message', 'Error'));
|
||||||
});
|
});
|
||||||
|
|
||||||
await getUserPoints(_username)
|
await getPointsHistory(_username)
|
||||||
.then((userActivitiesP) => {
|
.then((userActivitiesP) => {
|
||||||
if (Object.entries(userActivitiesP).length !== 0) {
|
if (Object.entries(userActivitiesP).length !== 0) {
|
||||||
setUserActivities(_groomUserActivities(userActivitiesP));
|
setUserActivities(_groomUserActivities(userActivitiesP));
|
||||||
@ -158,7 +158,7 @@ const PointsContainer = ({
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const _getUserBalance = async (_username) => {
|
const _getUserBalance = async (_username) => {
|
||||||
await getUser(_username)
|
await getPointsSummary(_username)
|
||||||
.then((_userPoints) => {
|
.then((_userPoints) => {
|
||||||
const _balance = Math.round(get(_userPoints, 'points') * 1000) / 1000;
|
const _balance = Math.round(get(_userPoints, 'points') * 1000) / 1000;
|
||||||
return _balance;
|
return _balance;
|
||||||
|
@ -19,7 +19,7 @@ import {
|
|||||||
} from '../providers/hive/dhive';
|
} from '../providers/hive/dhive';
|
||||||
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/ecency/ePoint';
|
import { getPointsSummary } from '../providers/ecency/ePoint';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { countDecimals } from '../utils/number';
|
import { countDecimals } from '../utils/number';
|
||||||
@ -58,7 +58,7 @@ class TransferContainer extends Component {
|
|||||||
// Component Functions
|
// Component Functions
|
||||||
|
|
||||||
_getUserPointsBalance = async (username) => {
|
_getUserPointsBalance = async (username) => {
|
||||||
await getUser(username)
|
await getPointsSummary(username)
|
||||||
.then((userPoints) => {
|
.then((userPoints) => {
|
||||||
const balance = Math.round(get(userPoints, 'points') * 1000) / 1000;
|
const balance = Math.round(get(userPoints, 'points') * 1000) / 1000;
|
||||||
this.setState({ balance });
|
this.setState({ balance });
|
||||||
|
@ -4,7 +4,7 @@ import Config from 'react-native-config';
|
|||||||
import get from 'lodash/get';
|
import get from 'lodash/get';
|
||||||
|
|
||||||
import { getDigitPinCode, getMutes, getUser } from './dhive';
|
import { getDigitPinCode, getMutes, getUser } from './dhive';
|
||||||
import { getUser as getEcencyUser } from '../ecency/ePoint';
|
import { getPointsSummary } from '../ecency/ePoint';
|
||||||
import {
|
import {
|
||||||
setUserData,
|
setUserData,
|
||||||
setAuthStatus,
|
setAuthStatus,
|
||||||
@ -67,11 +67,11 @@ export const login = async (username, password, isPinCodeOpen) => {
|
|||||||
const signerPrivateKey = privateKeys.ownerKey || privateKeys.activeKey || privateKeys.postingKey;
|
const signerPrivateKey = privateKeys.ownerKey || privateKeys.activeKey || privateKeys.postingKey;
|
||||||
const code = await makeHsCode(account.name, signerPrivateKey);
|
const code = await makeHsCode(account.name, signerPrivateKey);
|
||||||
const scTokens = await getSCAccessToken(code);
|
const scTokens = await getSCAccessToken(code);
|
||||||
account.unread_activity_count = await getUnreadNotificationCount(
|
|
||||||
scTokens ? scTokens.access_token : '',
|
const accessToken = scTokens?.access_token;
|
||||||
);
|
account.unread_activity_count = await getUnreadNotificationCount(accessToken);
|
||||||
|
account.pointsSummary = await getPointsSummary(account.username);
|
||||||
account.mutes = await getMutes(account.username);
|
account.mutes = await getMutes(account.username);
|
||||||
account.ecencyUserData = await getEcencyUser(account.username);
|
|
||||||
|
|
||||||
let jsonMetadata;
|
let jsonMetadata;
|
||||||
try {
|
try {
|
||||||
@ -134,11 +134,10 @@ export const loginWithSC2 = async (code, isPinCodeOpen) => {
|
|||||||
let avatar = '';
|
let avatar = '';
|
||||||
|
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
account.unread_activity_count = await getUnreadNotificationCount(
|
const accessToken = scTokens ? scTokens.access_token : '';
|
||||||
scTokens ? scTokens.access_token : '',
|
account.unread_activity_count = await getUnreadNotificationCount(accessToken);
|
||||||
);
|
account.pointsSummary = await getPointsSummary(account.username);
|
||||||
account.mutes = await getMutes(account.username);
|
account.mutes = await getMutes(account.username);
|
||||||
account.ecencyUserData = await getEcencyUser(account.username);
|
|
||||||
|
|
||||||
let jsonMetadata;
|
let jsonMetadata;
|
||||||
try {
|
try {
|
||||||
|
@ -41,7 +41,7 @@ import {
|
|||||||
getTheme,
|
getTheme,
|
||||||
} from '../../../realm/realm';
|
} from '../../../realm/realm';
|
||||||
import { getUser, getPost, getDigitPinCode, getMutes } from '../../../providers/hive/dhive';
|
import { getUser, getPost, getDigitPinCode, getMutes } from '../../../providers/hive/dhive';
|
||||||
import { getUser as getEcencyUser } from '../../../providers/ecency/ePoint';
|
import { getPointsSummary } from '../../../providers/ecency/ePoint';
|
||||||
import {
|
import {
|
||||||
migrateToMasterKeyWithAccessToken,
|
migrateToMasterKeyWithAccessToken,
|
||||||
refreshSCToken,
|
refreshSCToken,
|
||||||
@ -777,7 +777,7 @@ class ApplicationContainer extends Component {
|
|||||||
|
|
||||||
accountData.unread_activity_count = await getUnreadNotificationCount();
|
accountData.unread_activity_count = await getUnreadNotificationCount();
|
||||||
accountData.mutes = await getMutes(realmObject.username);
|
accountData.mutes = await getMutes(realmObject.username);
|
||||||
accountData.ecencyUserData = await getEcencyUser(realmObject.username);
|
accountData.pointsSummary = await getPointsSummary(realmObject.username);
|
||||||
dispatch(updateCurrentAccount(accountData));
|
dispatch(updateCurrentAccount(accountData));
|
||||||
dispatch(fetchSubscribedCommunities(realmObject.username));
|
dispatch(fetchSubscribedCommunities(realmObject.username));
|
||||||
this._connectNotificationServer(accountData.name);
|
this._connectNotificationServer(accountData.name);
|
||||||
@ -956,9 +956,11 @@ class ApplicationContainer extends Component {
|
|||||||
//update refresh token
|
//update refresh token
|
||||||
_currentAccount = await this._refreshAccessToken(_currentAccount);
|
_currentAccount = await this._refreshAccessToken(_currentAccount);
|
||||||
|
|
||||||
|
//TODO decrypt access token here;
|
||||||
_currentAccount.unread_activity_count = await getUnreadNotificationCount();
|
_currentAccount.unread_activity_count = await getUnreadNotificationCount();
|
||||||
|
_currentAccount.pointsSummary = await getPointsSummary(_currentAccount.username);
|
||||||
_currentAccount.mutes = await getMutes(_currentAccount.username);
|
_currentAccount.mutes = await getMutes(_currentAccount.username);
|
||||||
_currentAccount.ecencyUserData = await getEcencyUser(_currentAccount.username);
|
|
||||||
dispatch(updateCurrentAccount(_currentAccount));
|
dispatch(updateCurrentAccount(_currentAccount));
|
||||||
dispatch(fetchSubscribedCommunities(_currentAccount.username));
|
dispatch(fetchSubscribedCommunities(_currentAccount.username));
|
||||||
};
|
};
|
||||||
|
@ -36,7 +36,7 @@ import {
|
|||||||
} from '../../../realm/realm';
|
} from '../../../realm/realm';
|
||||||
import { updateCurrentAccount, removeOtherAccount } from '../../../redux/actions/accountAction';
|
import { updateCurrentAccount, removeOtherAccount } from '../../../redux/actions/accountAction';
|
||||||
import { getDigitPinCode, getMutes, getUser } from '../../../providers/hive/dhive';
|
import { getDigitPinCode, getMutes, getUser } from '../../../providers/hive/dhive';
|
||||||
import { getUser as getEcencyUser } from '../../../providers/ecency/ePoint';
|
import { getPointsSummary } from '../../../providers/ecency/ePoint';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { encryptKey, decryptKey } from '../../../utils/crypto';
|
import { encryptKey, decryptKey } from '../../../utils/crypto';
|
||||||
@ -320,8 +320,9 @@ class PinCodeContainer extends Component {
|
|||||||
|
|
||||||
//get unread notifications
|
//get unread notifications
|
||||||
_currentAccount.unread_activity_count = await getUnreadNotificationCount();
|
_currentAccount.unread_activity_count = await getUnreadNotificationCount();
|
||||||
|
_currentAccount.pointsSummary = await getPointsSummary(_currentAccount.username);
|
||||||
_currentAccount.mutes = await getMutes(_currentAccount.username);
|
_currentAccount.mutes = await getMutes(_currentAccount.username);
|
||||||
_currentAccount.ecencyUserData = await getEcencyUser(_currentAccount.username);
|
|
||||||
dispatch(updateCurrentAccount({ ..._currentAccount }));
|
dispatch(updateCurrentAccount({ ..._currentAccount }));
|
||||||
dispatch(fetchSubscribedCommunities(_currentAccount.username));
|
dispatch(fetchSubscribedCommunities(_currentAccount.username));
|
||||||
dispatch(closePinCodeModal());
|
dispatch(closePinCodeModal());
|
||||||
|
@ -7,7 +7,7 @@ import { getCurrencyTokenRate, getLatestQuotes } from '../providers/ecency/ecenc
|
|||||||
import { CoinActivitiesCollection, CoinActivity, CoinBase, CoinData, DataPair, QuoteItem } from '../redux/reducers/walletReducer';
|
import { CoinActivitiesCollection, CoinActivity, CoinBase, CoinData, DataPair, QuoteItem } from '../redux/reducers/walletReducer';
|
||||||
import { GlobalProps } from '../redux/reducers/accountReducer';
|
import { GlobalProps } from '../redux/reducers/accountReducer';
|
||||||
import { getEstimatedAmount } from './vote';
|
import { getEstimatedAmount } from './vote';
|
||||||
import { getUser as getEcencyUser, getUserPoints } from '../providers/ecency/ePoint';
|
import { getPointsSummary, getUserPoints } from '../providers/ecency/ePoint';
|
||||||
// Constant
|
// Constant
|
||||||
import POINTS from '../constants/options/points';
|
import POINTS from '../constants/options/points';
|
||||||
import { COIN_IDS } from '../constants/defaultCoins';
|
import { COIN_IDS } from '../constants/defaultCoins';
|
||||||
@ -530,7 +530,7 @@ export const fetchCoinsData = async ({
|
|||||||
|
|
||||||
//TODO: Use already available accoutn for frist wallet start
|
//TODO: Use already available accoutn for frist wallet start
|
||||||
const userdata = refresh ? await getAccount(username) : currentAccount;
|
const userdata = refresh ? await getAccount(username) : currentAccount;
|
||||||
const _ecencyUserData = refresh ? await getEcencyUser(username) : currentAccount.ecencyUserData
|
const _pointsSummary = refresh ? await getPointsSummary(username) : currentAccount.pointsSummary
|
||||||
//TODO: cache data in redux or fetch once on wallet startup
|
//TODO: cache data in redux or fetch once on wallet startup
|
||||||
const _prices = !refresh && quotes ? quotes : await getLatestQuotes(currencyRate); //TODO: figure out a way to handle other currencies
|
const _prices = !refresh && quotes ? quotes : await getLatestQuotes(currencyRate); //TODO: figure out a way to handle other currencies
|
||||||
|
|
||||||
@ -539,8 +539,8 @@ export const fetchCoinsData = async ({
|
|||||||
|
|
||||||
switch (coinBase.id) {
|
switch (coinBase.id) {
|
||||||
case COIN_IDS.ECENCY: {
|
case COIN_IDS.ECENCY: {
|
||||||
const balance = _ecencyUserData.points ? parseFloat(_ecencyUserData.points) : 0;
|
const balance = _pointsSummary.points ? parseFloat(_pointsSummary.points) : 0;
|
||||||
const unclaimedFloat = parseFloat(_ecencyUserData.unclaimed_points || '0');
|
const unclaimedFloat = parseFloat(_pointsSummary.unclaimed_points || '0');
|
||||||
const unclaimedBalance = unclaimedFloat ? unclaimedFloat + ' Points' : '';
|
const unclaimedBalance = unclaimedFloat ? unclaimedFloat + ' Points' : '';
|
||||||
const ppEstm = _prices[coinBase.id].price;
|
const ppEstm = _prices[coinBase.id].price;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user