migrated promited entries endpoint

This commit is contained in:
Nouman Tahir 2021-07-05 18:41:15 +05:00
parent 8669a4a801
commit 7a4e4e04b0
4 changed files with 44 additions and 20 deletions

View File

@ -2,7 +2,7 @@ import { getAccountPosts, getRankedPosts } from "../../../providers/hive/dhive";
import { filterLatestPosts, getUpdatedPosts } from "./tabbedPostsHelpers";
import Matomo from 'react-native-matomo-sdk';
import { LoadPostsOptions } from "./tabbedPostsModels";
import { getPromotePosts } from "../../../providers/ecency/ecency";
import { getPromotedEntries } from "../../../providers/ecency/ecency";
const POSTS_FETCH_COUNT = 20;
@ -170,9 +170,9 @@ export const loadPosts = async ({
export const getPromotedPosts = async (username:string) => {
export const fetchPromotedEntries = async (username:string) => {
try {
const posts = await getPromotePosts(username);
const posts = await getPromotedEntries(username);
return Array.isArray(posts) ? posts : [];
} catch(err){

View File

@ -1,6 +1,6 @@
import React, {useState, useEffect, useRef} from 'react';
import PostsList from '../../postsList';
import { getPromotedPosts, loadPosts } from '../services/tabbedPostsFetch';
import { fetchPromotedEntries, loadPosts } from '../services/tabbedPostsFetch';
import { LoadPostsOptions, TabContentProps, TabMeta } from '../services/tabbedPostsModels';
import {useSelector, useDispatch } from 'react-redux';
import TabEmptyView from './listEmptyView';
@ -10,6 +10,7 @@ import { calculateTimeLeftForPostCheck } from '../services/tabbedPostsHelpers';
import { AppState } from 'react-native';
import { PostsListRef } from '../../postsList/container/postsListContainer';
const DEFAULT_TAB_META = {
startAuthor:'',
startPermlink:'',
@ -175,7 +176,7 @@ const TabContent = ({
if(pageType === 'profile' || pageType === 'ownProfile'){
return;
}
const pPosts = await getPromotedPosts(username)
const pPosts = await fetchPromotedEntries(username)
if(pPosts){
setPromotedPosts(pPosts)
}

View File

@ -20,8 +20,8 @@ api.interceptors.request.use((request) => {
//skip code addition is register and token refresh endpoint is triggered
if(request.url === '/signup/account-create'
|| request.url === '/auth-api/hs-token-refresh'
|| request.url === '/private-api/promoted-entries'
|| request.url.startsWith('private-api/leaderboard')
){
return request
}

View File

@ -636,6 +636,13 @@ export const uploadImage = (media, username, sign) => {
export const getNodes = () => serverList.get().then((resp) => resp.data.hived || SERVER_LIST);
/**
* refreshes access token using refresh token
* @param code refresh token
* @returns scToken (includes accessToken as property)
*/
export const getSCAccessToken = (code) =>
new Promise((resolve, reject) => {
ecencyApi
@ -649,19 +656,28 @@ export const getSCAccessToken = (code) =>
});
});
export const getPromotePosts = (username) => {
try {
console.log('Fetching promoted posts');
return api.get('/promoted-posts?limit=10').then((resp) => {
return resp.data.map(({ post_data }) =>
post_data ? parsePost(post_data, username, true) : null,
);
});
} catch (error) {
bugsnag.notify(error);
return error;
}
};
/**
* fetches promoted posts for tab content
* @param username for parsing post data
* @returns array of promoted posts
*/
export const getPromotedEntries = async (username:string) => {
try {
console.log('Fetching promoted entries');
return ecencyApi.get('/private-api/promoted-entries').then((resp) => {
return resp.data.map((post_data:any) =>
post_data ? parsePost(post_data, username, true) : null,
);
});
} catch (error) {
console.warn("Failed to get promoted enties")
bugsnag.notify(error);
return error;
}
};
export const purchaseOrder = (data) =>
api
@ -678,7 +694,14 @@ export const getPostReblogs = (data) =>
.catch((error) => bugsnag.notify(error));
/**
* Registers new user with ecency and hive, on confirmation sends
* details to user email
* @param username for new user
* @param email of new user
* @param referral username
* @returns boolean success flag
*/
export const signUp = async (username:string, email:string, referral?:string) => {
try {
const data = {