@@ -6,68 +6,64 @@ export default async function({login, q, imports, data, account}, {enabled = fal
6
6
if ( ( ! q . crypto ) || ( ! imports . metadata . plugins . crypto . enabled ( enabled , { extras} ) ) )
7
7
return null
8
8
9
- //Load inputs
10
- let { id, days, vs_currency, precision } = imports . metadata . plugins . crypto . inputs ( { data, account, q} )
9
+ //Load inputs
10
+ let { id, days, vs_currency, precision} = imports . metadata . plugins . crypto . inputs ( { data, account, q} )
11
11
if ( ! id )
12
- throw { error : { message : "Crypto currency id is not set" } }
12
+ throw { error : { message : "Crypto currency id is not set" } }
13
13
14
14
console . debug ( `metrics/compute/${ login } /plugins > crypto > querying api for crypto` )
15
15
16
16
const {
17
- data : coin
18
- } = await imports . axios . get ( `https://api.coingecko.com/api/v3/coins/${ id } ` ,
19
- {
20
- params : {
21
- market_data :true
22
- }
23
- } )
17
+ data : coin ,
18
+ } = await imports . axios . get ( `https://api.coingecko.com/api/v3/coins/${ id } ` , {
19
+ params : {
20
+ market_data : true ,
21
+ } ,
22
+ } )
24
23
25
- if ( ! coin ) {
24
+ if ( ! coin )
26
25
throw { error : { message : "Crypto currency not found" } }
27
- }
28
26
29
27
const {
30
- data : { prices } ,
31
- } = await imports . axios . get ( `https://api.coingecko.com/api/v3/coins/${ id } /market_chart` , {
28
+ data : { prices} ,
29
+ } = await imports . axios . get ( `https://api.coingecko.com/api/v3/coins/${ id } /market_chart` , {
32
30
params : {
33
- vs_currency,
34
- days,
35
- precision
31
+ vs_currency,
32
+ days,
33
+ precision,
36
34
} ,
37
- } )
38
-
35
+ } )
39
36
40
37
const chart = imports . Graph . timeline (
41
- prices . map ( ( y , _ ) => ( { x : new Date ( y [ 0 ] ) , y : y [ 1 ] } ) ) ,
38
+ prices . map ( ( y , _ ) => ( { x : new Date ( y [ 0 ] ) , y : y [ 1 ] } ) ) ,
42
39
{
43
40
low : Math . min ( ...prices . map ( ( y , _ ) => y [ 1 ] ) ) ,
44
41
45
42
high : Math . max ( ...prices . map ( ( y , _ ) => y [ 1 ] ) ) ,
46
43
47
- points : false , text : false ,
44
+ points : false ,
45
+ text : false ,
48
46
width : 480 * ( 1 + data . large ) ,
49
- height : 200
50
- }
47
+ height : 200 ,
48
+ } ,
51
49
)
52
50
53
-
54
51
//Results
55
52
return {
56
53
chart,
57
54
id,
58
55
precision,
59
- days :{ "1" :"Today" , "14" :"2 Weeks" , "30" :"1 Month" , max : "All-time" } [ days ] ,
56
+ days : { "1" : "Today" , "14" : "2 Weeks" , "30" : "1 Month" , max : "All-time" } [ days ] ,
60
57
symbol : coin . symbol ,
61
58
name : coin . name ,
62
59
current_price : coin . market_data . current_price [ vs_currency ] ,
63
60
price_change_percentage_24h : coin . market_data . price_change_percentage_24h ,
64
61
vs_currency,
65
- logo :coin . image . small ,
62
+ logo : coin . image . small ,
66
63
}
67
64
}
68
65
//Handle errors
69
66
catch ( error ) {
70
67
throw imports . format . error ( error )
71
68
}
72
69
}
73
-
0 commit comments