From 4b6391e8b561664535db44229ffd7e324f9a3fdd Mon Sep 17 00:00:00 2001 From: Gregory Hill Date: Fri, 6 Sep 2024 11:44:45 +0100 Subject: [PATCH] refactor: rename to useSendGatewayTransaction Signed-off-by: Gregory Hill --- packages/sats-wagmi/src/hooks/index.ts | 2 +- ...eway.tsx => useSendGatewayTransaction.tsx} | 21 ++++++++++++------- playgrounds/vite-react/src/Gateway.tsx | 11 +++++++--- 3 files changed, 22 insertions(+), 12 deletions(-) rename packages/sats-wagmi/src/hooks/{useSendToGateway.tsx => useSendGatewayTransaction.tsx} (73%) diff --git a/packages/sats-wagmi/src/hooks/index.ts b/packages/sats-wagmi/src/hooks/index.ts index 5f6ea09..76152f4 100644 --- a/packages/sats-wagmi/src/hooks/index.ts +++ b/packages/sats-wagmi/src/hooks/index.ts @@ -6,4 +6,4 @@ export * from './useFeeRate'; export * from './useFeeEstimate'; export * from './useSendTransaction'; export * from './useSignMessage'; -export * from './useSendToGateway'; +export * from './useSendGatewayTransaction'; diff --git a/packages/sats-wagmi/src/hooks/useSendToGateway.tsx b/packages/sats-wagmi/src/hooks/useSendGatewayTransaction.tsx similarity index 73% rename from packages/sats-wagmi/src/hooks/useSendToGateway.tsx rename to packages/sats-wagmi/src/hooks/useSendGatewayTransaction.tsx index 0258e46..ce132f9 100644 --- a/packages/sats-wagmi/src/hooks/useSendToGateway.tsx +++ b/packages/sats-wagmi/src/hooks/useSendGatewayTransaction.tsx @@ -3,29 +3,34 @@ import { GatewayQuoteParams, GatewaySDK } from '@gobob/bob-sdk'; import { useAccount } from './useAccount'; -type SendToGatewayParams = { +type SendGatewayTransactionParams = { toToken: string; evmAddress: string; value: bigint; }; -type UseSendToGatewayProps = Omit< +type UseSendGatewayTransactionProps = Omit< { gatewaySDK?: GatewaySDK } & Omit< Optional< GatewayQuoteParams, 'fromUserAddress' | 'toUserAddress' | 'amount' | 'toToken' | 'fromChain' | 'fromToken' >, 'toChain' - > & { toChain: 'bob' | 'bob-sepolia' } & UseMutationOptions, + > & { toChain: 'bob' | 'bob-sepolia' } & UseMutationOptions< + string | undefined, + Error, + SendGatewayTransactionParams, + unknown + >, 'mutationKey' | 'mutationFn' >; -const useSendToGateway = ({ gatewaySDK, toChain = 'bob', ...props }: UseSendToGatewayProps) => { +const useSendGatewayTransaction = ({ gatewaySDK, toChain = 'bob', ...props }: UseSendGatewayTransactionProps) => { const { address: btcAddress, publicKey: btcPublicKey, connector } = useAccount(); const { mutate, mutateAsync, ...result } = useMutation({ mutationKey: ['sats-gateway', btcAddress], - mutationFn: async ({ toToken, evmAddress, value }: SendToGatewayParams) => { + mutationFn: async ({ toToken, evmAddress, value }: SendGatewayTransactionParams) => { if (!connector) return undefined; if (!btcAddress) return undefined; @@ -58,9 +63,9 @@ const useSendToGateway = ({ gatewaySDK, toChain = 'bob', ...props }: UseSendToGa return { ...result, - sendToGateway: mutate, - sendToGatewayAsync: mutateAsync + sendGatewayTransaction: mutate, + sendGatewayTransactionAsync: mutateAsync }; }; -export { useSendToGateway }; +export { useSendGatewayTransaction }; diff --git a/playgrounds/vite-react/src/Gateway.tsx b/playgrounds/vite-react/src/Gateway.tsx index 6781cd4..4603994 100644 --- a/playgrounds/vite-react/src/Gateway.tsx +++ b/playgrounds/vite-react/src/Gateway.tsx @@ -1,10 +1,15 @@ import type { FormEvent } from 'react'; -import { useSendToGateway } from '@gobob/sats-wagmi'; +import { useSendGatewayTransaction } from '@gobob/sats-wagmi'; import { type Hex, parseUnits } from 'viem'; function Gateway() { - const { data: hash, error, isPending, sendToGateway } = useSendToGateway({ toChain: 'bob-sepolia' }); + const { + data: hash, + error, + isPending, + sendGatewayTransaction + } = useSendGatewayTransaction({ toChain: 'bob-sepolia' }); async function submit(e: FormEvent) { e.preventDefault(); @@ -12,7 +17,7 @@ function Gateway() { const evmAddress = formData.get('address') as Hex; const value = formData.get('value') as string; - sendToGateway({ toToken: 'tBTC', evmAddress, value: parseUnits(value, 8) }); + sendGatewayTransaction({ toToken: 'tBTC', evmAddress, value: parseUnits(value, 8) }); } return (