import { useSignAndExecuteTransaction } from '@mysten/dapp-kit';
import { useUser } from '@sage-app/sdk/react';
interface JoinUserInput {
amounts: number[]; // payment amounts set to [0, 0]
self: string; // user's wallet address
soulId: string; // address of user's owned soul
userId: string; // user's object id
}
...
const { mutateAsync: signAndExecuteTransaction } = useSignAndExecuteTransaction();
const { join } = useUser();
...
const followUser = async (data: JoinUserInput) => {
const { ok, err, transaction } = join(data);
const { digest } = await signAndExecuteTransaction({
transaction
});
};
import { useSignAndExecuteTransaction } from '@mysten/dapp-kit';
import { useUser } from '@sage-app/sdk/react';
interface LeaveUserInput {
amounts: number[]; // payment amounts set to [0, 0]
self: string; // user's wallet address
userId: string; // user's object id
}
...
const { mutateAsync: signAndExecuteTransaction } = useSignAndExecuteTransaction();
const { leave } = useUser();
...
const unfollowUser = async (data: LeaveUserInput) => {
const { ok, err, transaction } = leave(data);
const { digest } = await signAndExecuteTransaction({
transaction
});
};
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 pollUserMembershipChanges = async ({ cursor }) => {
const {
eventCount,
events,
hasNextPage,
nextCursor
} = await sageClient.queryUserMembershipEvents({ cursor }: QueryInput);
// do something with events
setTimeout(() => pollUserMembershipChanges({ cursor: nextCursor }), 5000);
};
interface UserMemberEvent {
accountType: "OBJECT" | "WALLET";
followedUser: string; // followed user's wallet address
message: "JOIN" | "LEAVE";
updatedAt: string;
user: string; // user's wallet address
}