Skip to content

Commit

Permalink
feat(connect-kit): add useDeleteCharacter & useDeleteEmailAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
runjuu committed Mar 15, 2023
1 parent a946c95 commit f3b3d91
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/connect-kit/src/apis/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ export async function updateHandle(
});
}

export async function deleteAccount(
token: string
): Promise<{ ok: boolean; msg: string }> {
return request("/newbie/account", {
method: "DELETE",
token,
});
}

export async function linkNote({
token,
toNoteId,
Expand Down
2 changes: 2 additions & 0 deletions packages/connect-kit/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export * from "./use-account-has-character";
export * from "./use-connected-account";
export * from "./use-connected-action";
export * from "./use-create-character";
export * from "./use-delete-character";
export * from "./use-delete-email-account";
export * from "./use-disconnect-account";
export * from "./use-is-connected";
export * from "./use-is-ssr-ready";
Expand Down
33 changes: 33 additions & 0 deletions packages/connect-kit/src/hooks/use-delete-character.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { SCOPE_KEY_CHARACTER, SCOPE_KEY_CHARACTERS } from "@crossbell/indexer";

import { useAccountState } from "./account-state";
import { createAccountTypeBasedMutationHooks } from "./account-type-based-hooks";

export const useDeleteCharacter = createAccountTypeBasedMutationHooks<
void,
{ characterId: number }
>(
{
actionDesc: "setting character handle",
withParams: false,
connectType: "wallet",
},
() => {
const { refresh } = useAccountState();
return {
async contract({ characterId }, { contract }) {
return contract.burnCharacter(characterId);
},

onSuccess({ queryClient, variables, account }) {
const { characterId } = variables;

return Promise.all([
queryClient.invalidateQueries(SCOPE_KEY_CHARACTER(characterId)),
queryClient.invalidateQueries(SCOPE_KEY_CHARACTERS(account?.address)),
refresh(),
]);
},
};
}
);
22 changes: 22 additions & 0 deletions packages/connect-kit/src/hooks/use-delete-email-account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { deleteAccount } from "../apis";
import { useAccountState } from "./account-state";
import { createAccountTypeBasedMutationHooks } from "./account-type-based-hooks";

export const useDeleteEmailAccount = createAccountTypeBasedMutationHooks(
{
actionDesc: "delete email account",
withParams: false,
connectType: "email",
},
() => {
const { disconnectEmail } = useAccountState();

return {
async email(_, { account }) {
await deleteAccount(account.token);
},

onSuccess: async () => disconnectEmail(),
};
}
);

0 comments on commit f3b3d91

Please sign in to comment.