diff --git a/src/graphql/queries/__generated__/prices.generated.tsx b/src/graphql/queries/__generated__/prices.generated.tsx index 460b7897..9a48de31 100644 --- a/src/graphql/queries/__generated__/prices.generated.tsx +++ b/src/graphql/queries/__generated__/prices.generated.tsx @@ -30,6 +30,25 @@ export type GetPricesHistoricalQuery = { }; }; +export type GetPriceCurrentQueryVariables = Types.Exact<{ + [key: string]: never; +}>; + +export type GetPriceCurrentQuery = { + __typename?: 'Query'; + prices: { + __typename?: 'PriceQueries'; + id: string; + current: { + __typename?: 'PricePoint'; + currency: string; + date: string; + id: string; + value?: number | null; + }; + }; +}; + export const GetPricesHistoricalDocument = gql` query getPricesHistorical($input: PriceChartInput!) { prices { @@ -117,3 +136,81 @@ export type GetPricesHistoricalQueryResult = Apollo.QueryResult< GetPricesHistoricalQuery, GetPricesHistoricalQueryVariables >; +export const GetPriceCurrentDocument = gql` + query getPriceCurrent { + prices { + current { + currency + date + id + value + } + id + } + } +`; + +/** + * __useGetPriceCurrentQuery__ + * + * To run a query within a React component, call `useGetPriceCurrentQuery` and pass it any options that fit your needs. + * When your component renders, `useGetPriceCurrentQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useGetPriceCurrentQuery({ + * variables: { + * }, + * }); + */ +export function useGetPriceCurrentQuery( + baseOptions?: Apollo.QueryHookOptions< + GetPriceCurrentQuery, + GetPriceCurrentQueryVariables + > +) { + const options = { ...defaultOptions, ...baseOptions }; + return Apollo.useQuery( + GetPriceCurrentDocument, + options + ); +} +export function useGetPriceCurrentLazyQuery( + baseOptions?: Apollo.LazyQueryHookOptions< + GetPriceCurrentQuery, + GetPriceCurrentQueryVariables + > +) { + const options = { ...defaultOptions, ...baseOptions }; + return Apollo.useLazyQuery< + GetPriceCurrentQuery, + GetPriceCurrentQueryVariables + >(GetPriceCurrentDocument, options); +} +export function useGetPriceCurrentSuspenseQuery( + baseOptions?: Apollo.SuspenseQueryHookOptions< + GetPriceCurrentQuery, + GetPriceCurrentQueryVariables + > +) { + const options = { ...defaultOptions, ...baseOptions }; + return Apollo.useSuspenseQuery< + GetPriceCurrentQuery, + GetPriceCurrentQueryVariables + >(GetPriceCurrentDocument, options); +} +export type GetPriceCurrentQueryHookResult = ReturnType< + typeof useGetPriceCurrentQuery +>; +export type GetPriceCurrentLazyQueryHookResult = ReturnType< + typeof useGetPriceCurrentLazyQuery +>; +export type GetPriceCurrentSuspenseQueryHookResult = ReturnType< + typeof useGetPriceCurrentSuspenseQuery +>; +export type GetPriceCurrentQueryResult = Apollo.QueryResult< + GetPriceCurrentQuery, + GetPriceCurrentQueryVariables +>; diff --git a/src/graphql/queries/prices.ts b/src/graphql/queries/prices.ts index 2a314dcf..a72fda4b 100644 --- a/src/graphql/queries/prices.ts +++ b/src/graphql/queries/prices.ts @@ -17,3 +17,17 @@ export const getPricesHistorical = gql` } } `; + +export const getPriceCurrent = gql` + query getPriceCurrent { + prices { + current { + currency + date + id + value + } + id + } + } +`; diff --git a/src/graphql/types.ts b/src/graphql/types.ts index d0a941bb..629ceff0 100644 --- a/src/graphql/types.ts +++ b/src/graphql/types.ts @@ -467,6 +467,7 @@ export type PricePoint = { export type PriceQueries = { __typename?: 'PriceQueries'; + current: PricePoint; historical: PriceHistorical; id: Scalars['String']['output']; }; diff --git a/src/views/wallet/Receive.tsx b/src/views/wallet/Receive.tsx index c9128ed1..03f52d20 100644 --- a/src/views/wallet/Receive.tsx +++ b/src/views/wallet/Receive.tsx @@ -1,4 +1,3 @@ -import { sub } from 'date-fns'; import { ArrowLeft, ArrowUpDown, ChevronsUpDown } from 'lucide-react'; import Link from 'next/link'; import { useTranslations } from 'next-intl'; @@ -17,7 +16,7 @@ import { Skeleton } from '@/components/ui/skeleton'; import { useToast } from '@/components/ui/use-toast'; import { useCreateLightningInvoiceMutation } from '@/graphql/mutations/__generated__/createInvoice.generated'; import { useCreateOnchainAddressMutation } from '@/graphql/mutations/__generated__/createOnchainAddress.generated'; -import { useGetPricesHistoricalQuery } from '@/graphql/queries/__generated__/prices.generated'; +import { useGetPriceCurrentQuery } from '@/graphql/queries/__generated__/prices.generated'; import { useGetWalletDetailsQuery, useGetWalletQuery, @@ -186,19 +185,11 @@ export const Receive = () => { } }, [receive, bancoCode, receiveString, liquidAddress, t]); - const from_date = useMemo( - () => sub(new Date(), { days: 1 }).toISOString(), - [] - ); - const { data: priceData, loading: priceLoading, error: priceError, - } = useGetPricesHistoricalQuery({ - variables: { - input: { from_date }, - }, + } = useGetPriceCurrentQuery({ onError: err => { const messages = handleApolloError(err); @@ -210,13 +201,7 @@ export const Receive = () => { }, }); - const latestPrice = useMemo( - () => - priceData?.prices.historical.points - .filter(p => p.value !== null) - .toSorted((a, b) => Date.parse(b.date) - Date.parse(a.date))[0].value, - [priceData] - ); + const latestPrice = priceData?.prices.current.value; const loading = detailsLoading ||