Skip to content

Commit

Permalink
docs: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
avasisht23 committed Apr 17, 2024
1 parent 553fcf2 commit 6a67fd0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/alchemy/src/react/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { BaseError } from "../errors/base.js";

export class NoAlchemyAccountContextError extends BaseError {
constructor(hookName: string) {
super(`${hookName} must be used within a AlchemyAccountProvider`);
super(`${hookName} must be used within a AlchemyAxccountProvider`);
}
}

export class ClientUndefinedError extends BaseError {
export class ClientUndefinedHookError extends BaseError {
constructor(hookName: string) {
super(`client must be defined in ${hookName}`);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/alchemy/src/react/hooks/useSignMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@tanstack/react-query";
import type { Hex, SignableMessage } from "viem";
import { useAlchemyAccountContext } from "../context.js";
import { ClientUndefinedError } from "../errors.js";
import { ClientUndefinedHookError } from "../errors.js";
import type { BaseHookMutationArgs } from "../types.js";
import { type UseSmartAccountClientResult } from "./useSmartAccountClient.js";

Expand Down Expand Up @@ -51,7 +51,7 @@ export function useSignMessage({
{
mutationFn: async (params: SignMessageArgs) => {
if (!client) {
throw new ClientUndefinedError("useSignMessage");
throw new ClientUndefinedHookError("useSignMessage");
}

return client.signMessageWith6492(params);
Expand Down
4 changes: 2 additions & 2 deletions packages/alchemy/src/react/hooks/useSignTypedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@tanstack/react-query";
import type { Hex, TypedDataDefinition } from "viem";
import { useAlchemyAccountContext } from "../context.js";
import { ClientUndefinedError } from "../errors.js";
import { ClientUndefinedHookError } from "../errors.js";
import type { BaseHookMutationArgs } from "../types.js";
import type { UseSmartAccountClientResult } from "./useSmartAccountClient.js";

Expand Down Expand Up @@ -51,7 +51,7 @@ export function useSignTypedData({
{
mutationFn: async (params: SignTypedDataArgs) => {
if (!client) {
throw new ClientUndefinedError("useSignTypedData");
throw new ClientUndefinedHookError("useSignTypedData");
}
return client.signTypedDataWith6492({ ...params });
},
Expand Down
15 changes: 13 additions & 2 deletions site/snippets/react/useSignMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ import {
import { useState } from "react";

export function ComponentWithSignMessage() {
// Assumes the app has context of a signer with an authenticated user
/**
* Assumes the app has context of a signer with an authenticated user
* by using the `AlchemyAccountProvider` from `@alchemy/aa-alchemy/react`.
*/
const [message, setMessage] = useState("");
const client = useSmartAccountClient({
type: "MultiOwnerModularAccount",
});
const { signMessage, isSigningMessage } = useSignMessage({ client });
const { signMessage, isSigningMessage } = useSignMessage({
client,
onSuccess: (signature) => {
// Do something with the signature
},
onError: (error) => {
// Handle the error
},
});

return (
<div>
Expand Down
15 changes: 13 additions & 2 deletions site/snippets/react/useSignTypedData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ import {
import { useState } from "react";

export function ComponentWithSignTypedData() {
// Assumes the app has context of a signer with an authenticated user
/**
* Assumes the app has context of a signer with an authenticated user
* by using the `AlchemyAccountProvider` from `@alchemy/aa-alchemy/react`.
*/
const [typedDataMessage, setTypedDataMessage] = useState("");
const client = useSmartAccountClient({
type: "MultiOwnerModularAccount",
});
const { signTypedData, isSigningTypedData } = useSignTypedData({ client });
const { signTypedData, isSigningTypedData } = useSignTypedData({
client,
onSuccess: (signature) => {
// Do something with the signature
},
onError: (error) => {
// Handle the error
},
});

return (
<div>
Expand Down

0 comments on commit 6a67fd0

Please sign in to comment.