mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-21 22:11:37 +01:00
chore: prettier
This commit is contained in:
parent
ba484e55e7
commit
a84131d5f2
1 changed files with 37 additions and 37 deletions
|
@ -1,45 +1,45 @@
|
|||
import { logger } from "../../../helpers/logger";
|
||||
import { requestLimiter } from "../../../helpers/rateLimiter";
|
||||
import { GraphQLString } from "graphql";
|
||||
import { BitcoinPriceType } from "../../../schemaTypes/query/data/bitcoinPrice";
|
||||
import fetch from "node-fetch";
|
||||
import { logger } from '../../../helpers/logger';
|
||||
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||
import { GraphQLString } from 'graphql';
|
||||
import { BitcoinPriceType } from '../../../schemaTypes/query/data/bitcoinPrice';
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const url = "https://blockchain.info/ticker";
|
||||
const url = 'https://blockchain.info/ticker';
|
||||
|
||||
export const getBitcoinPrice = {
|
||||
type: BitcoinPriceType,
|
||||
args: {
|
||||
currency: {
|
||||
type: GraphQLString
|
||||
}
|
||||
},
|
||||
resolve: async (root: any, params: any, context: any) => {
|
||||
await requestLimiter(context.ip, params, "bitcoinPrice", 1, "1s");
|
||||
type: BitcoinPriceType,
|
||||
args: {
|
||||
currency: {
|
||||
type: GraphQLString,
|
||||
},
|
||||
},
|
||||
resolve: async (root: any, params: any, context: any) => {
|
||||
await requestLimiter(context.ip, 'bitcoinPrice');
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const json = await response.json();
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const json = await response.json();
|
||||
|
||||
if (!params.currency && "EUR" in json) {
|
||||
const value = json.EUR;
|
||||
if (!params.currency && 'EUR' in json) {
|
||||
const value = json.EUR;
|
||||
|
||||
return {
|
||||
price: value.last,
|
||||
symbol: value.symbol
|
||||
};
|
||||
} else if (params.currency in json) {
|
||||
const value = json[params.currency];
|
||||
return {
|
||||
price: value.last,
|
||||
symbol: value.symbol,
|
||||
};
|
||||
} else if (params.currency in json) {
|
||||
const value = json[params.currency];
|
||||
|
||||
return {
|
||||
price: value.last,
|
||||
symbol: value.symbol
|
||||
};
|
||||
} else {
|
||||
throw new Error("Problem getting Bitcoin price.");
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error("Error getting bitcoin price: %o", error);
|
||||
throw new Error("Problem getting Bitcoin price.");
|
||||
}
|
||||
}
|
||||
return {
|
||||
price: value.last,
|
||||
symbol: value.symbol,
|
||||
};
|
||||
} else {
|
||||
throw new Error('Problem getting Bitcoin price.');
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('Error getting bitcoin price: %o', error);
|
||||
throw new Error('Problem getting Bitcoin price.');
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue