Skip to content

Commit

Permalink
Showing btc balance
Browse files Browse the repository at this point in the history
  • Loading branch information
manelgavalda committed Jan 13, 2024
1 parent 4d4820f commit 2050265
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 80 deletions.
3 changes: 2 additions & 1 deletion app/Models/Total.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Total extends Model
protected $casts = [
'price' => 'float',
'balance' => 'float',
'price_eur' => 'float',
'btc_price' => 'float',
'price_eur' => 'float'
'btc_price_eur' => 'float'
];
}
6 changes: 4 additions & 2 deletions app/Services/SupabaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ public function getHistoricalBalances()
return [
'prices' => $balances->pluck('price')->toArray(),
'ethereum' => $balances->pluck('balance')->toArray(),
'bitcoin' => $balances->pluck('btc_price')->toArray(),
'btc_prices' => $balances->pluck('btc_price')->toArray(),
'prices_eur' => $balances->pluck('price_eur')->toArray(),
'btc_prices_eur' => $balances->pluck('btc_price_eur')->toArray(),
'totals' => $balances->map(fn ($balance) => $balance->price * $balance->balance)->toArray(),
'totals_eur' => $balances->map(fn ($balance) => $balance->price_eur * $balance->balance)->toArray(),
'dates' => $balances->map(fn ($balance) => Carbon::parse($balance->created_at)->format('M d Y'))->toArray()
'dates' => $balances->map(fn ($balance) => Carbon::parse($balance->created_at)->format('M d Y'))->toArray(),
'bitcoin' => $balances->map(fn ($balance) => $balance->btc_price ? (($balance->price * $balance->balance) / $balance->btc_price) : null)->toArray()
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function up(): void
$table->string('balance');
$table->string('price_eur');
$table->string('btc_price')->nullable();
$table->string('btc_price_eur')->nullable();
$table->timestamps();
});
}
Expand Down
2 changes: 1 addition & 1 deletion public/build/assets/app2.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion resources/js/Pages/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
:dates="balances.dates"
:data="balances.ethereum"
:total="totals.eth.toFixed(3)"
:subtotal="`(${totals.btc.toFixed(3)} BTC)`"
/>
</div>
<div class="w-1/3">
Expand Down Expand Up @@ -226,6 +227,7 @@
created() {
this.totals = {
usd: this.balances.totals.at(-1),
btc: this.balances.bitcoin.at(-1),
eth: this.balances.ethereum.at(-1),
eur: this.balances.totals_eur.at(-1),
pricesUsd: this.balances.prices.at(-1),
Expand Down Expand Up @@ -282,15 +284,18 @@
this.totals = {
usd: 0,
eth: 0,
btc: 0,
eur: 0,
pricesEur: data.ethereumPrice.eur,
pricesUsd: data.ethereumPrice.usd
pricesUsd: data.ethereumPrice.usd,
btcPricesUsd: data.bitcoinPrice.usd
}
data.balances.forEach(token => {
this.totals.usd += token.price * token.balance
this.totals.eur += token.price_eur * token.balance
this.totals.eth += token.price * token.balance / this.totals.pricesUsd
this.totals.btc += token.price * token.balance / this.totals.btcPricesUsd
})
this.loading = false
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/Dashboard/BalancesChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="flex items-start ">
<div class="text-right mr-2 text-slate-800 dark:text-slate-100">
<div class="text-3xl font-bold">{{ total }}</div>
<div class="text-xl font-semibold h-1">{{ subtotal }}</div>
<div class="text-lg font-semibold h-2">{{ subtotal }}</div>
</div>
<div class="text-sm font-semibold text-white px-1.5 rounded-full" :class="{
'bg-red-700': getChange() < 0,
Expand Down
46 changes: 0 additions & 46 deletions resources/views/components/dashboard/chart.blade.php

This file was deleted.

27 changes: 0 additions & 27 deletions resources/views/components/dashboard/simple-chart.blade.php

This file was deleted.

4 changes: 3 additions & 1 deletion tests/Unit/SupabaseServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ function createEntries($type) {

expect(end($dates))->toBe('Nov 08 2024');
expect(end($this->balances['prices']))->toBe(2000.0);
expect(end($this->balances['bitcoin']))->toBe(20000.0);
expect(end($this->balances['bitcoin']))->toBe(200.0);
expect(end($this->balances['ethereum']))->toBe(2000.0);
expect(end($this->balances['totals']))->toBe(4000000.0);
expect(end($this->balances['prices_eur']))->toBe(1900.0);
expect(end($this->balances['btc_prices']))->toBe(20000.0);
expect(end($this->balances['totals_eur']))->toBe(3800000.0);
expect(end($this->balances['btc_prices_eur']))->toBe(19000.0);

expect(Carbon::parse($dates[0])->lt(Carbon::createFromFormat('M d Y', end($dates))))->toBetrue();
});
Expand Down
1 change: 1 addition & 0 deletions tests/responses/totals.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"price_eur": 1900,
"balance": 2000,
"btc_price": 20000,
"btc_price_eur": 19000,
"created_at": "2024-11-08T00:00:00.000000+00:00"
},
{
Expand Down

0 comments on commit 2050265

Please sign in to comment.