Skip to content

Commit

Permalink
chore(hooks): add MutationEventArgs typing
Browse files Browse the repository at this point in the history
  • Loading branch information
codingki committed Oct 24, 2022
1 parent 4850149 commit 130a830
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/graz/src/hooks/methods.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { DeliverTxResponse } from "@cosmjs/stargate";
import { useMutation } from "@tanstack/react-query";

import type { SendIbcTokensArgs, SendTokensArgs } from "../actions/methods";
Expand All @@ -24,7 +25,11 @@ import { useAccount } from "./account";
*
* @see {@link sendTokens}
*/
export const useSendTokens = ({ onError, onLoading, onSuccess }: MutationEventArgs = {}) => {
export const useSendTokens = ({
onError,
onLoading,
onSuccess,
}: MutationEventArgs<SendTokensArgs, DeliverTxResponse> = {}) => {
const { data: account } = useAccount();
const accountAddress = account?.bech32Address;

Expand All @@ -33,7 +38,7 @@ export const useSendTokens = ({ onError, onLoading, onSuccess }: MutationEventAr
queryKey,
(args: SendTokensArgs) => sendTokens({ senderAddress: accountAddress, ...args }),
{
onError: (err, args) => Promise.resolve(onError?.(err, args)),
onError: (err, data) => Promise.resolve(onError?.(err, data)),
onMutate: onLoading,
onSuccess: (txResponse) => Promise.resolve(onSuccess?.(txResponse)),
},
Expand Down Expand Up @@ -66,7 +71,11 @@ export const useSendTokens = ({ onError, onLoading, onSuccess }: MutationEventAr
* })
* ```
*/
export const useSendIbcTokens = ({ onError, onLoading, onSuccess }: MutationEventArgs = {}) => {
export const useSendIbcTokens = ({
onError,
onLoading,
onSuccess,
}: MutationEventArgs<SendIbcTokensArgs, DeliverTxResponse> = {}) => {
const { data: account } = useAccount();
const accountAddress = account?.bech32Address;

Expand All @@ -75,7 +84,7 @@ export const useSendIbcTokens = ({ onError, onLoading, onSuccess }: MutationEven
queryKey,
(args: SendIbcTokensArgs) => sendIbcTokens({ senderAddress: accountAddress, ...args }),
{
onError: (err, txResponse) => Promise.resolve(onError?.(err, txResponse)),
onError: (err, data) => Promise.resolve(onError?.(err, data)),
onMutate: onLoading,
onSuccess: (txResponse) => Promise.resolve(onSuccess?.(txResponse)),
},
Expand Down

0 comments on commit 130a830

Please sign in to comment.