mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feat(server): ability to assign the base currency as api query when getting latest ex. rate
This commit is contained in:
@@ -20,13 +20,16 @@ function AutoExchangeRateProvider({ children }: AutoExchangeRateProviderProps) {
|
||||
|
||||
// Retrieves the exchange rate.
|
||||
const { data: autoExchangeRate, isLoading: isAutoExchangeRateLoading } =
|
||||
useLatestExchangeRate(autoExRateCurrency, {
|
||||
enabled: Boolean(autoExRateCurrency),
|
||||
refetchOnWindowFocus: false,
|
||||
staleTime: 0,
|
||||
cacheTime: 0,
|
||||
retry: 0,
|
||||
});
|
||||
useLatestExchangeRate(
|
||||
{ fromCurrency: autoExRateCurrency },
|
||||
{
|
||||
enabled: Boolean(autoExRateCurrency),
|
||||
refetchOnWindowFocus: false,
|
||||
staleTime: 0,
|
||||
cacheTime: 0,
|
||||
retry: 0,
|
||||
},
|
||||
);
|
||||
|
||||
const value = {
|
||||
autoExRateCurrency,
|
||||
|
||||
@@ -3,15 +3,23 @@ import { useQuery } from 'react-query';
|
||||
import QUERY_TYPES from './types';
|
||||
import useApiRequest from '../useRequest';
|
||||
|
||||
interface LatestExchangeRateQuery {
|
||||
fromCurrency?: string;
|
||||
toCurrency?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves latest exchange rate.
|
||||
* @param {number} customerId - Customer id.
|
||||
*/
|
||||
export function useLatestExchangeRate(toCurrency: string, props) {
|
||||
export function useLatestExchangeRate(
|
||||
{ toCurrency, fromCurrency }: LatestExchangeRateQuery,
|
||||
props,
|
||||
) {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useQuery(
|
||||
[QUERY_TYPES.EXCHANGE_RATE, toCurrency],
|
||||
[QUERY_TYPES.EXCHANGE_RATE, toCurrency, fromCurrency],
|
||||
() =>
|
||||
apiRequest
|
||||
.http({
|
||||
@@ -19,6 +27,7 @@ export function useLatestExchangeRate(toCurrency: string, props) {
|
||||
method: 'get',
|
||||
params: {
|
||||
to_currency: toCurrency,
|
||||
from_currency: fromCurrency,
|
||||
},
|
||||
})
|
||||
.then((res) => res.data),
|
||||
|
||||
Reference in New Issue
Block a user