Browse Source

Replace axios with fetch

No need for a dependency for simple HTTP requests.
no-contract-setup-message
Thomas Eizinger 3 years ago
parent
commit
47c2fee8c6
No known key found for this signature in database GPG Key ID: 651AC83A6C6C8B96
  1. 1
      frontend/package.json
  2. 3
      frontend/src/Maker.tsx
  3. 7
      frontend/src/Taker.tsx
  4. 9
      frontend/yarn.lock

1
frontend/package.json

@ -24,7 +24,6 @@
"@types/react-table": "^7.7.2",
"@typescript-eslint/eslint-plugin": "^4.30.0",
"@typescript-eslint/parser": "^4.30.0",
"axios": "^0.21.1",
"babel-eslint": "^10.1.0",
"eslint": "^7.32.0",
"eslint-config-react-app": "^6.0.0",

3
frontend/src/Maker.tsx

@ -11,7 +11,6 @@ import {
useToast,
VStack,
} from "@chakra-ui/react";
import axios from "axios";
import React, { useState } from "react";
import { useAsync } from "react-async";
import { Route, Routes } from "react-router-dom";
@ -32,7 +31,7 @@ interface CfdSellOrderPayload {
}
async function postCfdSellOrderRequest(payload: CfdSellOrderPayload) {
let res = await axios.post(`/api/order/sell`, JSON.stringify(payload));
let res = await fetch(`/api/order/sell`, { method: "POST", body: JSON.stringify(payload) });
if (!res.status.toString().startsWith("2")) {
console.log("Status: " + res.status + ", " + res.statusText);

7
frontend/src/Taker.tsx

@ -1,5 +1,4 @@
import { Box, Button, Center, Flex, HStack, SimpleGrid, StackDivider, Text, useToast, VStack } from "@chakra-ui/react";
import axios from "axios";
import React, { useState } from "react";
import { useAsync } from "react-async";
import { Route, Routes } from "react-router-dom";
@ -28,7 +27,7 @@ interface MarginResponse {
}
async function postCfdTakeRequest(payload: CfdTakeRequestPayload) {
let res = await axios.post(`/api/cfd`, JSON.stringify(payload));
let res = await fetch(`/api/cfd`, { method: "POST", body: JSON.stringify(payload) });
if (!res.status.toString().startsWith("2")) {
throw new Error("failed to create new CFD take request: " + res.status + ", " + res.statusText);
@ -36,13 +35,13 @@ async function postCfdTakeRequest(payload: CfdTakeRequestPayload) {
}
async function getMargin(payload: MarginRequestPayload): Promise<MarginResponse> {
let res = await axios.post(`/api/calculate/margin`, JSON.stringify(payload));
let res = await fetch(`/api/calculate/margin`, { method: "POST", body: JSON.stringify(payload) });
if (!res.status.toString().startsWith("2")) {
throw new Error("failed to create new CFD take request: " + res.status + ", " + res.statusText);
}
return res.data;
return res.json();
}
export default function App() {

9
frontend/yarn.lock

@ -3562,13 +3562,6 @@ axe-core@^4.0.2:
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.3.3.tgz#b55cd8e8ddf659fe89b064680e1c6a4dceab0325"
integrity sha512-/lqqLAmuIPi79WYfRpy2i8z+x+vxU3zX2uAm0gs1q52qTuKwolOj1P8XbufpXcsydrpKx2yGn2wzAnxCMV86QA==
axios@^0.21.1:
version "0.21.4"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==
dependencies:
follow-redirects "^1.14.0"
axobject-query@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be"
@ -6214,7 +6207,7 @@ focus-lock@^0.8.1:
dependencies:
tslib "^1.9.3"
follow-redirects@^1.0.0, follow-redirects@^1.14.0:
follow-redirects@^1.0.0:
version "1.14.3"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.3.tgz#6ada78118d8d24caee595595accdc0ac6abd022e"
integrity sha512-3MkHxknWMUtb23apkgz/83fDoe+y+qr0TdgacGIA7bew+QLBo3vdgEN2xEsuXNivpFy4CyDhBBZnNZOtalmenw==

Loading…
Cancel
Save