updated getUser and getPoints implemenation with getPointsSummary and getPointsHistory

This commit is contained in:
noumantahir 2022-05-15 13:39:48 +05:00
parent 7444a17d47
commit 6d5926d60a
9 changed files with 35 additions and 33 deletions

View File

@ -25,7 +25,7 @@ import { useIntl } from 'react-intl';
import { useAppSelector } from '../../../hooks';
import { getUnreadNotificationCount } from '../../../providers/ecency/ecency';
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';
const AccountsBottomSheetContainer = ({ navigation }) => {
@ -104,11 +104,11 @@ const AccountsBottomSheetContainer = ({ navigation }) => {
_currentAccount.local.accessToken = encryptedAccessToken;
_currentAccount.unread_activity_count = await getUnreadNotificationCount(
decryptKey(encryptedAccessToken, getDigitPinCode(pinHash))
);
const accessToken = decryptKey(encryptedAccessToken, getDigitPinCode(pinHash));
_currentAccount.unread_activity_count = await getUnreadNotificationCount(accessToken);
_currentAccount.pointsSummary = await getPointsSummary(_currentAccount.username);
_currentAccount.mutes = await getMutes(_currentAccount.username);
_currentAccount.ecencyUserData = await getEcencyUser(_currentAccount.username);
dispatch(updateCurrentAccount(_currentAccount));
dispatch(fetchSubscribedCommunities(_currentAccount.username))
}

View File

@ -8,7 +8,7 @@ import { Icon, TextInput } from '..';
import { hsOptions } from '../../constants/hsOptions';
// Services and Actions
import { getUser } from '../../providers/ecency/ePoint';
import { getPointsSummary } from '../../providers/ecency/ePoint';
import { searchPath } from '../../providers/ecency/ecency';
// Components
@ -92,7 +92,7 @@ class BoostPostScreen extends PureComponent {
);
_getUserBalance = async (username) => {
await getUser(username)
await getPointsSummary(username)
.then((userPoints) => {
const balance = Math.round(get(userPoints, 'points') * 1000) / 1000;
this.setState({ balance });

View File

@ -8,7 +8,7 @@ import { ScaleSlider, TextInput } from '..';
import { hsOptions } from '../../constants/hsOptions';
// Services and Actions
import { getUser } from '../../providers/ecency/ePoint';
import { getPointsSummary } from '../../providers/ecency/ePoint';
import { searchPath } from '../../providers/ecency/ecency';
// Components
@ -111,7 +111,7 @@ const PromoteView = ({
);
const _getUserBalance = async (username) => {
await getUser(username)
await getPointsSummary(username)
.then((userPoints) => {
const balance = Math.round(get(userPoints, 'points') * 1000) / 1000;
setBalance(balance);

View File

@ -6,7 +6,7 @@ import { useIntl } from 'react-intl';
import { withNavigation } from 'react-navigation';
// 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 { getAccount, boost } from '../providers/hive/dhive';
import { getUserDataWithUsername } from '../realm/realm';
@ -130,7 +130,7 @@ const PointsContainer = ({
}
setRefreshing(true);
await getUser(_username)
await getPointsSummary(_username)
.then(async (userPointsP) => {
const _balance = Math.round(get(userPointsP, 'points') * 1000) / 1000;
setUserPoints(userPointsP);
@ -141,7 +141,7 @@ const PointsContainer = ({
Alert.alert(get(err, 'message', 'Error'));
});
await getUserPoints(_username)
await getPointsHistory(_username)
.then((userActivitiesP) => {
if (Object.entries(userActivitiesP).length !== 0) {
setUserActivities(_groomUserActivities(userActivitiesP));
@ -158,7 +158,7 @@ const PointsContainer = ({
}, []);
const _getUserBalance = async (_username) => {
await getUser(_username)
await getPointsSummary(_username)
.then((_userPoints) => {
const _balance = Math.round(get(_userPoints, 'points') * 1000) / 1000;
return _balance;

View File

@ -19,7 +19,7 @@ import {
} from '../providers/hive/dhive';
import { toastNotification } from '../redux/actions/uiAction';
import { getUserDataWithUsername } from '../realm/realm';
import { getUser } from '../providers/ecency/ePoint';
import { getPointsSummary } from '../providers/ecency/ePoint';
// Utils
import { countDecimals } from '../utils/number';
@ -58,7 +58,7 @@ class TransferContainer extends Component {
// Component Functions
_getUserPointsBalance = async (username) => {
await getUser(username)
await getPointsSummary(username)
.then((userPoints) => {
const balance = Math.round(get(userPoints, 'points') * 1000) / 1000;
this.setState({ balance });

View File

@ -4,7 +4,7 @@ import Config from 'react-native-config';
import get from 'lodash/get';
import { getDigitPinCode, getMutes, getUser } from './dhive';
import { getUser as getEcencyUser } from '../ecency/ePoint';
import { getPointsSummary } from '../ecency/ePoint';
import {
setUserData,
setAuthStatus,
@ -67,11 +67,11 @@ export const login = async (username, password, isPinCodeOpen) => {
const signerPrivateKey = privateKeys.ownerKey || privateKeys.activeKey || privateKeys.postingKey;
const code = await makeHsCode(account.name, signerPrivateKey);
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.ecencyUserData = await getEcencyUser(account.username);
let jsonMetadata;
try {
@ -134,11 +134,10 @@ export const loginWithSC2 = async (code, isPinCodeOpen) => {
let avatar = '';
return new Promise(async (resolve, reject) => {
account.unread_activity_count = await getUnreadNotificationCount(
scTokens ? scTokens.access_token : '',
);
const accessToken = scTokens ? scTokens.access_token : '';
account.unread_activity_count = await getUnreadNotificationCount(accessToken);
account.pointsSummary = await getPointsSummary(account.username);
account.mutes = await getMutes(account.username);
account.ecencyUserData = await getEcencyUser(account.username);
let jsonMetadata;
try {

View File

@ -41,7 +41,7 @@ import {
getTheme,
} from '../../../realm/realm';
import { getUser, getPost, getDigitPinCode, getMutes } from '../../../providers/hive/dhive';
import { getUser as getEcencyUser } from '../../../providers/ecency/ePoint';
import { getPointsSummary } from '../../../providers/ecency/ePoint';
import {
migrateToMasterKeyWithAccessToken,
refreshSCToken,
@ -777,7 +777,7 @@ class ApplicationContainer extends Component {
accountData.unread_activity_count = await getUnreadNotificationCount();
accountData.mutes = await getMutes(realmObject.username);
accountData.ecencyUserData = await getEcencyUser(realmObject.username);
accountData.pointsSummary = await getPointsSummary(realmObject.username);
dispatch(updateCurrentAccount(accountData));
dispatch(fetchSubscribedCommunities(realmObject.username));
this._connectNotificationServer(accountData.name);
@ -956,9 +956,11 @@ class ApplicationContainer extends Component {
//update refresh token
_currentAccount = await this._refreshAccessToken(_currentAccount);
//TODO decrypt access token here;
_currentAccount.unread_activity_count = await getUnreadNotificationCount();
_currentAccount.pointsSummary = await getPointsSummary(_currentAccount.username);
_currentAccount.mutes = await getMutes(_currentAccount.username);
_currentAccount.ecencyUserData = await getEcencyUser(_currentAccount.username);
dispatch(updateCurrentAccount(_currentAccount));
dispatch(fetchSubscribedCommunities(_currentAccount.username));
};

View File

@ -36,7 +36,7 @@ import {
} from '../../../realm/realm';
import { updateCurrentAccount, removeOtherAccount } from '../../../redux/actions/accountAction';
import { getDigitPinCode, getMutes, getUser } from '../../../providers/hive/dhive';
import { getUser as getEcencyUser } from '../../../providers/ecency/ePoint';
import { getPointsSummary } from '../../../providers/ecency/ePoint';
// Utils
import { encryptKey, decryptKey } from '../../../utils/crypto';
@ -320,8 +320,9 @@ class PinCodeContainer extends Component {
//get unread notifications
_currentAccount.unread_activity_count = await getUnreadNotificationCount();
_currentAccount.pointsSummary = await getPointsSummary(_currentAccount.username);
_currentAccount.mutes = await getMutes(_currentAccount.username);
_currentAccount.ecencyUserData = await getEcencyUser(_currentAccount.username);
dispatch(updateCurrentAccount({ ..._currentAccount }));
dispatch(fetchSubscribedCommunities(_currentAccount.username));
dispatch(closePinCodeModal());

View File

@ -7,7 +7,7 @@ import { getCurrencyTokenRate, getLatestQuotes } from '../providers/ecency/ecenc
import { CoinActivitiesCollection, CoinActivity, CoinBase, CoinData, DataPair, QuoteItem } from '../redux/reducers/walletReducer';
import { GlobalProps } from '../redux/reducers/accountReducer';
import { getEstimatedAmount } from './vote';
import { getUser as getEcencyUser, getUserPoints } from '../providers/ecency/ePoint';
import { getPointsSummary, getUserPoints } from '../providers/ecency/ePoint';
// Constant
import POINTS from '../constants/options/points';
import { COIN_IDS } from '../constants/defaultCoins';
@ -530,7 +530,7 @@ export const fetchCoinsData = async ({
//TODO: Use already available accoutn for frist wallet start
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
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) {
case COIN_IDS.ECENCY: {
const balance = _ecencyUserData.points ? parseFloat(_ecencyUserData.points) : 0;
const unclaimedFloat = parseFloat(_ecencyUserData.unclaimed_points || '0');
const balance = _pointsSummary.points ? parseFloat(_pointsSummary.points) : 0;
const unclaimedFloat = parseFloat(_pointsSummary.unclaimed_points || '0');
const unclaimedBalance = unclaimedFloat ? unclaimedFloat + ' Points' : '';
const ppEstm = _prices[coinBase.id].price;