more refactor for feature structure

This commit is contained in:
Matthias Kretschmann 2024-04-01 14:23:01 +01:00
parent c75354a54d
commit f2991d22df
Signed by: m
GPG Key ID: 606EEEF3C479A91F
19 changed files with 60 additions and 55 deletions

View File

@ -3,16 +3,14 @@ import { Hanken_Grotesk } from 'next/font/google'
import '@/styles/globals.css' import '@/styles/globals.css'
import '@/styles/loading-ui.css' import '@/styles/loading-ui.css'
import Script from 'next/script' import Script from 'next/script'
import { title, description } from '@/constants'
const hankenGrotesk = Hanken_Grotesk({ const hankenGrotesk = Hanken_Grotesk({
subsets: ['latin'], subsets: ['latin'],
variable: '--font-hanken-grotesk' variable: '--font-hanken-grotesk'
}) })
export const metadata: Metadata = { export const metadata: Metadata = { title, description }
title: 'ASI Calculator',
description: 'See how much ASI you get for your OCEAN, AGIX, or FET.'
}
export default function RootLayout({ export default function RootLayout({
children children

View File

@ -1,9 +1,7 @@
import styles from './page.module.css' import styles from './page.module.css'
import { Swap, Buy } from '@/features/strategies' import { Swap, Buy } from '@/features/strategies'
import { Content } from '@/components/Content'
import { Header } from '@/components/Header'
import { Footer } from '@/components/Footer'
import { MarketData } from '@/features/prices' import { MarketData } from '@/features/prices'
import { Content, Footer, Header } from '@/components'
export default function Home() { export default function Home() {
return ( return (

View File

@ -1,11 +1,11 @@
import { metadata } from '@/app/layout' import { title, description } from '@/constants'
import styles from './Header.module.css' import styles from './Header.module.css'
export function Header() { export function Header() {
return ( return (
<header> <header>
<h1 className={styles.title}>{`${metadata.title}`}</h1> <h1 className={styles.title}>{`${title}`}</h1>
<p className={styles.description}>{`${metadata.description}`}</p> <p className={styles.description}>{`${description}`}</p>
</header> </header>
) )
} }

View File

@ -0,0 +1,8 @@
import { InputHTMLAttributes } from 'react'
import styles from './Input.module.css'
type Props = InputHTMLAttributes<HTMLInputElement>
export function Input(props: Props) {
return <input className={styles.input} {...props} />
}

View File

@ -0,0 +1 @@
export * from './Input'

7
components/index.tsx Normal file
View File

@ -0,0 +1,7 @@
export * from './Content'
export * from './Footer'
export * from './Header'
export * from './Input'
export * from './Label'
export * from './Select'
export * from './TokenLogo'

View File

@ -1,5 +1,9 @@
import { Token } from '@/types' import { Token } from '@/types'
export const title = 'ASI Calculator'
export const description =
'See how much ASI you get for your OCEAN, AGIX, or FET.'
export const ratioOceanToAsi = 0.433226 export const ratioOceanToAsi = 0.433226
export const ratioAgixToAsi = 0.43335 export const ratioAgixToAsi = 0.43335
export const ratioFetToAsi = 1 export const ratioFetToAsi = 1

View File

@ -2,8 +2,8 @@
import { ratioOceanToAsi, ratioAgixToAsi, ratioFetToAsi } from '@/constants' import { ratioOceanToAsi, ratioAgixToAsi, ratioFetToAsi } from '@/constants'
import styles from './MarketData.module.css' import styles from './MarketData.module.css'
import { usePrices } from '@/features/prices/hooks' import { usePrices } from '@/features/prices'
import { Label } from '@/components/Label' import { Label } from '@/components'
export function MarketData() { export function MarketData() {
const { prices, isValidating, isLoading } = usePrices() const { prices, isValidating, isLoading } = usePrices()

View File

@ -1,3 +1,5 @@
'use client'
import { tokens } from '@/constants' import { tokens } from '@/constants'
import { fetcher, getTokenAddressBySymbol } from '@/lib/utils' import { fetcher, getTokenAddressBySymbol } from '@/lib/utils'
import useSWR from 'swr' import useSWR from 'swr'

View File

@ -1,8 +1,7 @@
import { InputAmount } from './Inputs/InputAmount'
import styles from './FormAmount.module.css' import styles from './FormAmount.module.css'
import { Dispatch, SetStateAction } from 'react' import { Dispatch, SetStateAction } from 'react'
import { TokenSymbol } from '@/types' import { TokenSymbol } from '@/types'
import { Select } from '@/components/Select' import { Select, Input } from '@/components'
export function FormAmount({ export function FormAmount({
amount, amount,
@ -17,6 +16,16 @@ export function FormAmount({
setToken?: Dispatch<SetStateAction<TokenSymbol>> setToken?: Dispatch<SetStateAction<TokenSymbol>>
isFiat?: boolean isFiat?: boolean
}) { }) {
function handleAmountChange(e: React.ChangeEvent<HTMLInputElement>) {
const { value } = e.target
if (value === '') {
setAmount(0)
} else {
setAmount(Number(value))
}
}
function handleTokenChange(e: React.ChangeEvent<HTMLSelectElement>) { function handleTokenChange(e: React.ChangeEvent<HTMLSelectElement>) {
if (!setToken) return if (!setToken) return
setToken(e.target.value as TokenSymbol) setToken(e.target.value as TokenSymbol)
@ -32,7 +41,16 @@ export function FormAmount({
return ( return (
<form className={styles.form}> <form className={styles.form}>
<InputAmount amount={amount} setAmount={setAmount} /> <Input
type="text"
inputMode="numeric"
pattern="[0-9]*"
value={amount}
onChange={handleAmountChange}
style={{
width: Math.min(Math.max(amount.toString().length, 2), 50) + 'ch'
}}
/>
<Select <Select
options={options} options={options}

View File

@ -1,34 +0,0 @@
import { Dispatch, SetStateAction } from 'react'
import styles from './InputAmount.module.css'
export function InputAmount({
amount,
setAmount
}: {
amount: number
setAmount: Dispatch<SetStateAction<number>>
}) {
function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
const { value } = e.target
if (value === '') {
setAmount(0)
} else {
setAmount(Number(value))
}
}
return (
<input
className={styles.input}
type="text"
inputMode="numeric"
pattern="[0-9]*"
value={amount}
onChange={handleChange}
style={{
width: Math.min(Math.max(amount.toString().length, 2), 50) + 'ch'
}}
/>
)
}

View File

@ -1,6 +1,6 @@
import styles from './FormMarket.module.css' import styles from './FormMarket.module.css'
import { Dispatch, SetStateAction } from 'react' import { Dispatch, SetStateAction } from 'react'
import { Select } from '@/components/Select' import { Select } from '@/components'
import { type Market } from '@/features/strategies' import { type Market } from '@/features/strategies'
export function FormMarket({ export function FormMarket({

View File

@ -1,7 +1,7 @@
import styles from './Result.module.css' import styles from './Result.module.css'
import { formatNumber } from '@/lib/utils' import { formatNumber } from '@/lib/utils'
import { ArrowRightIcon } from '@radix-ui/react-icons' import { ArrowRightIcon } from '@radix-ui/react-icons'
import { TokenLogo } from '../../../../components/TokenLogo/TokenLogo' import { TokenLogo } from '@/components'
import { Token } from '@/types' import { Token } from '@/types'
type Props = { type Props = {

View File

@ -1,8 +1,8 @@
import { ratioOceanToAsi, ratioAgixToAsi, ratioFetToAsi } from '@/constants' import { ratioOceanToAsi, ratioAgixToAsi, ratioFetToAsi } from '@/constants'
import { usePrices, type Prices } from '@/features/prices'
import { getTokenBySymbol } from '@/lib/utils' import { getTokenBySymbol } from '@/lib/utils'
import { TokenSymbol } from '@/types' import { type TokenSymbol } from '@/types'
import { useQuote, type Market } from '@/features/strategies' import { usePrices } from '@/features/prices'
import { type Market, useQuote } from '@/features/strategies'
import { Result } from '../Result' import { Result } from '../Result'
export function SwapResults({ export function SwapResults({

View File

@ -0,0 +1 @@
export * from './Swap'

View File

@ -1,3 +1,5 @@
'use client'
import { TokenSymbol } from '@/types' import { TokenSymbol } from '@/types'
import { getTokenAddressBySymbol, fetcher } from '@/lib/utils' import { getTokenAddressBySymbol, fetcher } from '@/lib/utils'
import useSWR from 'swr' import useSWR from 'swr'

View File

@ -1,4 +1,4 @@
export * from './components/Buy' export * from './components/Buy'
export * from './components/Swap/Swap' export * from './components/Swap'
export * from './hooks' export * from './hooks'
export * from './types' export * from './types'