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

feat: update currency tooltips when currency is changed #845

Merged
merged 33 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
042e8d7
Update currency tooltip on latest record tables
alfonsobries Jun 14, 2021
b1f9e31
Refresh block table when currency changes
alfonsobries Jun 14, 2021
a61c5c9
Remove conflicting wire:key
alfonsobries Jun 14, 2021
23ecacb
Block transactions & wallet transaction refresh
alfonsobries Jun 14, 2021
fac74b7
Update currency on wallet header
alfonsobries Jun 14, 2021
72c2633
Test update fiat tooltip
alfonsobries Jun 14, 2021
bafc185
Test block update amounts
alfonsobries Jun 14, 2021
40f7202
test wallet & block transaction tables update
alfonsobries Jun 14, 2021
b58c27f
style: resolve style guide violations
alfonsobries Jun 14, 2021
55aaf6a
style: resolve style guide violations
faustbrian Jun 14, 2021
c6a1248
Wallet voter table update
alfonsobries Jun 14, 2021
395be0e
Merge branch 'develop' into feat/update-currency-stuff-when-changed
ItsANameToo Jun 17, 2021
7cf0130
Merge branch 'develop' of github.com:ArkEcosystem/explorer.ark.io int…
alfonsobries Jun 17, 2021
37a815b
remove wire:key from recipient
alfonsobries Jun 17, 2021
f54b790
Merge branch 'feat/update-currency-stuff-when-changed' of github.com:…
alfonsobries Jun 17, 2021
da201a5
Merge branch 'develop' into feat/update-currency-stuff-when-changed
ItsANameToo Jun 18, 2021
91e89a1
Merge branch 'develop' into feat/update-currency-stuff-when-changed
alfonsobries Jun 18, 2021
2657ef1
Remove unneeded wire:key
alfonsobries Jun 18, 2021
b72aac4
Use new generateId Helper
alfonsobries Jun 18, 2021
9f51fbb
Merge branch 'develop' of github.com:ArkEcosystem/explorer.ark.io int…
alfonsobries Jun 18, 2021
634cda9
style: resolve style guide violations
alfonsobries Jun 18, 2021
3c7f908
typo
alfonsobries Jun 18, 2021
3370e2b
Fix conditions
alfonsobries Jun 18, 2021
b76e781
style: resolve style guide violations
alfonsobries Jun 18, 2021
e56feca
wire:key for wallet transactions table
alfonsobries Jun 18, 2021
8e99e0c
style: resolve style guide violations
alfonsobries Jun 18, 2021
287c943
new wire:key failing test
alfonsobries Jun 18, 2021
a8f0b47
style: resolve style guide violations
alfonsobries Jun 18, 2021
8ce9632
Merge branch 'develop' of github.com:ArkEcosystem/explorer.ark.io int…
alfonsobries Jun 21, 2021
ae18eda
Merge branch 'develop' of github.com:ArkEcosystem/explorer.ark.io int…
alfonsobries Jun 22, 2021
49b89e3
Recompile assets
alfonsobries Jun 22, 2021
38f1e40
chore: rebuild assets
alfonsobries Jun 22, 2021
e09303d
Merge branch 'develop' into feat/update-currency-stuff-when-changed
ItsANameToo Jun 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/Http/Livewire/BlockTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ final class BlockTable extends Component
{
use HasPagination;

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

public function render(): View
{
return view('livewire.block-table', [
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Livewire/BlockTransactionsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ final class BlockTransactionsTable extends Component

public string $blockId;

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

public function mount(string $blockId): void
{
$this->blockId = $blockId;
Expand Down
12 changes: 12 additions & 0 deletions app/Http/Livewire/LatestRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ final class LatestRecords extends Component
use ManagesLatestBlocks;
use ManagesLatestTransactions;

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

public array $state = [
'selected' => 'transactions',
'type' => 'all',
Expand All @@ -34,6 +37,15 @@ public function render(): View
return $this->renderTransactions();
}

public function currencyChanged(): void
{
if ($this->state['selected'] === 'blocks') {
$this->pollBlocks();
} else {
$this->pollTransactions();
}
}

private function renderBlocks(): View
{
if (is_null($this->blocks)) {
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Livewire/TransactionTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ final class TransactionTable extends Component
{
use HasPagination;

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

public array $state = [
'type' => 'all',
];
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Livewire/WalletBalance.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

final class WalletBalance extends Component
{
/** @phpstan-ignore-next-line */
protected $listeners = [
'currencyChanged' => '$refresh',
];

public string $walletAddress;

public function mount(Wallet $wallet): void
Expand Down
1 change: 1 addition & 0 deletions app/Http/Livewire/WalletTransactionTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final class WalletTransactionTable extends Component
/** @phpstan-ignore-next-line */
protected $listeners = [
'filterTransactionsByDirection',
'currencyChanged' => '$refresh',
];

public function mount(string $address, bool $isCold, ?string $publicKey): void
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Livewire/WalletVoterTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ final class WalletVoterTable extends Component
{
use HasPagination;

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

public string $publicKey;

public string $username;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</thead>
<tbody>
@foreach($blocks as $block)
<x-ark-tables.row wire:key="block-{{ $block->id() }}">
<x-ark-tables.row wire:key="block-{{ $block->id() }}-{{ Settings::currency() }}">
<x-ark-tables.cell>
<x-tables.rows.desktop.block-id :model="$block" />
</x-ark-tables.cell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</thead>
<tbody>
@foreach($transactions as $transaction)
<x-ark-tables.row wire:key="transaction-{{ $transaction->id() }}">
<x-ark-tables.row wire:key="transaction-{{ $transaction->id() }}-{{ Settings::currency() }}">
<x-ark-tables.cell>
<x-tables.rows.desktop.transaction-id :model="$transaction" />
</x-ark-tables.cell>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="divide-y table-list-mobile">
@foreach ($blocks as $block)
<div class="table-list-mobile-row">
<div class="table-list-mobile-row" wire:key="mobile-block-{{ $block->id() }}-{{ Settings::currency() }}">
<x-tables.rows.mobile.block-id :model="$block" />

<x-tables.rows.mobile.timestamp :model="$block" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="divide-y table-list-mobile">
@foreach ($transactions as $transaction)
<div class="table-list-mobile-row">
<div class="table-list-mobile-row" wire:key="mobile-transaction-{{ $transaction->id() }}-{{ Settings::currency() }}">
<x-tables.rows.mobile.transaction-id :model="$transaction" />

<x-tables.rows.mobile.timestamp :model="$transaction" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="flex items-center space-x-4" wire:key="sender:{{ $model->id() }}">
<div class="flex items-center space-x-4">
<div class="flex justify-center items-center sender-direction-wrapper">
<div class="flex">
<div class="arrow-direction text-theme-secondary-900 border-theme-secondary-900 dark:text-theme-secondary-600 dark:border-theme-secondary-600">
Expand Down
34 changes: 34 additions & 0 deletions tests/Feature/Http/Livewire/BlockTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
use App\Http\Livewire\BlockTable;
use App\Models\Block;
use App\Models\Scopes\OrderByHeightScope;
use App\Services\Cache\CryptoCompareCache;
use App\Services\NumberFormatter;
use App\Services\Settings;
use App\ViewModels\ViewModelFactory;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Session;
use Livewire\Livewire;
use function Tests\configureExplorerDatabase;

Expand All @@ -28,3 +32,33 @@
$component->assertSee(NumberFormatter::currency($block->fee(), Network::currency()));
}
});

it('should update the records fiat tooltip when currency changed', function () {
Config::set('explorer.networks.development.canBeExchanged', true);

(new CryptoCompareCache())->setPrices('USD', collect([
'2020-10-19' => 24210,
]));

(new CryptoCompareCache())->setPrices('BTC', collect([
'2020-10-19' => 0.1234567,
]));

Block::factory()->create([
'total_amount' => 499 * 1e8,
]);

$component = Livewire::test(BlockTable::class);

$component->assertSeeHtml('data-tippy-content="12,080,790 USD"');
$component->assertDontSeeHtml('data-tippy-content="61.6048933 BTC"');

$settings = Settings::all();
$settings['currency'] = 'BTC';
Session::put('settings', json_encode($settings));

$component->emit('currencyChanged', 'BTC');

$component->assertDontSeeHtml('data-tippy-content="12,080,790 USD"');
$component->assertSeeHtml('data-tippy-content="61.6048933 BTC"');
});
39 changes: 38 additions & 1 deletion tests/Feature/Http/Livewire/BlockTransactionsTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
use App\Http\Livewire\BlockTransactionsTable;
use App\Models\Block;
use App\Models\Transaction;
use App\Services\Cache\CryptoCompareCache;
use App\Services\NumberFormatter;

use App\Services\Settings;
use App\ViewModels\ViewModelFactory;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Session;
use Livewire\Livewire;

it('should list the first transactions for the giving block id', function () {
Expand All @@ -26,3 +29,37 @@
$component->assertSee(NumberFormatter::currency($transaction->fee(), Network::currency()));
}
});

it('should update the records fiat tooltip when currency changed', function () {
Config::set('explorer.networks.development.canBeExchanged', true);

(new CryptoCompareCache())->setPrices('USD', collect([
'2020-10-19' => 24210,
]));

(new CryptoCompareCache())->setPrices('BTC', collect([
'2020-10-19' => 0.1234567,
]));

$block = Block::factory()->create();

Transaction::factory()->create([
'block_id' => $block->id,
'timestamp' => 112982056,
'amount' => 499 * 1e8,
]);

$component = Livewire::test(BlockTransactionsTable::class, ['blockId' => $block->id]);

$component->assertSeeHtml('data-tippy-content="12,080,790 USD"');
$component->assertDontSeeHtml('data-tippy-content="61.6048933 BTC"');

$settings = Settings::all();
$settings['currency'] = 'BTC';
Session::put('settings', json_encode($settings));

$component->emit('currencyChanged', 'BTC');

$component->assertDontSeeHtml('data-tippy-content="12,080,790 USD"');
$component->assertSeeHtml('data-tippy-content="61.6048933 BTC"');
});
19 changes: 19 additions & 0 deletions tests/Feature/Http/Livewire/LatestRecordsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,22 @@
$component->assertSee($transaction->amount());
}
});

it('should poll transactions when currency changed', function () {
$transaction = Transaction::factory()->create();

Livewire::test(LatestRecords::class)
->assertDontSee($transaction->id)
->emit('currencyChanged')
->assertSee($transaction->id);
});

it('should poll blocks when currency changed', function () {
$block = Block::factory()->create();

Livewire::test(LatestRecords::class)
->set('state.selected', 'blocks')
->assertDontSee($block->id)
->emit('currencyChanged')
->assertSee($block->id);
});
36 changes: 35 additions & 1 deletion tests/Feature/Http/Livewire/TransactionTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
use App\Models\Scopes\OrderByTimestampScope;
use App\Models\Transaction;
use App\Models\Wallet;
use App\Services\Cache\CryptoCompareCache;
use App\Services\NumberFormatter;

use App\Services\Settings;
use App\ViewModels\ViewModelFactory;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Session;
use Livewire\Livewire;
use Ramsey\Uuid\Uuid;
use function Tests\configureExplorerDatabase;
Expand Down Expand Up @@ -122,3 +125,34 @@
$component->assertSee(NumberFormatter::currency($transaction->amount(), Network::currency()));
}
});

it('should update the records fiat tooltip when currency changed', function () {
Config::set('explorer.networks.development.canBeExchanged', true);

(new CryptoCompareCache())->setPrices('USD', collect([
'2020-10-19' => 24210,
]));

(new CryptoCompareCache())->setPrices('BTC', collect([
'2020-10-19' => 0.1234567,
]));

Transaction::factory()->create([
'timestamp' => 112982056,
'amount' => 499 * 1e8,
]);

$component = Livewire::test(TransactionTable::class);

$component->assertSeeHtml('data-tippy-content="12,080,790 USD"');
$component->assertDontSeeHtml('data-tippy-content="61.6048933 BTC"');

$settings = Settings::all();
$settings['currency'] = 'BTC';
Session::put('settings', json_encode($settings));

$component->emit('currencyChanged', 'BTC');

$component->assertDontSeeHtml('data-tippy-content="12,080,790 USD"');
$component->assertSeeHtml('data-tippy-content="61.6048933 BTC"');
});
22 changes: 22 additions & 0 deletions tests/Feature/Http/Livewire/WalletBalanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use App\Http\Livewire\WalletBalance;
use App\Models\Wallet;
use App\Services\Cache\CryptoCompareCache;
use App\Services\Settings;
use Carbon\Carbon;
use Illuminate\Support\Facades\Session;
use Livewire\Livewire;

it('should show the balance of the wallet', function () {
Expand All @@ -17,3 +19,23 @@

Livewire::test(WalletBalance::class, ['wallet' => $wallet])->assertSee('0.01 USD');
});

it('updates the balance when currency changes', function () {
(new CryptoCompareCache())->setPrices('USD', collect([
Carbon::now()->format('Y-m-d') => 10,
]));

(new CryptoCompareCache())->setPrices('BTC', collect([
Carbon::now()->format('Y-m-d') => 0.1234567,
]));

$wallet = Wallet::factory()->create(['balance' => 125456]);

$component = Livewire::test(WalletBalance::class, ['wallet' => $wallet])->assertSee('0.01 USD');

$settings = Settings::all();
$settings['currency'] = 'BTC';
Session::put('settings', json_encode($settings));

$component->emit('currencyChanged', 'BTC')->assertSee('0.00015488 BTC');
});
36 changes: 36 additions & 0 deletions tests/Feature/Http/Livewire/WalletTransactionTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
use App\Models\Block;
use App\Models\Transaction;
use App\Models\Wallet;
use App\Services\Cache\CryptoCompareCache;
use App\Services\NumberFormatter;
use App\Services\Settings;
use App\ViewModels\ViewModelFactory;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Session;
use Livewire\Livewire;
use Ramsey\Uuid\Uuid;
use function Tests\configureExplorerDatabase;
Expand Down Expand Up @@ -290,3 +294,35 @@
$component->assertSee($received->id);
$component->assertSee($sent->id);
});

it('should update the records fiat tooltip when currency changed', function () {
Config::set('explorer.networks.development.canBeExchanged', true);

(new CryptoCompareCache())->setPrices('USD', collect([
'2020-10-19' => 24210,
]));

(new CryptoCompareCache())->setPrices('BTC', collect([
'2020-10-19' => 0.1234567,
]));

Transaction::factory()->create([
'sender_public_key' => $this->subject->public_key,
'timestamp' => 112982056,
'amount' => 499 * 1e8,
]);

$component = Livewire::test(WalletTransactionTable::class, [$this->subject->address, false, $this->subject->public_key]);

$component->assertSeeHtml('data-tippy-content="12,080,790 USD"');
$component->assertDontSeeHtml('data-tippy-content="61.6048933 BTC"');

$settings = Settings::all();
$settings['currency'] = 'BTC';
Session::put('settings', json_encode($settings));

$component->emit('currencyChanged', 'BTC');

$component->assertDontSeeHtml('data-tippy-content="12,080,790 USD"');
$component->assertSeeHtml('data-tippy-content="61.6048933 BTC"');
});