diff --git a/src/pages/legacyfavourites.tsx b/src/pages/legacyfavourites.tsx index e1968f9ae..fc093843a 100644 --- a/src/pages/legacyfavourites.tsx +++ b/src/pages/legacyfavourites.tsx @@ -1,5 +1,6 @@ -import { Effect, pipe } from 'effect' -import { ReactElement, useEffect, useState } from 'react' +/* eslint-disable max-classes-per-file */ +import { Context, Effect, pipe } from 'effect' +import { Dispatch, ReactElement, SetStateAction, useEffect, useState } from 'react' import styled, { css } from 'styled-components' import { useChainId } from 'wagmi' @@ -12,6 +13,8 @@ import { Outlink } from '@app/components/Outlink' import { Content } from '@app/layouts/Content' import { ContentGrid } from '@app/layouts/ContentGrid' +const { succeed, flatMap, map, match, runSync, sync, tap } = Effect + const Container = styled.div( ({ theme }) => css` border-radius: 20px; @@ -79,21 +82,23 @@ const jsonParseEffect = (input: string): Effect.Effect new JsonParseError(error as string), }) +const setFavoritesProgram = (setState: Dispatch>) => + pipe( + sync(getLegacyFavorites), + flatMap(jsonParseEffect), + map(simplifyLegacyFavorites), + match({ + onFailure: console.error, + onSuccess: setState, + }), + ) + export default function Page() { const [favorites, setFavorites] = useState(null) const chainId = useChainId() useEffect(() => { - pipe( - Effect.succeed(getLegacyFavorites()), - Effect.flatMap(jsonParseEffect), - Effect.map(simplifyLegacyFavorites), - Effect.match({ - onFailure: console.error, - onSuccess: setFavorites, - }), - Effect.runSync, - ) + runSync(setFavoritesProgram(setFavorites)) }, []) return (