import { useSignAndExecuteTransaction } from '@mysten/dapp-kit';
import { usePost } from '@sage-app/sdk/react';
interface LikePostInput {
amounts: number[]; // payment amounts set to [0, 0]
postId: string;
self: string; // user's wallet address
soulId: string; // address of user's owned soul
}
...
const { mutateAsync: signAndExecuteTransaction } = useSignAndExecuteTransaction();
const { like } = usePost();
...
const likePost = async (data: LikePostInput) => {
const { ok, err, transaction } = like(data);
const { digest } = await signAndExecuteTransaction({
transaction
});
};
Querying for New Post Like Events
import { EventId, SuiClient, getFullnodeUrl } from '@mysten/sui/client';
import { SageClient } from '@sage-app/sdk/client';
...
interface QueryInput {
cursor?: EventId;
}
const appId = '<YOUR_APP_ID>';
const network = 'mainnet' | 'testnet';
const suiClient = new SuiClient({ url: getFullnodeUrl(network) });
const sageClient = new SageClient({ appId, network, suiClient });
...
const pollNewLikes = async ({ cursor }) => {
const {
eventCount,
events,
hasNextPage,
nextCursor
} = await sageClient.queryPostLikeEvents({ cursor }: QueryInput);
// do something with events
setTimeout(() => pollNewLikes({ cursor: nextCursor }), 5000);
};
interface PostLikeEvent {
id: string; // post object address
updatedAt: string;
user: string; // user's wallet address
}