Skip to content

Commit 397678c

Browse files
committed
fix: settle post processing toasts
1 parent f888c4a commit 397678c

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

src/hooks/useCreatePost.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const useCreatePost = ({
3838
});
3939

4040
if (!data?.post) {
41+
toast.error("Post is still processing. Please refresh in a moment.", {
42+
id: toastId
43+
});
4144
return;
4245
}
4346

@@ -61,10 +64,13 @@ const useCreatePost = ({
6164

6265
const onCompletedWithTransaction = useCallback(
6366
(hash: string) => {
64-
const toastId = toast.loading(
65-
`${isComment ? "Comment" : "Post"} processing...`
66-
);
67-
waitForTransactionToComplete(hash).then(() => updateCache(hash, toastId));
67+
const type = isComment ? "Comment" : "Post";
68+
const toastId = toast.loading(`${type} processing...`);
69+
waitForTransactionToComplete(hash)
70+
.then(() => updateCache(hash, toastId))
71+
.catch(() => {
72+
toast.error(`${type} processing failed`, { id: toastId });
73+
});
6874
return onCompleted();
6975
},
7076
[waitForTransactionToComplete, updateCache, onCompleted, isComment]

src/hooks/useEditPost.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const useEditPost = ({ onCompleted, onError }: EditPostProps) => {
3131
});
3232

3333
if (!data?.post) {
34+
toast.error("Post is still processing. Please refresh in a moment.", {
35+
id: toastId
36+
});
3437
return;
3538
}
3639

@@ -48,7 +51,11 @@ const useEditPost = ({ onCompleted, onError }: EditPostProps) => {
4851
const onCompletedWithTransaction = useCallback(
4952
(hash: string) => {
5053
const toastId = toast.loading("Editing post...");
51-
waitForTransactionToComplete(hash).then(() => updateCache(toastId));
54+
waitForTransactionToComplete(hash)
55+
.then(() => updateCache(toastId))
56+
.catch(() => {
57+
toast.error("Post editing failed", { id: toastId });
58+
});
5259
return onCompleted();
5360
},
5461
[waitForTransactionToComplete, updateCache, onCompleted]

0 commit comments

Comments
 (0)