@@ -8,17 +8,13 @@ export const convert = async (
8
8
) => {
9
9
fromCurrency = fromCurrency . trim ( ) . toLowerCase ( ) ;
10
10
toCurrency = toCurrency . trim ( ) . toLowerCase ( ) ;
11
- const url = [
12
- 'https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies' ,
13
- fromCurrency ,
14
- toCurrency ,
15
- ] . join ( '/' ) ;
16
11
17
- return await fetch ( url + '.json' )
12
+ return await fetch (
13
+ `https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/${ fromCurrency } .json` ,
14
+ )
18
15
. then ( ( res ) => res . json ( ) )
19
- . then ( ( data ) => value * data [ toCurrency ] ) ;
16
+ . then ( ( data ) => value * data [ fromCurrency ] [ toCurrency ] ) ;
20
17
} ;
21
- // https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@{apiVersion}/{date}/{endpoint}
22
18
23
19
export const convertWithDate = async (
24
20
value : number ,
@@ -33,18 +29,15 @@ export const convertWithDate = async (
33
29
fromCurrency = fromCurrency . trim ( ) . toLowerCase ( ) ;
34
30
toCurrency = toCurrency . trim ( ) . toLowerCase ( ) ;
35
31
36
- // Format date to YYYY-MM-DD
37
- const formattedDate = date . toJSON ( ) . substring ( 0 , 10 ) ;
38
-
39
- const url = [
40
- 'https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1' ,
41
- formattedDate ,
42
- 'currencies' ,
43
- fromCurrency ,
44
- toCurrency ,
45
- ] . join ( '/' ) ;
32
+ // https://github.com/fawazahmed0/exchange-api
33
+ // Format date to YYYY.M.D
34
+ // const formattedDate = date.toJSON().substring(0, 10).replaceAll('-', '.');
35
+ // TODO: Migrated API does not work with historical API yet, so we use latest for now.
36
+ const formattedDate = 'latest' ;
46
37
47
- return await fetch ( url + '.json' )
38
+ return await fetch (
39
+ `https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@${ formattedDate } /v1/${ fromCurrency } .json` ,
40
+ )
48
41
. then ( ( res ) => res . json ( ) )
49
42
. then ( ( data ) => value * data [ toCurrency ] ) ;
50
43
} ;
0 commit comments