Skip to content

Commit

Permalink
chore(feed): remove out of scope code,
Browse files Browse the repository at this point in the history
FIX BIG MISTAKE in postMutate identifier
  • Loading branch information
WaDadidou committed Nov 20, 2024
1 parent 62b7926 commit 0db0ab2
Showing 1 changed file with 25 additions and 48 deletions.
73 changes: 25 additions & 48 deletions packages/hooks/feed/useSocialReactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import useSelectedWallet from "../useSelectedWallet";

import { Post } from "@/api/feed/v1/feed";
import { signingSocialFeedClient } from "@/client-creators/socialFeedClient";
import { useFeedbacks } from "@/context/FeedbacksProvider";
import { useWalletControl } from "@/context/WalletControlProvider";
import { useTeritoriSocialFeedReactPostMutation } from "@/contracts-clients/teritori-social-feed/TeritoriSocialFeed.react-query";
import {
Expand All @@ -32,7 +31,6 @@ export const useSocialReactions = ({
setPost: Dispatch<SetStateAction<Post>>;
}) => {
const selectedWallet = useSelectedWallet();
const { setToast } = useFeedbacks();
const userId = selectedWallet?.userId;
const { showNotEnoughFundsModal, showConnectWalletModal } =
useWalletControl();
Expand All @@ -51,15 +49,6 @@ export const useSocialReactions = ({
);
setPost({ ...post, reactions });
},
onError(err) {
console.error(err);
setToast({
mode: "normal",
type: "error",
title: "Failed to react on Cosmos network",
message: err.message,
});
},
});
const [isLoading, setLoading] = useState(false);

Expand All @@ -77,7 +66,7 @@ export const useSocialReactions = ({
client,
msg: {
icon: emoji,
identifier: "post.localIdentifier",
identifier: post.localIdentifier,
up: true,
},
});
Expand All @@ -93,44 +82,32 @@ export const useSocialReactions = ({
args: [TERITORI_FEED_ID, post.id.split("-")[1], emoji, "true"],
};

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);
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,
});
}
setPost({ ...post, reactions });
} catch (err) {
console.error(err);
if (err instanceof Error) {
setToast({
mode: "normal",
type: "error",
title: "Failed to react on Gno network",
message: err.message,
});
}
} finally {
setLoading(false);
if (currentReactionIdx > -1) {
reactions[currentReactionIdx].count++;
} else {
reactions.push({
icon: emoji,
count: 1,
ownState: true,
});
}
setPost({ ...post, reactions });

setLoading(false);
};

const handleReaction = async (emoji: string) => {
Expand Down

0 comments on commit 0db0ab2

Please sign in to comment.