Skip to content

Commit

Permalink
TW-1194 Remove old 'fetch' method
Browse files Browse the repository at this point in the history
  • Loading branch information
keshan3262 committed Nov 27, 2023
1 parent 2be2d5c commit baae247
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 35 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"bignumber.js": "^9.1.0",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"cross-fetch": "^3.1.5",
"dotenv": "^9.0.2",
"express": "^4.18.2",
"firebase-admin": "^10.0.2",
Expand Down
23 changes: 0 additions & 23 deletions src/utils/fetch.ts

This file was deleted.

24 changes: 21 additions & 3 deletions src/utils/tezos.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { compose, MichelCodecPacker, Signer, TezosToolkit } from '@taquito/taquito';
import { tzip12 } from '@taquito/tzip12';
import { tzip16 } from '@taquito/tzip16';
import axios, { AxiosError } from 'axios';
import memoizee from 'memoizee';

import { ITicker } from '../interfaces/ticker.interface';
import fetch from './fetch';
import { isDefined } from './helpers';
import logger from './logger';
import SingleQueryDataProvider from './SingleQueryDataProvider';
import { BcdTokenData } from './tzkt';

Expand Down Expand Up @@ -53,9 +55,25 @@ export const getStorage = memoizee(
);

const getTezExchangeRate = async () => {
const { price: rawPrice } = await fetch<ITicker>('https://api.binance.com/api/v3/ticker/price?symbol=XTZUSDT');
try {
const { data } = await axios.get<ITicker>('https://api.binance.com/api/v3/ticker/price?symbol=XTZUSDT');

return Number(data.price);
} catch (e) {
if (!(e instanceof AxiosError)) {
logger.error('Request for TEZ exchange rate failed with unknown error');
} else if (isDefined(e.response) && isDefined(e.response.data)) {
logger.error(
`Request for TEZ exchange rate failed with status ${e.response.status} and message ${e.response.data}`
);
} else if (isDefined(e.response) && isDefined(e.response.status)) {
logger.error(`Request for TEZ exchange rate failed with status ${e.response.status}`);
} else {
logger.error('Request for TEZ exchange rate failed without response');
}

return Number(rawPrice);
throw e;
}
};

export const tezExchangeRateProvider = new SingleQueryDataProvider(60000, getTezExchangeRate);
Expand Down
9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1311,13 +1311,6 @@ cross-env@^7.0.3:
dependencies:
cross-spawn "^7.0.1"

cross-fetch@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
dependencies:
node-fetch "2.6.7"

cross-spawn@^6.0.5:
version "6.0.5"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
Expand Down Expand Up @@ -3168,7 +3161,7 @@ nice-try@^1.0.4:
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==

node-fetch@2.6.7, node-fetch@^2.6.1:
node-fetch@^2.6.1:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
Expand Down

0 comments on commit baae247

Please sign in to comment.