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: prevent amount to be truncated on transactions headers #851

Merged
merged 18 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
42 changes: 42 additions & 0 deletions app/ViewModels/Concerns/Transaction/InteractsWithTypeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,48 @@ public function hasExtraData(): bool
return false;
}

/**
* The transactions that return `false` are the ones that don't show an
* amount on the transaction details page. We are validating one by one so
* it can be considered within the test coverage driver.
*/
public function hasAmount(): bool
{
if ($this->isDelegateRegistration()) {
return false;
}

if ($this->isEntityRegistration()) {
return false;
}

if ($this->isEntityResignation()) {
return false;
}

if ($this->isEntityUpdate()) {
return false;
}

if ($this->isMultiSignature()) {
return false;
}

if ($this->isVoteCombination()) {
return false;
}

if ($this->isUnvote()) {
return false;
}

if ($this->isVote()) {
return false;
}

return true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make more sense to reverse this, or reducing it completely until there are more "amount" types? 🤔

    public function hasAmount(): bool
    {
        if ($this->isTransfer()) {
            return true;
        }

        if ($this->isMultiPayment()) {
            return true;
        }

        return false;
    }

or

    public function hasAmount(): bool
    {
        return $this->isTransfer() || $this->isMultiPayment();
    }

Copy link
Member Author

@alfonsobries alfonsobries Jun 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexbarnsley by checking the views that don't have the amount I was able to securely say which types don't have the amount, the rest of them used the fallback view and includes other types like "second signature", IPFS, etc. In other words, those types are the ones that have a special template so it's safest to exclude them. (In case you are wondering I tested the condition you proposed and even that the test pass some views are broken)

Regarding the multiline, it was in purpose to ensure the code coverage covers all the conditions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alfonsobries can you add a comment regarding that to the code so the next guy doesn't go and refactor this without prior knowledge


public function isRegistration(): bool
{
if ($this->isDelegateRegistration()) {
Expand Down
2 changes: 1 addition & 1 deletion public/css/app.css

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,7 +1,7 @@
{
"/js/manifest.js": "/js/manifest.js?id=7db827d654313dce4250",
"/js/app.js": "/js/app.js?id=617b2861f2898aba06c3",
"/css/app.css": "/css/app.css?id=8f7bb492f3b821bd620f",
"/css/app.css": "/css/app.css?id=deba9a572ebd2c1a2235",
"/js/vendor.js": "/js/vendor.js?id=d2021daf9ac3eabd5cad",
"/js/chart.js": "/js/chart.js?id=34ccf97ba22038c7b06d",
"/js/clipboard.js": "/js/clipboard.js?id=99d052d4c54fa6c91edc"
Expand Down
33 changes: 23 additions & 10 deletions resources/views/components/general/entity-header-item.blade.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
<div class="entity-header-item {{ $wrapperClass ?? false }}">
@unless($withoutIcon ?? false)
@props([
'title',
'text',
'wrapperClass' => '',
'contentClass' => 'md:ml-4 md:pr-4',
'url' => false,
'withoutIcon' => false,
'icon' => false,
'iconSize' => false,
'avatar' => false,
'truncate' => true,
])

<div class="entity-header-item {{ $wrapperClass }}{{ $truncate ? ' overflow-x-auto truncate' : '' }}">
@unless($withoutIcon)
<div class="hidden items-center md:flex">
<div class="circled-icon text-theme-secondary-900 border-theme-secondary-900 dark:text-theme-secondary-600 dark:border-theme-secondary-600">
@if ($icon ?? false)
@if ($iconSize ?? false)
@if ($icon)
@if ($iconSize)
<x-ark-icon :name="$icon" :size="$iconSize" />
@else
<x-ark-icon :name="$icon" />
@endif
@elseif ($avatar ?? false)
@elseif ($avatar)
<x-general.avatar-small :identifier="$avatar" />
@endif
</div>
</div>
@endunless

<div class="flex flex-col flex-1 justify-between font-semibold truncate space-y-2 p-1 -m-1 {{ $contentClass ?? 'md:ml-4 md:pr-4' }}">
<div class="text-sm leading-tight text-theme-secondary-500 dark:text-theme-secondary-700">{{ $title }}</div>
<div class="flex flex-col flex-1 justify-between font-semibold space-y-2 p-1 -m-1 {{ $contentClass }}{{ $truncate ? ' overflow-x-auto truncate' : '' }}">
<div class="text-sm leading-tight text-theme-secondary-500 dark:text-theme-secondary-700{{ $truncate ? ' truncate' : '' }}">{{ $title }}</div>

@if ($url ?? false)
@if ($url)
<a href="{{ $url }}" class="flex leading-tight link">
<span class="truncate">{{ $text }}</span>
<span class="{{ $truncate ? 'truncate' : 'whitespace-nowrap' }}">{{ $text }}</span>
</a>
@else
<span class="leading-tight truncate text-theme-secondary-900 dark:text-theme-secondary-200">{{ $text }}</span>
<span class="leading-tight text-theme-secondary-900 dark:text-theme-secondary-200{{ $truncate ? ' truncate' : ' whitespace-nowrap' }} ">{{ $text }}</span>
@endif
</div>
</div>
12 changes: 9 additions & 3 deletions resources/views/components/page-headers/transaction.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@
</x-slot>

<x-slot name="bottom">
<div class="grid grid-cols-1 gap-y-8 sm:grid-cols-2 xl:grid-cols-4">
<x-dynamic-component :component="$transaction->headerComponent()" :transaction="$transaction" />
</div>
@if($transaction->hasAmount())
<div class="grid grid-cols-1 gap-y-8 xl:grid-cols-2">
<x-dynamic-component :component="$transaction->headerComponent()" :transaction="$transaction" />
</div>
@else
<div class="grid grid-cols-1 gap-y-8 sm:grid-cols-2 xl:grid-cols-4">
<x-dynamic-component :component="$transaction->headerComponent()" :transaction="$transaction" />
</div>
@endif
</x-slot>
</x-general.entity-header>
</x-ark-container>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
<x-page-headers.transaction.icon-type :model="$transaction" />
<div class="flex flex-col space-y-8 sm:flex-row sm:space-y-0 xl:pr-7 xl:border-r xl:border-theme-secondary-300">
<x-page-headers.transaction.icon-type :model="$transaction" wrapper-class="sm:w-1/2" />

<x-general.entity-header-item
:title="trans('pages.transaction.amount')"
icon="app-supply"
>
<x-slot name="text">
<x-general.amount-fiat-tooltip
:amount="$transaction->amount()"
:fiat="$transaction->amountFiat()"
/>
</x-slot>
</x-general.entity-header-item>
<x-general.entity-header-item
:title="trans('pages.transaction.amount')"
icon="app-supply"
:truncate="false"
>
<x-slot name="text">
<x-general.amount-fiat-tooltip
:amount="$transaction->amount()"
:fiat="$transaction->amountFiat()"
/>
</x-slot>
</x-general.entity-header-item>
</div>

<x-general.entity-header-item
:title="trans('pages.transaction.fee')"
icon="app-monitor"
>
<x-slot name="text">
<x-general.amount-fiat-tooltip
<div class="grid grid-cols-1 gap-y-8 sm:grid-cols-2 xl:pl-7">
<x-general.entity-header-item
:title="trans('pages.transaction.fee')"
:wrapper-class="$wrapperClass ?? ''"
icon="app-monitor"
>
<x-slot name="text">
<x-general.amount-fiat-tooltip
:amount="$transaction->fee()"
:fiat="$transaction->feeFiat()"
/>
</x-slot>
</x-general.entity-header-item>
</x-slot>
</x-general.entity-header-item>

<x-general.entity-header-item
:title="trans('pages.transaction.confirmations')"
icon="app-confirmations"
>
<x-slot name="text">
<x-number>{{ $transaction->confirmations() }}</x-number>
</x-slot>
</x-general.entity-header-item>
<x-general.entity-header-item
:title="trans('pages.transaction.confirmations')"
:wrapper-class="$wrapperClass ?? ''"
icon="app-confirmations"
>
<x-slot name="text">
<x-number>{{ $transaction->confirmations() }}</x-number>
</x-slot>
</x-general.entity-header-item>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<x-general.entity-header-item :title="trans('pages.transaction.transaction_type')" icon="app-transactions.{{ $model->iconType() }}">
<x-general.entity-header-item
:title="trans('pages.transaction.transaction_type')"
icon="app-transactions.{{ $model->iconType() }}"
:wrapper-class="$wrapperClass ?? ''"
>
<x-slot name="text">
@isset($asEntity)
@lang('general.transaction.types.'.$model->entityType())
Expand Down
21 changes: 21 additions & 0 deletions tests/Unit/ViewModels/TransactionViewModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,27 @@
],
]);

it('should determine transactions that doesnt have amount', function (string $type) {
$subject = new TransactionViewModel(Transaction::factory()->{$type}()->create());

expect($subject->hasAmount())->toBeFalse();
})->with([
'delegateRegistration',
'entityRegistration',
'entityResignation',
'entityUpdate',
'multiSignature',
'voteCombination',
'unvote',
'vote',
]);

it('should determine that transactions have amount by default', function () {
$subject = new TransactionViewModel(Transaction::factory()->transfer()->create());

expect($subject->hasAmount())->toBeTrue();
});

it('should determine the direction icon', function () {
expect($this->subject->iconDirection('sender'))->toBeString();
});
Expand Down