From 269f23fa12b9016eb304b9c97d64bb8a322807ff Mon Sep 17 00:00:00 2001 From: WaDadidou Date: Thu, 21 Nov 2024 11:43:31 -0500 Subject: [PATCH] fix(feed): Add try catch when react to post on gno --- packages/hooks/feed/useSocialReactions.ts | 52 ++++++++++++----------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/packages/hooks/feed/useSocialReactions.ts b/packages/hooks/feed/useSocialReactions.ts index 9d40df5b3..11e264289 100644 --- a/packages/hooks/feed/useSocialReactions.ts +++ b/packages/hooks/feed/useSocialReactions.ts @@ -82,32 +82,36 @@ export const useSocialReactions = ({ args: [TERITORI_FEED_ID, post.id.split("-")[1], emoji, "true"], }; - setLoading(true); - const txHash = await adenaDoContract( - post.networkId, - [{ type: AdenaDoContractMessageType.CALL, value: vmCall }], - { - gasWanted: 2_000_000, - }, - ); - const provider = new GnoJSONRPCProvider(rpcEndpoint); - // Wait for tx done - await provider.waitForTransaction(txHash); - const reactions = [...post.reactions]; - const currentReactionIdx = reactions.findIndex((r) => r.icon === emoji); + try { + setLoading(true); + const txHash = await adenaDoContract( + post.networkId, + [{ type: AdenaDoContractMessageType.CALL, value: vmCall }], + { + gasWanted: 2_000_000, + }, + ); + const provider = new GnoJSONRPCProvider(rpcEndpoint); + // Wait for tx done + await provider.waitForTransaction(txHash); + const reactions = [...post.reactions]; + const currentReactionIdx = reactions.findIndex((r) => r.icon === emoji); - if (currentReactionIdx > -1) { - reactions[currentReactionIdx].count++; - } else { - reactions.push({ - icon: emoji, - count: 1, - ownState: true, - }); + if (currentReactionIdx > -1) { + reactions[currentReactionIdx].count++; + } else { + reactions.push({ + icon: emoji, + count: 1, + ownState: true, + }); + } + setPost({ ...post, reactions }); + } catch (err) { + console.error(err); + } finally { + setLoading(false); } - setPost({ ...post, reactions }); - - setLoading(false); }; const handleReaction = async (emoji: string) => {