Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: price stat chart refresh #754

Merged
merged 11 commits into from
May 28, 2021
3 changes: 3 additions & 0 deletions app/Http/Livewire/PriceStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ final class PriceStats extends Component
{
public bool $placeholder = false;

/** @phpstan-ignore-next-line */
protected $listeners = ['refreshNetworkStatusBlock' => '$refresh'];

public function mount(bool $placeholder = false) : void
{
$this->placeholder = $placeholder;
Expand Down
12 changes: 11 additions & 1 deletion app/Services/CryptoCompare.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,17 @@ public static function historicalHourly(string $source, string $target, int $lim

return collect($result)
->groupBy(fn ($day) => Carbon::createFromTimestamp($day['time'])->format($format))
->mapWithKeys(fn ($transactions, $day) => [$day => NumberFormatter::number($transactions->sum('close'))]);
->mapWithKeys(function ($transactions, $day) use ($target): array {
if (ExchangeRate::isFiat($target)) {
return [
$day => NumberFormatter::number($transactions->sum('close')),
];
}

return [
$day => NumberFormatter::currency($transactions->sum('close'), '', 8),
];
});
});
}
}
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"/js/manifest.js": "/js/manifest.js?id=7db827d654313dce4250",
"/js/app.js": "/js/app.js?id=d829404a24aac8f97aa9",
"/js/app.js": "/js/app.js?id=d32d2105a320cbd75b45",
"/css/app.css": "/css/app.css?id=00959284b45a387c419a",
"/js/vendor.js": "/js/vendor.js?id=d2021daf9ac3eabd5cad",
"/js/chart.js": "/js/chart.js?id=34ccf97ba22038c7b06d",
Expand Down
7 changes: 4 additions & 3 deletions resources/js/price-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const PriceChart = (
darkMode,
time
) => {
// The `0.02` is to left some space to prevent the border to be cropped
const maxValue = Math.max.apply(Math, values) + 0.02;
const minValue = Math.min.apply(Math, values) - 0.02;
// The margin is used to not cut the line at the top/bottom
const margin = Math.max.apply(Math, values) * 0.01;
const maxValue = Math.max.apply(Math, values) + margin;
const minValue = Math.min.apply(Math, values) - margin;

return {
time: time,
Expand Down
1 change: 1 addition & 0 deletions resources/views/livewire/price-stats.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class="flex flex-grow justify-between ml-3 h-full"

<div class="hidden flex-grow justify-end lg:flex" >
<div
wire:key="{{ Settings::currency() }}"
class="ml-6"
style="width: 120px; height: 40px;"
x-data="PriceChart(
Expand Down