Skip to content

Commit

Permalink
Merge pull request #62 from ecency/bugfix/sentry-issues-02
Browse files Browse the repository at this point in the history
bugfix/sentry-issues-02
  • Loading branch information
feruzm authored Oct 6, 2024
2 parents 15c1e42 + 50e27ca commit cd4ce7d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 31 deletions.
36 changes: 16 additions & 20 deletions src/api/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const dataLimit = typeof window !== "undefined" && window.screen.width <
export const bridgeApiCall = <T>(endpoint: string, params: {}): Promise<T> =>
bridgeServer.call("bridge", endpoint, params);

export const resolvePost = (post: Entry, observer: string, num?: number): Promise<Entry> => {
export const resolvePost = async (post: Entry, observer: string, num?: number): Promise<Entry> => {
const { json_metadata: json } = post;

if (
Expand All @@ -21,26 +21,22 @@ export const resolvePost = (post: Entry, observer: string, num?: number): Promis
json.tags &&
json.tags[0] === "cross-post"
) {
return getPost(json.original_author, json.original_permlink, observer, num)
.then((resp) => {
if (resp) {
return {
...post,
original_entry: resp,
num
};
}

return post;
})
.catch(() => {
return post;
});
try {
const resp = await getPost(json.original_author, json.original_permlink, observer, num);
if (resp) {
return {
...post,
original_entry: resp,
num
};
}
return post;
} catch (e) {
return post;
}
}

return new Promise((resolve) => {
resolve({ ...post, num });
});
return { ...post, num };
};

const resolvePosts = (posts: Entry[], observer: string): Promise<Entry[]> => {
Expand Down Expand Up @@ -110,7 +106,7 @@ export const getPost = async (
});

if (resp) {
return await resolvePost(resp, observer, num);
return resolvePost(resp, observer, num);
}

return undefined;
Expand Down
3 changes: 2 additions & 1 deletion src/api/mutations/entry-vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export function useEntryVote(entry?: Entry) {
}

await vote(activeUser?.username, entry.author, entry.permlink, weight);
updateActiveUser(); // refresh voting power

return [
estimated,
Expand All @@ -39,6 +38,8 @@ export function useEntryVote(entry?: Entry) {
] as const;
},
onSuccess: ([estimated, votes]) => {
updateActiveUser(); // refresh voting power

if (!entry) {
throw new Error("No entry provided");
}
Expand Down
14 changes: 10 additions & 4 deletions src/api/queries/get-account-vote-history-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getDays = (createdDate: string): number => {

export const getAccountVoteHistoryQuery = <F>(username: string, filters: F[] = [], limit = 20) =>
EcencyQueriesManager.generateClientServerInfiniteQuery({
queryKey: [QueryIdentifiers.ACCOUNT_VOTES_HISTORY],
queryKey: [QueryIdentifiers.ACCOUNT_VOTES_HISTORY, username],
queryFn: async ({ pageParam: { start } }) => {
const response = await client.call("condenser_api", "get_account_history", [
username,
Expand All @@ -34,9 +34,15 @@ export const getAccountVoteHistoryQuery = <F>(username: string, filters: F[] = [
filtered.weight != 0 &&
getDays(filtered.timestamp) <= days
);
const entries = await Promise.all<Entry[]>(
result.map((obj: any) => getPostQuery(obj.author, obj.permlink).prefetch())
);
const entries: Entry[] = [];

for (const obj of result) {
const post = await getPostQuery(obj.author, obj.permlink).fetchAndGet();
if (post) {
entries.push(post);
}
}

return {
lastDate: getDays(response[0][1].timestamp),
lastItemFetched: response[0][0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ export function EntryFooterControls({ entry }: Props) {
useDistanceDetector(ref, showProfileBox, showWordCount, setShowProfileBox, setShowWordCount);

return (
<div className="entry-controls text-sm flex-wrap gap-4" ref={ref}>
<div className="flex items-center gap-2">
<div
className="entry-controls text-sm flex-wrap gap-4 [&_.entry-tip-btn]:mr-0 [&_.entry-reblog-btn]:!mr-0"
ref={ref}
>
<div className="flex items-center gap-4">
<EntryVoteBtn isPostSlider={true} entry={entry} />
<EntryPayout entry={entry} />
<EntryVotes entry={entry} />
Expand Down
10 changes: 8 additions & 2 deletions src/app/_components/top-communities-widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import { getCommunitiesQuery } from "@/api/queries";
import i18next from "i18next";
import { LinearProgress } from "@/features/shared";
import { CommunityListItem } from "@/app/communities/_components";
import { getCommunityCache } from "@/core/caches";

export const TopCommunitiesWidget = () => {
const { data: ecencyCommunity } = getCommunityCache("hive-125125").useClientQuery();
const { data, isLoading: loading } = getCommunitiesQuery("rank").useClientQuery();
const list = useMemo(() => {
if (!data) {
if (!data || !ecencyCommunity) {
return [];
}

Expand All @@ -22,8 +24,12 @@ export const TopCommunitiesWidget = () => {
result.push(data[index]);
}
}
if (ecencyCommunity) {
return [ecencyCommunity, ...result.slice(0, result.length - 1)];
}

return result;
}, [data]);
}, [ecencyCommunity, data]);

return (
<div className="top-communities-widget">
Expand Down
2 changes: 1 addition & 1 deletion src/core/global-store/modules/authentication-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function populateActiveUserByApi(activeUser: ActiveUser) {
name: activeUser.username
};
try {
const response = await getAccountFullQuery(activeUser.username).prefetch();
const response = await getAccountFullQuery(activeUser.username).fetchAndGet();
if (!response) {
return fallback;
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/react-query/ecency-queries-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export namespace EcencyQueriesManager {
return {
prefetch: () => prefetchQuery(options),
getData: () => getQueryData<T>(options.queryKey),
useClientQuery: () => useQuery(options)
useClientQuery: () => useQuery(options),
fetchAndGet: () => getQueryClient().fetchQuery(options)
};
}

Expand Down

0 comments on commit cd4ce7d

Please sign in to comment.