From 9ccaf12b09adf1e6a542d724569adb39f822911a Mon Sep 17 00:00:00 2001 From: Taehee Yoon Date: Wed, 22 Nov 2023 04:12:19 +0900 Subject: [PATCH] fix : FusionSDK remove --- package.json | 2 +- src/hooks/use1inch.tsx | 39 ----------------- src/pages/api/getOneInch.ts | 34 --------------- src/pages/api/getQuote.ts | 65 ----------------------------- src/pages/api/tokenPrice.ts | 83 ------------------------------------- yarn.lock | 8 ++-- 6 files changed, 5 insertions(+), 226 deletions(-) delete mode 100644 src/hooks/use1inch.tsx delete mode 100644 src/pages/api/getOneInch.ts delete mode 100644 src/pages/api/getQuote.ts delete mode 100644 src/pages/api/tokenPrice.ts diff --git a/package.json b/package.json index 18828da..5d10fee 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "postcss": "8.4.22", "react": "18.2.0", "react-dom": "18.2.0", - "react-icons": "^4.8.0", + "react-icons": "^4.12.0", "react-transition-state": "1.1.5", "styled-components": "^6.1.1", "tailwindcss": "3.3.1", diff --git a/src/hooks/use1inch.tsx b/src/hooks/use1inch.tsx deleted file mode 100644 index d0c688a..0000000 --- a/src/hooks/use1inch.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { NetworkEnum } from "@1inch/fusion-sdk"; -import axios from "axios"; -import { useCallback } from "react"; - -type Use1inchParams = { - fromTokenAddress: string; - toTokenAddress: string; - amount: string; -}; - -export const CHAIN_MAPPINGS = { - 1: NetworkEnum.ETHEREUM, - 42161: NetworkEnum.ARBITRUM, - 137: NetworkEnum.POLYGON, - // 1101: NetworkEnum.POLYGON, zk version - 100: NetworkEnum.GNOSIS, -} as Record; - -export const use1inch = ({ - fromTokenAddress, - toTokenAddress, - amount, -}: Use1inchParams) => { - const getQuote = useCallback(async () => { - if (fromTokenAddress && toTokenAddress && amount) { - const _quote = await axios.get("/api/getOneInch", { - params: { - fromTokenAddress, - toTokenAddress, - amount, - }, - }); - return _quote; - } - return null; - }, [fromTokenAddress, toTokenAddress, amount]); - - return { getQuote }; -}; diff --git a/src/pages/api/getOneInch.ts b/src/pages/api/getOneInch.ts deleted file mode 100644 index 6def267..0000000 --- a/src/pages/api/getOneInch.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; -import { FusionSDK, NetworkEnum } from "@1inch/fusion-sdk"; - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - const fromTokenAddress = req.query.fromTokenAddress; - const toTokenAddress = req.query.toTokenAddress; - const amount = req.query.amount; - console.log(fromTokenAddress, toTokenAddress, amount); - - try { - const sdk = new FusionSDK({ - url: "https://api.1inch.dev/fusion", - network: NetworkEnum.ETHEREUM, - authKey: process.env.ONE_INCH_API_KEY, - }); - - const quote = await sdk.getQuote({ - fromTokenAddress: fromTokenAddress as string, - toTokenAddress: toTokenAddress as string, - amount: amount as string, - }); - res.status(200).json({ quote }); - return; - } catch (error) { - console.log(error); - res.status(500).json({ - error: "1inch API error", - }); - return; - } -} diff --git a/src/pages/api/getQuote.ts b/src/pages/api/getQuote.ts deleted file mode 100644 index 50a67fa..0000000 --- a/src/pages/api/getQuote.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { FusionSDK, NetworkEnum } from "@1inch/fusion-sdk"; -import type { NextApiRequest, NextApiResponse } from "next"; -import { NextResponse } from "next/server"; -import { parseEther } from "viem"; - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - if (req.method !== "POST") { - res.status(405).json({ error: "Method not allowed" }); - return; - } - - const body = req.body; - let response = null; - - // try { - // response = await axios.get( - // `https://pro-api.coinmarketcap.com/v2/cryptocurrency/info?symbol=${body.fromToken}}`, - // { - // headers: { - // "X-CMC_PRO_API_KEY": process.env.COINMARKETCAP_API_KEY, - // }, - // } - // ); - // } catch (ex) { - // response = null; - // // error - // console.log(ex); - // // reject(ex); - // } - // if (response) { - // // success - // const json = response.data.data; - // return json; - // } - - const fromTokenAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; - const toTokenAddress = "0xdAC17F958D2ee523a2206206994597C13D831ec7"; - const amount = body.amount; - - // return res.json("hello~!"); - - const sdk = new FusionSDK({ - url: "https://api.1inch.dev/fusion", - network: NetworkEnum.ETHEREUM, - authKey: process.env.ONE_INCH_API_KEY, - }); - - try { - const quote = await sdk.getQuote({ - fromTokenAddress: fromTokenAddress as string, - toTokenAddress: toTokenAddress as string, - amount: parseEther(amount.toString()).toString(), - }); - - console.log("getquote :", quote); - - return NextResponse.json({ quote }); - } catch (error) { - console.log(error); - return NextResponse.json({}); - } -} diff --git a/src/pages/api/tokenPrice.ts b/src/pages/api/tokenPrice.ts deleted file mode 100644 index ba4c880..0000000 --- a/src/pages/api/tokenPrice.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { NextApiRequest, NextApiResponse } from "next"; -const Moralis = require("moralis").default; - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - try { - Moralis.start({ - apiKey: process.env.MORALIS_KEY, - }); - - let fetch; - const nodeFetch = await import("node-fetch"); - fetch = nodeFetch.default; - const { query } = req; - - const responseOne = await Moralis.EvmApi.token.getTokenPrice({ - address: query.addressOne, - }); - - const responseTwo = await Moralis.EvmApi.token.getTokenPrice({ - address: query.addressTwo, - }); - - const response = await fetch( - "https://api.exchangerate-api.com/v4/latest/USD" - ); - const data = await response.json(); - const usdToInrRate = data.rates.INR; - const usdToJpyRate = data.rates.JPY; - const usdToKrwRate = data.rates.KRW; - const usdToSgdRate = data.rates.SGD; - const usdToMyrRate = data.rates.MYR; - const usdToIdrRate = data.rates.IDR; - - const usdPrices = { - tokenOne: responseOne.raw.usdPrice, - tokenTwo: responseTwo.raw.usdPrice, - ratio: responseOne.raw.usdPrice / responseTwo.raw.usdPrice, - }; - - const inrPrices = { - tokenOne: usdPrices.tokenOne * usdToInrRate, - tokenTwo: usdPrices.tokenTwo * usdToInrRate, - ratio: usdPrices.ratio, // This ratio remains the same as it's a relative value - }; - - const sgdPrices = { - tokenOne: usdPrices.tokenOne * usdToSgdRate, - tokenTwo: usdPrices.tokenTwo * usdToSgdRate, - ratio: usdPrices.ratio, - }; - - const myrPrices = { - tokenOne: usdPrices.tokenOne * usdToMyrRate, - tokenTwo: usdPrices.tokenTwo * usdToMyrRate, - ratio: usdPrices.ratio, - }; - - const idrPrices = { - tokenOne: usdPrices.tokenOne * usdToIdrRate, - tokenTwo: usdPrices.tokenTwo * usdToIdrRate, - ratio: usdPrices.ratio, - }; - - const jpyPrices = { - tokenOne: usdPrices.tokenOne * usdToJpyRate, - tokenTwo: usdPrices.tokenTwo * usdToJpyRate, - ratio: usdPrices.ratio, // This ratio remains the same as it's a relative value - }; - - const krwPrices = { - tokenOne: usdPrices.tokenOne * usdToKrwRate, - tokenTwo: usdPrices.tokenTwo * usdToKrwRate, - ratio: usdPrices.ratio, // This ratio remains the same as it's a relative value - }; - - return res.status(200).json(usdPrices); - } catch (error) { - return res.status(500).json({ error: "Moralis API error" }); - } -} diff --git a/yarn.lock b/yarn.lock index bdae2a3..b7f5878 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9105,10 +9105,10 @@ react-focus-lock@^2.9.4: use-callback-ref "^1.3.0" use-sidecar "^1.1.2" -react-icons@^4.8.0: - version "4.8.0" - resolved "https://registry.npmjs.org/react-icons/-/react-icons-4.8.0.tgz" - integrity sha512-N6+kOLcihDiAnj5Czu637waJqSnwlMNROzVZMhfX68V/9bu9qHaMIJC4UdozWoOk57gahFCNHwVvWzm0MTzRjg== +react-icons@^4.12.0: + version "4.12.0" + resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-4.12.0.tgz#54806159a966961bfd5cdb26e492f4dafd6a8d78" + integrity sha512-IBaDuHiShdZqmfc/TwHu6+d6k2ltNCf3AszxNmjJc1KUfXdEeRJOKyNvLmAHaarhzGmTSVygNdyu8/opXv2gaw== react-is@^16.13.1, react-is@^16.7.0: version "16.13.1"