Skip to content

Commit

Permalink
refactor: output more details for transactions (#1003)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarnsley authored Nov 15, 2024
1 parent 265ea4e commit 04e1cd8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
10 changes: 4 additions & 6 deletions app/Models/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@

/**
* @property string $id
* @property array|null $asset
* @property BigNumber $amount
* @property BigNumber $gas_limit
* @property BigNumber $gas_price
* @property int $timestamp
* @property int $type
* @property int $type_group
* @property int $sequence
* @property string $block_id
* @property string|null $recipient_address
* @property string $sender_public_key
Expand Down Expand Up @@ -71,11 +70,10 @@ final class Transaction extends Model
*/
protected $casts = [
'amount' => BigInteger::class,
'asset' => 'array',
'gas_price' => BigInteger::class,
'gas_limit' => BigInteger::class,
'timestamp' => UnixSeconds::class,
'type_group' => 'int',
'type' => 'int',
'sequence' => 'int',
'block_height' => 'int',
];

Expand Down
21 changes: 21 additions & 0 deletions app/ViewModels/TransactionViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,27 @@ public function nonce(): int
return $this->transaction->nonce;
}

public function gasLimit(): float
{
return UnitConverter::formatUnits((string) $this->transaction->gas_limit, 'wei');
}

public function gasUsed(): float
{
$receipt = $this->transaction->receipt;

if ($receipt === null) {
return 0;
}

return UnitConverter::formatUnits((string) $receipt->gas_used, 'wei');
}

public function sequence(): int
{
return $this->transaction->sequence;
}

public function fee(): float
{
return UnitConverter::formatUnits((string) $this->transaction->fee(), 'gwei');
Expand Down
18 changes: 10 additions & 8 deletions resources/views/components/transaction/page/more-details.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ class="mt-6 sm:hidden"
</x-slot>

<x-tables.rows.mobile.encapsulated.cell :label="trans('pages.transaction.header.gas_limit')">
64,004
{{ ExplorerNumberFormatter::number($transaction->gasLimit()) }}
</x-tables.rows.mobile.encapsulated.cell>

<x-tables.rows.mobile.encapsulated.cell
:label="trans('pages.transaction.header.usage_by_transaction')"
class="pt-3"
>
63,185
{{ ExplorerNumberFormatter::number($transaction->gasUsed()) }}
</x-tables.rows.mobile.encapsulated.cell>
</x-tables.rows.mobile>

Expand All @@ -30,7 +30,7 @@ class="pt-3"
</x-slot>

<x-tables.rows.mobile.encapsulated.cell :label="trans('pages.transaction.header.position_in_block')">
137
{{ $transaction->sequence() }}
</x-tables.rows.mobile.encapsulated.cell>
</x-tables.rows.mobile>

Expand Down Expand Up @@ -90,16 +90,17 @@ class="mt-4 !px-0"

<x-transaction.page.section-detail.row
:title="trans('pages.transaction.header.gas_limit')"
value="64,004"
:value="ExplorerNumberFormatter::number($transaction->gasLimit())"
:transaction="$transaction"
allow-empty
/>

<x-transaction.page.section-detail.row
:title="trans('pages.transaction.header.usage_by_transaction')"
:value="ExplorerNumberFormatter::number($transaction->gasUsed())"
:transaction="$transaction"
>
63,185
</x-transaction.page.section-detail.row>
allow-empty
/>
</x-general.page-section.container>

<x-general.page-section.container
Expand All @@ -114,8 +115,9 @@ class="!px-0"

<x-transaction.page.section-detail.row
:title="trans('pages.transaction.header.position_in_block')"
value="137"
:value="$transaction->sequence()"
:transaction="$transaction"
allow-empty
/>
</x-general.page-section.container>

Expand Down

0 comments on commit 04e1cd8

Please sign in to comment.