1 import { useCallback, useEffect } from 'react';
3 import { createSelector } from '@reduxjs/toolkit';
5 import { baseUseSelector } from '@proton/react-redux-store';
6 import { createHooks } from '@proton/redux-utilities';
8 import type { GetQuotesArgs, QuotesByProvider } from '../slices/quotesByProvider';
9 import { getQuotesByProviderKey, quotesByProviderThunk, selectQuotesByProvider } from '../slices/quotesByProvider';
11 const hooks = createHooks(quotesByProviderThunk, selectQuotesByProvider);
13 export const useGetQuotesByProvider = () => {
14 const get = hooks.useGet();
16 async (args: GetQuotesArgs) => {
17 const key = getQuotesByProviderKey(args);
18 const results = await get({ thunkArg: args });
26 export const useQuotesByProvider = (args: GetQuotesArgs) => {
27 const getQuotesByProvider = useGetQuotesByProvider();
29 const key = getQuotesByProviderKey(args);
31 const paymentMethodsByProvider = createSelector(
32 selectQuotesByProvider,
33 (result): [QuotesByProvider | undefined, boolean] => {
34 const { error, value } = result;
36 const rate = value?.[key];
37 const loading = rate === undefined && error === undefined;
39 return [rate, loading];
44 void getQuotesByProvider(args);
45 }, [args, getQuotesByProvider]);
47 return baseUseSelector(paymentMethodsByProvider);