Skip to content

Commit

Permalink
fix(feed): use local identifier in cosmwasm replies (#1375)
Browse files Browse the repository at this point in the history
Signed-off-by: Norman Meier <[email protected]>
  • Loading branch information
n0izn0iz authored Nov 17, 2024
1 parent 08b05a5 commit 11f1977
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/hooks/feed/useFeedPosting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import { useBalances } from "../useBalances";
import useSelectedWallet from "../useSelectedWallet";

import { signingSocialFeedClient } from "@/client-creators/socialFeedClient";
import { TeritoriSocialFeedCreatePostMutation } from "@/contracts-clients/teritori-social-feed/TeritoriSocialFeed.react-query";
import {
getStakingCurrency,
mustGetCosmosNetwork,
NetworkKind,
parseNetworkObjectId,
parseUserId,
} from "@/networks";
import { prettyPrice } from "@/utils/coins";
Expand Down Expand Up @@ -62,7 +64,7 @@ export const useFeedPosting = (
freePostCount > 0 || postFee <= Number(feeBalance?.amount || "0");

const makePost = useCallback(
async (metadata: string, parentPostIdentifier?: string) => {
async (metadata: string, parentPostId?: string) => {
if (!canPayForPost) {
throw new Error("Not enough funds");
}
Expand All @@ -72,8 +74,17 @@ export const useFeedPosting = (
throw new Error("Invalid network");
}

const [parentPostNetwork, parentPostLocalIdentifier] =
parseNetworkObjectId(parentPostId);
if (parentPostId && (!parentPostNetwork || !parentPostLocalIdentifier)) {
throw new Error("Invalid parent post ID");
}

// FIXME: use id generated on-chain
const identifier = uuidv4();
const msg = {

const parentPostIdentifier = parentPostLocalIdentifier || undefined;
const msg: TeritoriSocialFeedCreatePostMutation["msg"] = {
category,
identifier,
metadata,
Expand Down Expand Up @@ -149,18 +160,14 @@ export const useFeedPosting = (
}
} else {
if (network?.kind === NetworkKind.Gno) {
parentPostIdentifier = !parentPostIdentifier
? "0"
: parentPostIdentifier.split("-")[1];

const vmCall = {
caller: userAddress,
send: "",
pkg_path: network.socialFeedsPkgPath,
func: "CreatePost",
args: [
TERITORI_FEED_ID,
parentPostIdentifier,
parentPostLocalIdentifier || "0",
msg.category.toString(),
msg.metadata,
],
Expand Down

0 comments on commit 11f1977

Please sign in to comment.