3
3
<div class =" bg-dacxi-white h-full" >
4
4
<Header />
5
5
<div
6
- class =" flex justify-between align-center w-8 /12 mx-auto height-adjust"
6
+ class =" flex justify-evenly flex-column flex-md-row align-center w-11/12 sm:w-11 /12 mx-auto height-adjust"
7
7
>
8
8
<div >
9
9
<p class =" text-center text-sm" @click =" updateChart()" >
10
- {{ priceTitle }} test
10
+ {{ priceTitle }}
11
11
</p >
12
12
<div v-if =" loading" class =" flex justify-center mb-7" >
13
13
<v-progress-circular
70
70
>{{ filterButton }}</v-btn
71
71
>
72
72
</div >
73
- <div >
73
+ <div class = " mt-10 mt-md-0 " >
74
74
<div
75
- class =" flex justify-end mb-5 font-weight-bold fade-in fade-out"
75
+ class =" flex justify-center mb-5 font-weight-bold fade-in fade-out"
76
76
>
77
- <h3 >
77
+ <h3 class = " text-base " >
78
78
<span class =" text-capitalize" >{{
79
79
cripto.currentCripto
80
80
}}</span >
84
84
}}</span >
85
85
</h3 >
86
86
</div >
87
- <apexchart
88
- width =" 650"
89
- type =" area"
90
- :options =" options"
91
- :series =" series"
92
- class =" fade-in fade-out"
93
- ></apexchart >
87
+ <div >
88
+ <apexchart
89
+ width =" 600"
90
+ type =" area"
91
+ :options =" options"
92
+ :series =" series"
93
+ class =" fade-in fade-out"
94
+ ></apexchart >
95
+ </div >
94
96
</div >
95
97
</div >
96
98
</div >
97
99
</v-app >
98
100
</template >
99
101
100
102
<script >
101
- import {
102
- getCoinCurrentPrice ,
103
- formatPriceBasedOnCoin ,
104
- getCurrentCoinPriceBasedOnDate ,
105
- convertDateToMiliseconds ,
106
- validateDateBasedOnCrypto ,
107
- disableFutureDates ,
108
- getCoinMarketChart ,
109
- } from ' ./utils/methods'
103
+ import * as gecko from ' ./utils/methods'
104
+ import { mockedData } from ' ./utils/mockedData'
110
105
import Header from ' ./components/Header.vue'
111
106
112
107
export default {
@@ -127,75 +122,18 @@ export default {
127
122
dateTime: ' ' ,
128
123
progressValue: 0 ,
129
124
progressView: true ,
130
- options: {
131
- chart: {
132
- id: ' dacxi-cripto-chart' ,
133
- },
134
- xaxis: {
135
- categories: [],
136
- },
137
- },
138
- series: [
139
- {
140
- name: ' ' ,
141
- data: [],
142
- },
143
- ],
144
- coin: {
145
- coins: [
146
- {
147
- text: ' USD' ,
148
- value: ' usd' ,
149
- },
150
- {
151
- text: ' EUR' ,
152
- value: ' eur' ,
153
- },
154
- {
155
- text: ' BRL' ,
156
- value: ' brl' ,
157
- },
158
- ],
159
- currentCoin: ' usd' ,
160
- },
161
- cripto: {
162
- criptos: [
163
- {
164
- text: ' Ethereum' ,
165
- value: ' ethereum' ,
166
- },
167
- {
168
- text: ' Bitcoin' ,
169
- value: ' bitcoin' ,
170
- },
171
- {
172
- text: ' Luna' ,
173
- value: ' terra-luna' ,
174
- },
175
- {
176
- text: ' Dacxi' ,
177
- value: ' dacxi' ,
178
- },
179
- ],
180
- currentCripto: ' bitcoin' ,
181
- },
125
+ coin: mockedData[0 ],
126
+ cripto: mockedData[1 ],
127
+ options: mockedData[2 ].options ,
128
+ series: mockedData[2 ].series ,
182
129
}),
183
- async mounted () {
184
- this .loadChart ()
130
+ mounted () {
185
131
this .setCripto ()
186
132
this .timerUpdate ()
187
133
},
188
134
methods: {
189
- async loadChart () {
190
- const { prices } = await getCoinMarketChart (
191
- this .cripto .currentCripto ,
192
- this .coin .currentCoin
193
- )
194
- this .series [0 ].data = prices .map ((price ) => price[1 ].toFixed (4 ))
195
- this .series [0 ].name = ' bitcoin $'
196
- },
197
135
async updateChart () {
198
- const { prices } = await getCoinMarketChart (
136
+ const { prices } = await gecko . getCoinMarketChart (
199
137
this .cripto .currentCripto ,
200
138
this .coin .currentCoin
201
139
)
@@ -210,7 +148,7 @@ export default {
210
148
async setCripto () {
211
149
this .loading = true
212
150
this .progressValue = 0
213
- this .price = await getCoinCurrentPrice (
151
+ this .price = await gecko . getCoinCurrentPrice (
214
152
this .cripto .currentCripto ,
215
153
this .coin .currentCoin
216
154
)
@@ -228,47 +166,33 @@ export default {
228
166
}, 100 )
229
167
},
230
168
formatCurrency (value , coin ) {
231
- return formatPriceBasedOnCoin (value, coin)
169
+ return gecko . formatPriceBasedOnCoin (value, coin)
232
170
},
233
171
async setDateTime () {
234
172
if (this .currentTime .date === ' ' || this .currentTime .hour === ' ' ) {
235
173
this .$toast .warning (' Please select a date and hour' )
236
174
return
237
175
}
238
- const fullDate = new Date (
239
- this .currentTime .date + ' ' + this .currentTime .hour
176
+ const fullDate = gecko .mergeDateAndTime (
177
+ this .currentTime .date ,
178
+ this .currentTime .hour
240
179
)
241
- const dateValidation = disableFutureDates (fullDate)
242
- if (dateValidation) {
180
+ if (gecko .disableFutureDates (fullDate)) {
243
181
this .$toast .warning (" You can't select a future date" )
244
182
return
245
183
}
246
184
this .progressView = false
247
185
this .loading = true
248
- const dateResult = validateDateBasedOnCrypto (
186
+ const dateResult = gecko . validateDateBasedOnCrypto (
249
187
this .cripto .currentCripto ,
250
188
fullDate
251
189
)
252
- const fulldatePlusOneHour = new Date (
253
- dateResult .getTime () + 300 * 300 * 1000
254
- )
255
- const fullDateMinusOneHour = new Date (
256
- dateResult .getTime () - 300 * 300 * 1000
257
- )
258
- const result = await getCurrentCoinPriceBasedOnDate (
190
+ const result = await gecko .getCurrentCoinPriceBasedOnDate (
259
191
this .cripto .currentCripto ,
260
192
this .coin .currentCoin ,
261
- fullDateMinusOneHour,
262
- fulldatePlusOneHour
193
+ dateResult
263
194
)
264
- const currentDateTimeStamp = convertDateToMiliseconds (fullDate)
265
- const closestPrice = result .prices .reduce ((prev , curr ) => {
266
- return Math .abs (curr[0 ] - currentDateTimeStamp) <
267
- Math .abs (prev[0 ] - currentDateTimeStamp)
268
- ? curr
269
- : prev
270
- })
271
- this .oldPrice = closestPrice[1 ]
195
+ this .oldPrice = result[1 ]
272
196
this .priceTitle = ' Closest available price'
273
197
this .filterButton = ' Clear filters'
274
198
this .loading = false
0 commit comments