Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passing access token as param to announcement query if available #2868

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/providers/ecency/ecency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,9 +964,12 @@ export const getCommentHistory = async (
}
};

export const getAnnouncements = async () => {
export const getAnnouncements = async (accessToken: string) => {
try {
const res = await ecencyApi.get('/private-api/announcements');

const params = accessToken ? { code:accessToken } : null

const res = await ecencyApi.get('/private-api/announcements', { params });
console.log('announcements fetcehd', res.data);
if (!res.data) {
throw new Error('No announcements found!');
Expand Down
15 changes: 12 additions & 3 deletions src/providers/queries/announcementsQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,29 @@ import { handleDeepLink, showActionModal } from '../../redux/actions/uiAction';
import { getPostUrl } from '../../utils/post';
import { delay } from '../../utils/editor';
import parseVersionNumber from '../../utils/parseVersionNumber';
import { decryptKey } from '../../utils/crypto';
import { getDigitPinCode } from '../hive/dhive';

const PROMPT_AGAIN_INTERVAL = 48 * 3600 * 1000; // 2 days

export const useAnnouncementsQuery = () => {
const intl = useIntl();
const dispatch = useDispatch();

const pinHash = useAppSelector((state) => state.application.pin);

const lastAppVersion = useAppSelector((state) => state.application.lastAppVersion);
const appVersion = useMemo(() => VersionNumber.appVersion, [])

const currentAccount = useAppSelector((state) => state.account.currentAccount);
const announcementsMeta = useAppSelector((state) => state.cache.announcementsMeta);

const announcmentsQuery = useQuery([QUERIES.ANNOUNCEMENTS.GET], getAnnouncements);

const announcmentsQuery = useQuery([QUERIES.ANNOUNCEMENTS.GET], () => {
const encToken = currentAccount?.local?.accessToken;
const token = !!encToken && decryptKey(encToken, getDigitPinCode(pinHash));
return getAnnouncements(token)
});


useEffect(() => {
Expand All @@ -38,8 +46,8 @@ export const useAnnouncementsQuery = () => {
}

//bypass if logged in user is required for announcement, skip otherwise
const firstAnnounce = announcmentsQuery.data[0];
if (firstAnnounce.auth && !currentAccount?.username) {
const firstAnnounce = announcementsMeta.data && announcmentsQuery.data[0];
if (!firstAnnounce || (firstAnnounce?.auth && !currentAccount?.username)) {
return;
}

Expand Down Expand Up @@ -101,3 +109,4 @@ export const useAnnouncementsQuery = () => {
);
};
};