Skip to content

Commit

Permalink
fix(feed): Add try catch when react to post on gno
Browse files Browse the repository at this point in the history
  • Loading branch information
WaDadidou committed Nov 21, 2024
1 parent 0db0ab2 commit 269f23f
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions packages/hooks/feed/useSocialReactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 269f23f

Please sign in to comment.