diff --git a/src/useStellar/useAccount.ts b/src/useStellar/useAccount.ts index e295d23..86ab863 100644 --- a/src/useStellar/useAccount.ts +++ b/src/useStellar/useAccount.ts @@ -11,13 +11,14 @@ import type { } from '@bluxcc/core/dist/exports/core/getAccount'; import { getAddress, getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = GetAccountResult; type O = GetAccountOptions; export function useAccount( options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const address = getAddress(options?.address); const network = getNetwork(options?.network); @@ -47,10 +48,10 @@ export function useAccount( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useAccounts.ts b/src/useStellar/useAccounts.ts index 58c4507..7a79945 100644 --- a/src/useStellar/useAccounts.ts +++ b/src/useStellar/useAccounts.ts @@ -11,13 +11,14 @@ import type { } from '@bluxcc/core/dist/exports/core/getAccounts'; import { getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = GetAccountsResult; type O = GetAccountsOptions; export function useAccounts( options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const network = getNetwork(options?.network); const enabled = queryOptions?.enabled ?? true; @@ -51,10 +52,10 @@ export function useAccounts( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useAssets.ts b/src/useStellar/useAssets.ts index d5ddd7c..7fbd2f8 100644 --- a/src/useStellar/useAssets.ts +++ b/src/useStellar/useAssets.ts @@ -11,13 +11,14 @@ import type { } from "@bluxcc/core/dist/exports/core/getAssets"; import { getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = GetAssetsResult; type O = GetAssetsOptions; export function useAssets( options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const network = getNetwork(options?.network); const enabled = queryOptions?.enabled ?? true; @@ -49,10 +50,10 @@ export function useAssets( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useBalances.ts b/src/useStellar/useBalances.ts index 15734a1..c818740 100644 --- a/src/useStellar/useBalances.ts +++ b/src/useStellar/useBalances.ts @@ -11,13 +11,14 @@ import type { } from "@bluxcc/core/dist/exports/core/getBalances"; import { getAddress, getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = GetBalancesResult; type O = GetBalancesOptions; export function useBalances( options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const address = getAddress(options?.address); const network = getNetwork(options?.network); @@ -50,10 +51,10 @@ export function useBalances( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useClaimableBalances.ts b/src/useStellar/useClaimableBalances.ts index e056f93..5bd0571 100644 --- a/src/useStellar/useClaimableBalances.ts +++ b/src/useStellar/useClaimableBalances.ts @@ -11,13 +11,14 @@ import type { } from "@bluxcc/core/dist/exports/core/getClaimableBalances"; import { getAddress, getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = GetClaimableBalancesResult; type O = GetClaimableBalancesOptions; export function useClaimableBalances( options: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const claimant = getAddress(options.claimant); const network = getNetwork(options?.network); @@ -52,10 +53,10 @@ export function useClaimableBalances( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useEffects.ts b/src/useStellar/useEffects.ts index 5d86514..2fa3321 100644 --- a/src/useStellar/useEffects.ts +++ b/src/useStellar/useEffects.ts @@ -11,13 +11,14 @@ import type { } from "@bluxcc/core/dist/exports/core/getEffects"; import { getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = GetEffectsResult; type O = GetEffectsOptions; export function useEffects( options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const network = getNetwork(options?.network); const enabled = queryOptions?.enabled ?? true; @@ -52,10 +53,10 @@ export function useEffects( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useLedgers.ts b/src/useStellar/useLedgers.ts index 6a8f36c..1acc234 100644 --- a/src/useStellar/useLedgers.ts +++ b/src/useStellar/useLedgers.ts @@ -11,13 +11,14 @@ import type { } from "@bluxcc/core/dist/exports/core/getLedgers"; import { getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = GetLedgersResult; type O = GetLedgersOptions; export function useLedgers( options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const network = getNetwork(options?.network); const enabled = queryOptions?.enabled ?? true; @@ -48,10 +49,10 @@ export function useLedgers( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useLiquidityPools.ts b/src/useStellar/useLiquidityPools.ts index c679401..d23182e 100644 --- a/src/useStellar/useLiquidityPools.ts +++ b/src/useStellar/useLiquidityPools.ts @@ -11,13 +11,14 @@ import type { } from "@bluxcc/core/dist/exports/core/getLiquidityPools"; import { getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = GetLiquidityPoolsResult; type O = GetLiquidityPoolsOptions; export function useLiquidityPools( options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const network = getNetwork(options?.network); const enabled = queryOptions?.enabled ?? true; @@ -49,10 +50,10 @@ export function useLiquidityPools( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useOffers.ts b/src/useStellar/useOffers.ts index e612d71..923eb1b 100644 --- a/src/useStellar/useOffers.ts +++ b/src/useStellar/useOffers.ts @@ -11,13 +11,14 @@ import type { } from "@bluxcc/core/dist/exports/core/getOffers"; import { getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = GetOffersResult; type O = GetOffersOptions; export function useOffers( options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const network = getNetwork(options?.network); const enabled = queryOptions?.enabled ?? true; @@ -28,7 +29,6 @@ export function useOffers( options?.selling, options?.sponsor, options?.seller, - options?.forAccount, options?.cursor, options?.limit, options?.network, @@ -53,10 +53,10 @@ export function useOffers( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useOperations.ts b/src/useStellar/useOperations.ts index aab80bc..1fc1d7b 100644 --- a/src/useStellar/useOperations.ts +++ b/src/useStellar/useOperations.ts @@ -11,13 +11,14 @@ import type { } from "@bluxcc/core/dist/exports/core/getOperations"; import { getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = GetOperationsResult; type O = GetOperationsOptions; export function useOperations( options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const network = getNetwork(options?.network); const enabled = queryOptions?.enabled ?? true; @@ -54,10 +55,10 @@ export function useOperations( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useOrderbook.ts b/src/useStellar/useOrderbook.ts index 63bb39b..bedaab9 100644 --- a/src/useStellar/useOrderbook.ts +++ b/src/useStellar/useOrderbook.ts @@ -10,8 +10,8 @@ import type { } from "@bluxcc/core/dist/exports/core/getOrderbook"; import { Asset } from '@stellar/stellar-sdk'; -import { CallBuilderOptions } from '../utils'; -import { getNetwork } from '../utils'; +import { CallBuilderOptions, getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = GetOrderbookResult; type O = CallBuilderOptions; @@ -19,7 +19,7 @@ type O = CallBuilderOptions; export function useOrderbook( args: [selling: Asset, buying: Asset], options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const network = getNetwork(options?.network); const enabled = queryOptions?.enabled ?? true; @@ -51,9 +51,9 @@ export function useOrderbook( ); return useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); } diff --git a/src/useStellar/usePayments.ts b/src/useStellar/usePayments.ts index 8b8cc6a..dfa3f65 100644 --- a/src/useStellar/usePayments.ts +++ b/src/useStellar/usePayments.ts @@ -12,6 +12,7 @@ import type { import { PaymentCallBuilder } from '@stellar/stellar-sdk/lib/horizon/payment_call_builder'; import { ServerApi } from '@stellar/stellar-sdk/lib/horizon'; import { getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = { builder: PaymentCallBuilder; @@ -21,7 +22,7 @@ type O = GetPaymentsOptions; export function usePayments( options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const network = getNetwork(options?.network); const enabled = queryOptions?.enabled ?? true; @@ -55,10 +56,10 @@ export function usePayments( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useStrictReceivePaths.ts b/src/useStellar/useStrictReceivePaths.ts index ef9fdc3..7a81459 100644 --- a/src/useStellar/useStrictReceivePaths.ts +++ b/src/useStellar/useStrictReceivePaths.ts @@ -10,8 +10,8 @@ import type { } from "@bluxcc/core/dist/exports/core/getStrictReceivePaths"; import { Asset } from '@stellar/stellar-sdk'; -import { CallBuilderOptions } from '../utils'; -import { getNetwork } from '../utils'; +import { CallBuilderOptions, getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = GetPaymentPathResult; type O = CallBuilderOptions; @@ -23,7 +23,7 @@ export function useStrictReceivePaths( destinationAmount: string, ], options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const network = getNetwork(options?.network); const enabled = queryOptions?.enabled ?? true; @@ -56,10 +56,10 @@ export function useStrictReceivePaths( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useStrictSendPaths.ts b/src/useStellar/useStrictSendPaths.ts index 1ece36c..7c610a0 100644 --- a/src/useStellar/useStrictSendPaths.ts +++ b/src/useStellar/useStrictSendPaths.ts @@ -10,8 +10,8 @@ import type { } from "@bluxcc/core/dist/exports/core/getStrictSendPaths"; import { Asset } from '@stellar/stellar-sdk'; -import { CallBuilderOptions } from '../utils'; -import { getNetwork } from '../utils'; +import { CallBuilderOptions, getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = GetPaymentPathResult; type O = CallBuilderOptions; @@ -23,7 +23,7 @@ export function useStrictSendPaths( destination: string | Asset[], ], options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const network = getNetwork(options?.network); const enabled = queryOptions?.enabled ?? true; @@ -56,10 +56,10 @@ export function useStrictSendPaths( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useTradeAggregation.ts b/src/useStellar/useTradeAggregation.ts index 68289ef..6d3213b 100644 --- a/src/useStellar/useTradeAggregation.ts +++ b/src/useStellar/useTradeAggregation.ts @@ -10,8 +10,8 @@ import type { } from "@bluxcc/core/dist/exports/core/getTradeAggregation"; import { Asset } from '@stellar/stellar-sdk'; -import { CallBuilderOptions } from '../utils'; -import { getNetwork } from '../utils'; +import { CallBuilderOptions, getNetwork } from '../utils'; +import type { QueryOptions } from '../utils'; type R = GetTradeAggregationResult; type O = CallBuilderOptions; @@ -26,7 +26,7 @@ export function useTradeAggregation( offset: number, ], options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const network = getNetwork(options?.network); const enabled = queryOptions?.enabled ?? true; @@ -62,10 +62,10 @@ export function useTradeAggregation( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useTrades.ts b/src/useStellar/useTrades.ts index 36ccc45..53a05e5 100644 --- a/src/useStellar/useTrades.ts +++ b/src/useStellar/useTrades.ts @@ -11,19 +11,19 @@ import type { } from "@bluxcc/core/dist/exports/core/getTrades"; import { getNetwork } from '../utils'; +import type { QueryOptions } from "../utils"; type R = GetTradesResult; type O = GetTradesOptions; export function useTrades( options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const network = getNetwork(options?.network); const enabled = queryOptions?.enabled ?? true; const deps = [ - options?.forAccount, options?.forAssetPair, options?.forOffer, options?.forType, @@ -53,10 +53,10 @@ export function useTrades( ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, }); return result; diff --git a/src/useStellar/useTransactions.ts b/src/useStellar/useTransactions.ts index c9f4eae..c085600 100644 --- a/src/useStellar/useTransactions.ts +++ b/src/useStellar/useTransactions.ts @@ -1,4 +1,4 @@ -import { useMemo } from 'react'; +import { useMemo } from "react"; import { getTransactions } from "@bluxcc/core"; import { useQuery, @@ -10,14 +10,15 @@ import type { GetTransactionsOptions, } from "@bluxcc/core/dist/exports/core/getTransactions"; -import { getNetwork } from '../utils'; +import { getNetwork } from "../utils"; +import type { QueryOptions } from "../utils"; type R = GetTransactionsResult; type O = GetTransactionsOptions; export function useTransactions( options?: O, - queryOptions?: UseQueryOptions, + queryOptions?: QueryOptions ): UseQueryResult { const network = getNetwork(options?.network); const enabled = queryOptions?.enabled ?? true; @@ -35,8 +36,8 @@ export function useTransactions( ]; const queryKey = useMemo( - () => ['blux', 'transactions', network, ...deps], - [network, ...deps], + () => ["blux", "transactions", network, ...deps], + [network, ...deps] ); const queryFn = useMemo( @@ -45,18 +46,17 @@ export function useTransactions( ...options, network, }; - return getTransactions(opts); }, - [network, ...deps], + [network, ...deps] ); const result = useQuery({ + ...(queryOptions as UseQueryOptions | undefined), + enabled, queryKey, queryFn, - enabled, - ...queryOptions, - }); +}); return result; -} \ No newline at end of file +} diff --git a/src/utils.ts b/src/utils.ts index 408579d..72f7085 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,5 @@ import { getState } from '@bluxcc/core'; +import { UseQueryOptions } from '@tanstack/react-query'; export type CallBuilderOptions = { cursor?: string; @@ -7,6 +8,11 @@ export type CallBuilderOptions = { order?: 'asc' | 'desc'; }; +export type QueryOptions = Omit< + UseQueryOptions, + "queryKey" | "queryFn" +>; + export const checkConfigCreated = () => { const { stellar } = getState();