1 import { useCallback, useEffect } from 'react';
3 import { createSelector } from '@reduxjs/toolkit';
5 import type { WasmFiatCurrencySymbol, WasmPriceGraph, WasmTimeframe } from '@proton/andromeda';
6 import { baseUseSelector } from '@proton/react-redux-store';
7 import { createHooks } from '@proton/redux-utilities';
9 import { getKey, priceGraphDataThunk, selectPriceGraphData } from '../slices/priceGraphData';
11 export const priceGraphDataHooks = createHooks(priceGraphDataThunk, selectPriceGraphData);
13 export const useGetPriceGraphData = () => {
14 const get = priceGraphDataHooks.useGet();
16 async (fiat: WasmFiatCurrencySymbol, timeframe: WasmTimeframe) => {
17 const results = await get({ thunkArg: [fiat, timeframe] });
18 const [key] = getKey(fiat, timeframe);
26 export const usePriceGraphData = (fiat: WasmFiatCurrencySymbol, timeframe: WasmTimeframe) => {
27 const getPriceGraphData = useGetPriceGraphData();
28 const [, loading] = priceGraphDataHooks.useValue();
30 const priceGraphDataSimpleSelector = createSelector(
32 (result): [WasmPriceGraph | undefined, boolean] => {
33 const key = getKey(fiat, timeframe);
35 const { value } = result;
36 const rate = value?.[key];
38 return [rate, loading];
43 void getPriceGraphData(fiat, timeframe);
44 }, [fiat, getPriceGraphData, timeframe]);
46 return baseUseSelector(priceGraphDataSimpleSelector);