Skip to content

Commit

Permalink
Tidy a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonmanRolls committed Oct 26, 2024
1 parent dcb5a06 commit 4d29b33
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/pages/legacyfavourites.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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;
Expand Down Expand Up @@ -79,21 +82,23 @@ const jsonParseEffect = (input: string): Effect.Effect<LegacyFavorite[], JsonPar
catch: (error) => new JsonParseError(error as string),
})

const setFavoritesProgram = (setState: Dispatch<SetStateAction<SimpleFavorite[] | null>>) =>
pipe(
sync(getLegacyFavorites),
flatMap(jsonParseEffect),
map(simplifyLegacyFavorites),
match({
onFailure: console.error,
onSuccess: setState,
}),
)

export default function Page() {
const [favorites, setFavorites] = useState<SimpleFavorite[] | null>(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 (
Expand Down

0 comments on commit 4d29b33

Please sign in to comment.