Skip to content

Commit

Permalink
feat(react-account/use-post-note): mark noteId as nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
runjuu committed Aug 16, 2023
1 parent 764f7f9 commit e34d108
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/react-account/src/hooks/use-post-note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { NoteMetadata } from "crossbell";
import { SCOPE_KEY_FOLLOWING_FEEDS_OF_CHARACTER } from "@crossbell/indexer";

import { putNote, siwePutNote } from "../apis";
import { optionalBigint, OptionalBigint } from "../utils";

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

export const usePostNote = createAccountTypeBasedMutationHooks<
void,
{ metadata: NoteMetadata; characterId?: number },
{ noteId: bigint; transactionHash: string }
{ noteId: OptionalBigint; transactionHash: string }
>(
{
actionDesc: "usePostNote",
Expand All @@ -27,7 +28,7 @@ export const usePostNote = createAccountTypeBasedMutationHooks<
metadata,
});

return { noteId: BigInt(data.noteId), transactionHash };
return { noteId: optionalBigint(data.noteId), transactionHash };
},

wallet: {
Expand All @@ -51,7 +52,7 @@ export const usePostNote = createAccountTypeBasedMutationHooks<
metadata,
});

return { noteId: BigInt(data.noteId), transactionHash };
return { noteId: optionalBigint(data.noteId), transactionHash };
} else {
const { data, transactionHash } = await contract.note.post({
characterId,
Expand Down
1 change: 1 addition & 0 deletions packages/react-account/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from "./zustand-slice";
export * from "./zustand-context";
export * from "./zustand-create-context";
export * from "./validate-handle";
export * from "./optional-bigint";
9 changes: 9 additions & 0 deletions packages/react-account/src/utils/optional-bigint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type OptionalBigint = bigint | null;

export function optionalBigint(input: any): OptionalBigint {
try {
return BigInt(input);
} catch {
return null;
}
}

0 comments on commit e34d108

Please sign in to comment.