File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed
Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 1616 - name : Install modules
1717 run : yarn
1818 - name : Run
19+ env :
20+ COINGECKO_PROXY_AUTHORIZATION_HEADER : ${{ secrets.COINGECKO_PROXY_AUTHORIZATION_HEADER }}
21+ CI_AUTHORIZATION_TOKEN : ${{ secrets.CI_AUTHORIZATION_TOKEN }}
1922 run : yarn pr
Original file line number Diff line number Diff line change @@ -281,6 +281,12 @@ export function setCoingeckoApiUrl(url: string) {
281281 API_URL = url ;
282282}
283283
284+ const coingeckoExtraHeaders = new Map < string , string > ( ) ;
285+
286+ export function setCoingeckoApiExtraHeader ( name : string , value : string ) {
287+ coingeckoExtraHeaders . set ( name , value ) ;
288+ }
289+
284290type VsCurrency = FiatApiSupportedFiatCurrency | FiatApiBridgedFiatCurrency | FiatApiSupportedCryptoCurrency ;
285291export async function getExchangeRates < C extends FiatApiSupportedCryptoCurrency , V extends VsCurrency > (
286292 cryptoCurrencies : C [ ] ,
@@ -510,13 +516,15 @@ function _findTimestampChunk(
510516 } ;
511517}
512518
513- async function _fetch < T > ( input : RequestInfo , init ?: RequestInit ) : Promise < T > {
519+ async function _fetch < T > ( input : RequestInfo ) : Promise < T > {
514520 let result : T | null = null ;
515521 do {
516522 let retry = true ;
517523 try {
518524 // eslint-disable-next-line no-await-in-loop
519- const response = await fetch ( input , init ) ; // throws when user is offline
525+ const response = await fetch ( input , {
526+ headers : [ ...coingeckoExtraHeaders . entries ( ) ] ,
527+ } ) ; // throws when user is offline
520528 if ( ! response . ok ) {
521529 if ( response . status === 400 ) {
522530 retry = false ;
Original file line number Diff line number Diff line change @@ -10,13 +10,25 @@ import {
1010 FiatApiSupportedFiatCurrency ,
1111 getExchangeRates ,
1212 getHistoricExchangeRates ,
13+ setCoingeckoApiUrl ,
14+ setCoingeckoApiExtraHeader ,
1315} from '../src/fiat-api/FiatApi' ;
1416
1517// If tests are failing locally, increase the timeout
1618const timeout = /* use default timeout of 5000 */ 0 ;
1719// const timeout = 300000;
1820
1921describe ( 'FiatApi' , ( ) => {
22+ beforeEach ( ( ) => {
23+ setCoingeckoApiUrl ( 'https://nq-coingecko-proxy.deno.dev/api/v3' ) ;
24+ if ( process . env . COINGECKO_PROXY_AUTHORIZATION_HEADER && process . env . CI_AUTHORIZATION_TOKEN ) {
25+ setCoingeckoApiExtraHeader (
26+ process . env . COINGECKO_PROXY_AUTHORIZATION_HEADER ,
27+ process . env . CI_AUTHORIZATION_TOKEN ,
28+ ) ;
29+ }
30+ } ) ;
31+
2032 it ( 'can fetch current USD rate for BTC' , async ( ) => {
2133 const rate = await getExchangeRates (
2234 [ FiatApiSupportedCryptoCurrency . BTC ] ,
You can’t perform that action at this time.
0 commit comments