diff --git a/app/components/strk-to-usd.tsx b/app/components/strk-to-usd.tsx new file mode 100644 index 0000000..b2e679d --- /dev/null +++ b/app/components/strk-to-usd.tsx @@ -0,0 +1,63 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +"use client"; + +import { useEffect, useState } from "react"; +import { EqualApproximately } from "lucide-react"; + +interface STRKtoUSDTDisplayProps { + amount: number; +} + +const COINGECKO_API = + "https://mainnet-api.ekubo.org/price/STRK/USDC/history?interval=60"; + +export default function STRKtoUSDTDisplay({ amount }: STRKtoUSDTDisplayProps) { + const [rate, setRate] = useState(null); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + + const fetchRate = async () => { + setLoading(true); + setError(null); + try { + const res = await fetch(COINGECKO_API); + console.log(res); + if (!res.ok) throw new Error("Failed to fetch price"); + const data = await res.json(); + const price = data?.data[0]?.min; + console.log("price and data are: and data " + data, price) + if (typeof price !== "number") throw new Error("Invalid price data"); + setRate(price); + } catch (err: any) { + setError(err.message || "Unknown error"); + } finally { + setLoading(false); + } + }; + + useEffect(() => { + fetchRate(); + const interval = setInterval(fetchRate, 30000); + return () => clearInterval(interval); + }, []); + + let content; + if (loading) { + content = ...; + } else if (error) { + content = Error; + } else if (rate !== null) { + const usdt = (amount * rate).toLocaleString(undefined, { + maximumFractionDigits: 2, + minimumFractionDigits: 2, + }); + content = ( +
+ + {usdt} USD +
+ ); + } + + return {content}; +} \ No newline at end of file diff --git a/app/hooks/useSubscription.ts b/app/hooks/useSubscription.ts index 709ca47..80bf97f 100644 --- a/app/hooks/useSubscription.ts +++ b/app/hooks/useSubscription.ts @@ -21,7 +21,7 @@ export function useSubscription(swapAmount: string) { : BigInt(0), ], ERC20_ABI, - STRK_TOKEN.contractAddress + STRK_TOKEN.contractAddress, ); useEffect(() => { diff --git a/app/hooks/useUnsubscribe.ts b/app/hooks/useUnsubscribe.ts index abaa04d..89e302a 100644 --- a/app/hooks/useUnsubscribe.ts +++ b/app/hooks/useUnsubscribe.ts @@ -15,7 +15,7 @@ export default function useUnsubscribe() { "approve", [swappr_contract_address, 0], ERC20_ABI, - strk_token_contract_address + strk_token_contract_address, ); useEffect(() => { diff --git a/app/overview/page.tsx b/app/overview/page.tsx index 2e8acd9..e8b5907 100644 --- a/app/overview/page.tsx +++ b/app/overview/page.tsx @@ -2,7 +2,7 @@ import { useState } from "react"; import { createPortal } from "react-dom"; -import { EqualApproximately, LoaderCircle, Settings } from "lucide-react"; +import { LoaderCircle, Settings } from "lucide-react"; // import type { TokenPair } from "../utils/types"; import SubscribeForm from "../components/subscribe-form"; @@ -13,6 +13,7 @@ import { Modal } from "../components/modal"; // import strk from "../../public/coin-logos/strk-logo.svg"; import TranscationHistory from "./transcation-history"; import ChangeAutoswapSettings from "../components/ui/modals/change-autoswap-settings"; +import STRKtoUSDTDisplay from "../components/strk-to-usd"; export default function Overview() { // State Management @@ -112,7 +113,7 @@ export default function Overview() {

Your Autoswap threshold is set to convert:

- +
- - - - 809 USDT +
diff --git a/app/utils/helper.ts b/app/utils/helper.ts index ab5a8a0..be85a32 100644 --- a/app/utils/helper.ts +++ b/app/utils/helper.ts @@ -21,7 +21,7 @@ export function useContractFetch( abi: any, functionName: string, address: `0x${string}`, - args: any[] = [] + args: any[] = [], ) { const { data, isLoading, refetch, isFetching, error } = useReadContract({ abi: abi, @@ -37,7 +37,7 @@ export function useContractWriteUtility( functionName: string, args: any[], abi: any, - contract_address: `0x${string}` + contract_address: `0x${string}`, ) { const { contract } = useContract({ abi, address: contract_address }); @@ -111,7 +111,7 @@ export async function createSubscription(data: { "Content-Type": "application/json", }, body: JSON.stringify(data), - } + }, ); console.log(response); @@ -140,7 +140,7 @@ export async function deleteSubscription(data: { "Content-Type": "application/json", }, body: JSON.stringify(data), - } + }, ); console.log(response); diff --git a/package.json b/package.json index 0ad9e12..d67d041 100644 --- a/package.json +++ b/package.json @@ -48,4 +48,4 @@ "typescript": "^5" }, "packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c" -} \ No newline at end of file +} diff --git a/tailwind.config.ts b/tailwind.config.ts index e0e4807..e5e2859 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -12,13 +12,13 @@ export default { }, extend: { colors: { - "accent": "var(--accent)", - "grey": { + accent: "var(--accent)", + grey: { 300: "var(--grey-300)", 700: "var(--grey-700)", 900: "var(--grey-900)", 1100: "var(--grey-1100)", - } + }, }, screens: { sm: "576px",