diff --git a/package.json b/package.json index 406d31f7..0081cec5 100644 --- a/package.json +++ b/package.json @@ -71,10 +71,6 @@ "typescript": "5.3.2", "vitest": "^2.0.2" }, - "resolution": { - "axios-extensions": "3.1.7", - "axios": "1.7.2" - }, "version": "1.0.1", "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/packages/oraidex-common-ui/package.json b/packages/oraidex-common-ui/package.json index 7708e7ce..5ca65358 100644 --- a/packages/oraidex-common-ui/package.json +++ b/packages/oraidex-common-ui/package.json @@ -15,8 +15,6 @@ }, "license": "MIT", "dependencies": { - "axios-extensions": "3.1.7", - "axios": "1.7.2", "react": "^18.2.0", "react-dom": "^18.2.0", "react-use": "17.4.0" diff --git a/packages/oraidex-common-ui/src/components/TVChartContainer/helpers/requests.ts b/packages/oraidex-common-ui/src/components/TVChartContainer/helpers/requests.ts index c40ae51f..e9a1d38f 100644 --- a/packages/oraidex-common-ui/src/components/TVChartContainer/helpers/requests.ts +++ b/packages/oraidex-common-ui/src/components/TVChartContainer/helpers/requests.ts @@ -1,21 +1,5 @@ import { PeriodParams } from "../charting_library"; import { Bar } from "./types"; -import Axios, { AxiosAdapter } from "axios"; -import { throttleAdapterEnhancer, retryAdapterEnhancer } from "axios-extensions"; - -const AXIOS_TIMEOUT = 10000; -const AXIOS_THROTTLE_THRESHOLD = 2000; -const axios = Axios.create({ - timeout: AXIOS_TIMEOUT, - retryTimes: 3, - // cache will be enabled by default in 2 seconds - adapter: retryAdapterEnhancer( - throttleAdapterEnhancer(Axios.defaults.adapter as AxiosAdapter, { - threshold: AXIOS_THROTTLE_THRESHOLD - }) - ), - baseURL: "https://api.oraidex.io" -}); export const getTokenChartPrice = async ( pair: string, @@ -23,15 +7,20 @@ export const getTokenChartPrice = async ( resolution: string ): Promise => { try { - const res = await axios.get("/v1/candles", { - params: { - pair, - startTime: periodParams.from, - endTime: periodParams.to, - tf: +resolution * 60 - } + const baseUrl = `https://api.oraidex.io/v1` + const response = await fetch(`${baseUrl}/candles?pair=${pair}&startTime=${periodParams.from}&endTime=${periodParams.to}&tf=${+resolution * 60}`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, }); - return res.data; + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const data = await response.json(); + return data; } catch (e) { console.error("GetTokenChartPrice", e); return []; diff --git a/packages/oraidex-common/package.json b/packages/oraidex-common/package.json index 48940a92..c0a0b888 100644 --- a/packages/oraidex-common/package.json +++ b/packages/oraidex-common/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-common", - "version": "2.0.12", + "version": "2.0.13", "main": "./build/index.js", "module": "./build/index.js", "types": "./build/index.d.ts", @@ -13,8 +13,6 @@ }, "license": "MIT", "dependencies": { - "axios-extensions": "3.1.7", - "axios": "1.7.2", "@ethersproject/providers": "^5.0.10", "ethers": "^5.0.15", "@keplr-wallet/types": "^0.11.38", diff --git a/packages/oraidex-common/src/axios-request.ts b/packages/oraidex-common/src/axios-request.ts deleted file mode 100644 index f8612bf6..00000000 --- a/packages/oraidex-common/src/axios-request.ts +++ /dev/null @@ -1,20 +0,0 @@ -import Axios, { AxiosAdapter } from "axios"; -import { cacheAdapterEnhancer, throttleAdapterEnhancer, retryAdapterEnhancer } from "axios-extensions"; - -export async function getAxios(baseUrl?: string) { - const AXIOS_TIMEOUT = 10000; - const AXIOS_THROTTLE_THRESHOLD = 2000; - const axios = Axios.create({ - timeout: AXIOS_TIMEOUT, - retryTimes: 3, - // cache will be enabled by default in 2 seconds - // adapter: retryAdapterEnhancer( - // throttleAdapterEnhancer(Axios.defaults.adapter!, { - // threshold: AXIOS_THROTTLE_THRESHOLD - // }) - // ), - baseURL: baseUrl - }); - - return { axios }; -} diff --git a/packages/oraidex-common/src/index.ts b/packages/oraidex-common/src/index.ts index 6a6ea262..3a10d43c 100644 --- a/packages/oraidex-common/src/index.ts +++ b/packages/oraidex-common/src/index.ts @@ -1,4 +1,3 @@ -export * from "./axios-request"; export * from "./bigdecimal"; export * from "./config/chainInfosWithIcon"; export * from "./constant"; diff --git a/packages/universal-swap/src/helper.ts b/packages/universal-swap/src/helper.ts index 77be0389..1c5419eb 100644 --- a/packages/universal-swap/src/helper.ts +++ b/packages/universal-swap/src/helper.ts @@ -41,7 +41,6 @@ import { oraib2oraichainTest, getSubAmountDetails, // evmChains, - getAxios, // parseAssetInfoFromContractAddrOrDenom, parseAssetInfo, calculateTimeoutTimestamp, @@ -704,7 +703,6 @@ export class UniversalSwapHelper { offerAmount: string, routerConfig: RouterConfigSmartRoute ): Promise => { - const { axios } = await getAxios(routerConfig.url); const data = { sourceAsset: parseAssetInfo(offerInfo), sourceChainId: offerChainId, @@ -720,13 +718,24 @@ export class UniversalSwapHelper { ignoreFee: routerConfig.ignoreFee } }; - const res: { - data: SmartRouterResponse; - } = await axios.post(routerConfig.path, data); + + const response = await fetch(routerConfig.url + routerConfig.path, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data), + }); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const res = await response.json(); return { - swapAmount: res.data.swapAmount, - returnAmount: res.data.returnAmount, - routes: res.data.routes + swapAmount: res.swapAmount, + returnAmount: res.returnAmount, + routes: res.routes }; }; diff --git a/packages/universal-swap/src/universal-demos/handle-simulate-swap.ts b/packages/universal-swap/src/universal-demos/handle-simulate-swap.ts index 712bd90f..e2d82e5d 100644 --- a/packages/universal-swap/src/universal-demos/handle-simulate-swap.ts +++ b/packages/universal-swap/src/universal-demos/handle-simulate-swap.ts @@ -8,7 +8,7 @@ const simulate = async () => { const oraidexCommon = await OraidexCommon.load(); const flattenTokens = oraidexCommon.flattenTokens; - let originalFromToken = flattenTokens.find((t) => t.chainId === "0x38" && t.coinGeckoId === "oraichain-token"); + let originalFromToken = flattenTokens.find((t) => t.chainId === "Oraichain" && t.coinGeckoId === "tether"); let originalToToken = flattenTokens.find((t) => t.chainId === "Oraichain" && t.coinGeckoId === "oraichain-token"); if (!originalFromToken) throw generateError("Could not find original from token"); @@ -31,6 +31,8 @@ const simulate = async () => { protocols: ["Oraidex", "OraidexV3", "Osmosis"] } }); + console.log({ res }); + } catch (error) { console.log("error: ", error); } diff --git a/yarn.lock b/yarn.lock index aae03e30..5932ff28 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7002,7 +7002,7 @@ axios@0.21.4, axios@^0.21.1, axios@^0.21.2: dependencies: follow-redirects "^1.14.0" -axios@1.7.2, axios@^1.6.0, axios@^1.6.2, axios@^1.6.8: +axios@1.7.2: version "1.7.2" resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.2.tgz#b625db8a7051fbea61c35a3cbb3a1daa7b9c7621" integrity sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw== @@ -7026,6 +7026,15 @@ axios@^0.27.2: follow-redirects "^1.14.9" form-data "^4.0.0" +axios@^1.6.0, axios@^1.6.2, axios@^1.6.8: + version "1.9.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.9.0.tgz#25534e3b72b54540077d33046f77e3b8d7081901" + integrity sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg== + dependencies: + follow-redirects "^1.15.6" + form-data "^4.0.0" + proxy-from-env "^1.1.0" + axios@^1.6.7, axios@^1.7.4: version "1.7.7" resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.7.tgz#2f554296f9892a72ac8d8e4c5b79c14a91d0a47f"