Skip to content

Commit

Permalink
maybe server side PricingsProvider issue?
Browse files Browse the repository at this point in the history
  • Loading branch information
junhoyeo committed Oct 12, 2022
1 parent 2eb0466 commit e2b4a50
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions packages/bento-web/src/hooks/pricings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,36 +109,36 @@ interface GetCachedPrice {
(coinGeckoId: string): number;
(coinGeckoIds: string[]): number[];
}
const GetCachedPriceContext = React.createContext<GetCachedPrice>(((
v: string | string[],
) => (typeof v === 'string' ? 0 : [0])) as GetCachedPrice);
const defaultFunc = ((v: string | string[]) =>
typeof v === 'string' ? 0 : [0]) as GetCachedPrice;
const GetCachedPriceContext = React.createContext<GetCachedPrice>(defaultFunc);

export const PricingsProvider: React.FC<React.PropsWithChildren> = ({
children,
}) => {
useCoinGeckoPrices();

const [prices] = useAtom(pricingsAtom);
const setCoinGeckoIds = useSetAtom(coinGeckoIdsAtom);

const getCachedPrice = useCallback(
(coinGeckoId: string | string[]) => {
const single = typeof coinGeckoId === 'string';
const ids = single ? [coinGeckoId] : coinGeckoId;
const res = ids.map((id) => {
if (id in prices) {
return prices[id];
}
setCoinGeckoIds((prev) => (prev.includes(id) ? prev : [...prev, id]));
return 0;
});
return single ? res[0] : res;
},
[prices],
) as GetCachedPrice;
// useCoinGeckoPrices();

// const [prices] = useAtom(pricingsAtom);
// const setCoinGeckoIds = useSetAtom(coinGeckoIdsAtom);

// const getCachedPrice = useCallback(
// (coinGeckoId: string | string[]) => {
// const single = typeof coinGeckoId === 'string';
// const ids = single ? [coinGeckoId] : coinGeckoId;
// const res = ids.map((id) => {
// if (id in prices) {
// return prices[id];
// }
// setCoinGeckoIds((prev) => (prev.includes(id) ? prev : [...prev, id]));
// return 0;
// });
// return single ? res[0] : res;
// },
// [prices],
// ) as GetCachedPrice;

return (
<GetCachedPriceContext.Provider value={getCachedPrice}>
<GetCachedPriceContext.Provider value={defaultFunc}>
{children}
</GetCachedPriceContext.Provider>
);
Expand Down

0 comments on commit e2b4a50

Please sign in to comment.