diff --git a/.changeset/purple-rivers-lick.md b/.changeset/purple-rivers-lick.md new file mode 100644 index 00000000..b620b6c3 --- /dev/null +++ b/.changeset/purple-rivers-lick.md @@ -0,0 +1,5 @@ +--- +'@starknet-react/core': patch +--- + +Change sign hook values to match other hooks diff --git a/examples/starknet-react-next/pages/sign.tsx b/examples/starknet-react-next/pages/sign.tsx index 55b1bbc1..7d33920d 100644 --- a/examples/starknet-react-next/pages/sign.tsx +++ b/examples/starknet-react-next/pages/sign.tsx @@ -44,24 +44,20 @@ const Sign: NextPage = () => { } const { account } = useStarknet() - const { data, error, isIdle, isError, isSuccess, signTypedData, reset } = - useSignTypedData(typedData) + const { data, error, signTypedData, reset } = useSignTypedData(typedData) return (
-

isIdle: {String(isIdle)}

-

isError: {String(isError)}

-

{isError && `error: ${error}`}

-

isSuccess: {String(isSuccess)}

+

{error && `error: ${error}`}

{data && `data: ${data}`}

{account && ( <> setMessage(evt.target.value)} /> - - + + )}
diff --git a/packages/core/src/hooks/sign.ts b/packages/core/src/hooks/sign.ts index f4e59341..5cad91db 100644 --- a/packages/core/src/hooks/sign.ts +++ b/packages/core/src/hooks/sign.ts @@ -1,13 +1,12 @@ import { TypedData } from 'starknet/utils/typedData' import type { AccountInterface, Signature } from 'starknet' import { useCallback, useReducer } from 'react' -import { useStarknet } from '..' +import { useStarknet } from '../providers/starknet' interface State { data?: string[] error?: string - isLoading: boolean - isSuccess: boolean + loading: boolean } interface StartSigning { @@ -39,29 +38,26 @@ function starknetSignReducer(state: State, action: Action): State { if (action.type === 'start_signing') { return { ...state, - isLoading: true, + loading: true, } } else if (action.type === 'set_signature') { return { ...state, data: action.data, - isLoading: false, - isSuccess: true, + loading: false, } } else if (action.type === 'set_error') { return { ...state, error: action.error, - isLoading: false, - isSuccess: false, + loading: false, } } else if (action.type === 'reset') { return { ...state, data: undefined, error: undefined, - isLoading: false, - isSuccess: false, + loading: false, } } return state @@ -70,18 +66,14 @@ function starknetSignReducer(state: State, action: Action): State { export interface UseSignTypedData { data?: string[] error?: string - isError: boolean - isIdle: boolean - isLoading: boolean - isSuccess: boolean + loading: boolean signTypedData: () => Promise reset: () => void } export function useSignTypedData(typedData: TypedData): UseSignTypedData { const [state, dispatch] = useReducer(starknetSignReducer, { - isLoading: false, - isSuccess: false, + loading: false, }) const { account: accountAddress, connectors } = useStarknet() @@ -90,7 +82,7 @@ export function useSignTypedData(typedData: TypedData): UseSignTypedData { dispatch({ type: 'reset' }) }, [dispatch]) - const { data, error, isLoading, isSuccess } = state + const { data, error, loading } = state const signTypedData = useCallback(async () => { dispatch({ type: 'reset' }) @@ -120,10 +112,7 @@ export function useSignTypedData(typedData: TypedData): UseSignTypedData { return { data, error, - isError: !!error, - isIdle: !isLoading, - isLoading, - isSuccess, + loading, signTypedData, reset, }