- The displayed values should be seen as estimates. Except for the{' '}
+ All displayed values should be seen as estimates. Except for the{' '}
fixed ASI exchange rate
- , the fiat values fetched from Coingecko and the token
- swap quotes from Uniswap v3 routes are
- constantly changing.
+ , the fiat values fetched from{' '}
+ Coingecko and the token swap quotes
+ from Uniswap v3 routes are constantly
+ changing.
There is no guarantee they reflect the value of your investment once the
diff --git a/components/FormAmount.module.css b/components/FormAmount/FormAmount.module.css
similarity index 100%
rename from components/FormAmount.module.css
rename to components/FormAmount/FormAmount.module.css
diff --git a/components/FormAmount.tsx b/components/FormAmount/FormAmount.tsx
similarity index 100%
rename from components/FormAmount.tsx
rename to components/FormAmount/FormAmount.tsx
diff --git a/components/FormAmount/index.tsx b/components/FormAmount/index.tsx
new file mode 100644
index 0000000..02478c5
--- /dev/null
+++ b/components/FormAmount/index.tsx
@@ -0,0 +1 @@
+export * from './FormAmount'
diff --git a/components/Prices.tsx b/components/Prices.tsx
deleted file mode 100644
index 9408397..0000000
--- a/components/Prices.tsx
+++ /dev/null
@@ -1,161 +0,0 @@
-'use client'
-
-import useSWR from 'swr'
-import { useDebounce } from 'use-debounce'
-import styles from './Prices.module.css'
-import { Result } from './Result'
-import {
- tokens,
- ratioOceanToAsi,
- ratioAgixToAsi,
- ratioFetToAsi
-} from '@/constants'
-import { useState } from 'react'
-import { FormAmount } from './FormAmount'
-import { fetcher, formatNumber } from '@/utils'
-import { Content } from '@/components/Content'
-
-export function Prices() {
- const [amountSwap, setAmountSwap] = useState(100)
- const [debouncedAmountSwap] = useDebounce(amountSwap, 500)
- const [amountBuy, setAmountBuy] = useState(100)
- const [debouncedAmountBuy] = useDebounce(amountBuy, 500)
-
- const { data: dataPrices } = useSWR(
- `/api/prices/?tokens=${tokens.toString()}`,
- fetcher
- )
-
- const { data: dataSwapOceanToAgix } = useSWR(
- `/api/quote/?tokenIn=${tokens[0]}&tokenOut=${tokens[2]}&amountIn=${debouncedAmountSwap}`,
- fetcher
- )
-
- const { data: dataSwapOceanToFet } = useSWR(
- `/api/quote/?tokenIn=${tokens[0]}&tokenOut=${tokens[1]}&amountIn=${debouncedAmountSwap}`,
- fetcher
- )
-
- const priceOcean = dataPrices?.[tokens[0]]?.usd || 0
- const priceFet = dataPrices?.[tokens[1]]?.usd || 0
- const priceAgix = dataPrices?.[tokens[2]]?.usd || 0
- const priceAsi = priceFet
-
- return (
- <>
-
-
-
- Swapping{' '}
- OCEAN (
- {formatNumber(debouncedAmountSwap * priceOcean, 'USD')}) right now
- gets you:
-
-
-
-
-
-
-
-
-
-
-
- Buying with $
- right now
- gets you:
-
-
-
-
-
-
-
- >
- )
-}
diff --git a/components/Result.module.css b/components/ResultRow/ResultRow.module.css
similarity index 100%
rename from components/Result.module.css
rename to components/ResultRow/ResultRow.module.css
diff --git a/components/Result.tsx b/components/ResultRow/ResultRow.tsx
similarity index 91%
rename from components/Result.tsx
rename to components/ResultRow/ResultRow.tsx
index 8aef644..47ae222 100644
--- a/components/Result.tsx
+++ b/components/ResultRow/ResultRow.tsx
@@ -1,5 +1,5 @@
-import styles from './Result.module.css'
-import { formatNumber } from '../utils'
+import styles from './ResultRow.module.css'
+import { formatNumber } from '@/utils'
import Image from 'next/image'
type Props = {
diff --git a/components/ResultRow/index.tsx b/components/ResultRow/index.tsx
new file mode 100644
index 0000000..4a4b4ec
--- /dev/null
+++ b/components/ResultRow/index.tsx
@@ -0,0 +1 @@
+export * from './ResultRow'
diff --git a/components/Strategies/Buy.tsx b/components/Strategies/Buy.tsx
new file mode 100644
index 0000000..954aa34
--- /dev/null
+++ b/components/Strategies/Buy.tsx
@@ -0,0 +1,66 @@
+'use client'
+
+import { ratioOceanToAsi, ratioAgixToAsi, ratioFetToAsi } from '@/constants'
+import { FormAmount } from '../FormAmount'
+import { Result } from '../ResultRow'
+import { useState } from 'react'
+import { useDebounce } from 'use-debounce'
+import styles from './styles.module.css'
+import { usePrices } from '@/hooks'
+
+export function Buy() {
+ const prices = usePrices()
+ const [amountBuy, setAmountBuy] = useState(100)
+ const [debouncedAmountBuy] = useDebounce(amountBuy, 500)
+
+ return (
+
+
+ Buying with $
+ right now
+ gets you:
+
+
+
+
+
+ )
+}
diff --git a/components/Strategies/Swap.tsx b/components/Strategies/Swap.tsx
new file mode 100644
index 0000000..96b659f
--- /dev/null
+++ b/components/Strategies/Swap.tsx
@@ -0,0 +1,86 @@
+'use client'
+
+import {
+ ratioOceanToAsi,
+ ratioAgixToAsi,
+ ratioFetToAsi,
+ tokens
+} from '@/constants'
+import { fetcher, formatNumber } from '@/utils'
+import { FormAmount } from '../FormAmount'
+import { Result } from '../ResultRow'
+import styles from './styles.module.css'
+import { useState } from 'react'
+import useSWR from 'swr'
+import { useDebounce } from 'use-debounce'
+import { usePrices } from '@/hooks'
+
+export function Swap() {
+ const prices = usePrices()
+ const [amountSwap, setAmountSwap] = useState(100)
+ const [debouncedAmountSwap] = useDebounce(amountSwap, 500)
+
+ const { data: dataSwapOceanToAgix } = useSWR(
+ `/api/quote/?tokenIn=${tokens[0]}&tokenOut=${tokens[2]}&amountIn=${debouncedAmountSwap}`,
+ fetcher
+ )
+
+ const { data: dataSwapOceanToFet } = useSWR(
+ `/api/quote/?tokenIn=${tokens[0]}&tokenOut=${tokens[1]}&amountIn=${debouncedAmountSwap}`,
+ fetcher
+ )
+
+ return (
+
+
+ Swapping {' '}
+ OCEAN ({formatNumber(debouncedAmountSwap * prices.ocean, 'USD')}) right
+ now gets you:
+
+
+
+
+
+
+
+
+ )
+}
diff --git a/components/Strategies/index.tsx b/components/Strategies/index.tsx
new file mode 100644
index 0000000..5b6d400
--- /dev/null
+++ b/components/Strategies/index.tsx
@@ -0,0 +1,2 @@
+export * from './Buy'
+export * from './Swap'
diff --git a/components/Prices.module.css b/components/Strategies/styles.module.css
similarity index 56%
rename from components/Prices.module.css
rename to components/Strategies/styles.module.css
index 1b69f7c..3097ed0 100644
--- a/components/Prices.module.css
+++ b/components/Strategies/styles.module.css
@@ -1,11 +1,3 @@
-.grid {
- display: grid;
- gap: 2rem;
- grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
- max-width: calc(var(--max-width) * 1.5);
- margin: 3rem auto;
-}
-
.results {
border: 1px solid rgba(var(--foreground-rgb), 0.2);
border-radius: var(--border-radius);
diff --git a/hooks/index.ts b/hooks/index.ts
new file mode 100644
index 0000000..95409a3
--- /dev/null
+++ b/hooks/index.ts
@@ -0,0 +1 @@
+export * from './use-prices'
diff --git a/hooks/use-prices.tsx b/hooks/use-prices.tsx
new file mode 100644
index 0000000..b20edb3
--- /dev/null
+++ b/hooks/use-prices.tsx
@@ -0,0 +1,19 @@
+'use client'
+
+import { tokens } from '@/constants'
+import { fetcher } from '@/utils'
+import useSWR from 'swr'
+
+export function usePrices() {
+ const { data: dataPrices } = useSWR(
+ `/api/prices/?tokens=${tokens.toString()}`,
+ fetcher
+ )
+
+ const ocean = dataPrices?.[tokens[0]]?.usd || 0
+ const fet = dataPrices?.[tokens[1]]?.usd || 0
+ const agix = dataPrices?.[tokens[2]]?.usd || 0
+ const asi = fet
+
+ return { ocean, fet, agix, asi }
+}