Skip to content

Commit 4f20155

Browse files
authored
feat: improve the summary of parent CONTRACTCALL transactions (#1887)
Signed-off-by: Simon Viénot <simon.vienot@icloud.com>
1 parent b285d01 commit 4f20155

File tree

6 files changed

+50
-31
lines changed

6 files changed

+50
-31
lines changed

src/components/transaction/TransactionAnalyzer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ export class TransactionAnalyzer {
6161
? computeNetAmount(this.transaction.value?.transfers, this.transaction.value?.charged_tx_fee)
6262
: 0)
6363

64+
public readonly hasRewardTransfers: ComputedRef<boolean> = computed(() =>
65+
this.transaction.value ? this.transaction.value.staking_reward_transfers.length >= 1 : false
66+
)
67+
public readonly hasNftTransfers: ComputedRef<boolean> = computed(() =>
68+
this.transaction.value ? this.transaction.value.nft_transfers.length >= 1 : false
69+
)
70+
public readonly hasTokenTransfers: ComputedRef<boolean> = computed(() =>
71+
this.transaction.value ? this.transaction.value.token_transfers.length >= 1 : false
72+
)
73+
6474
public readonly operatorAccount: ComputedRef<string | null> = computed(() =>
6575
this.transaction.value ? makeOperatorAccountLabel(this.transaction.value) : null
6676
)

src/components/transaction/TransactionSummary.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<template>
88
<template v-if="transaction">
99
<TransferGraphSection v-if="shouldGraph"
10-
v-bind:transaction="transactionDetail"
10+
v-bind:analyzer="transactionAnalyzer"
1111
v-bind:compact="true"/>
1212
<div v-else-if="isTokenAssociation">
1313
{{ transaction?.entity_id }}
@@ -56,7 +56,16 @@ const props = defineProps({
5656
})
5757
5858
const shouldGraph = computed(() => {
59-
return props.transaction?.name && GRAPH_TRANSACTION_TYPES.indexOf(props.transaction.name) != -1
59+
let result: boolean
60+
if (props.transaction?.name) {
61+
const alwaysGraph = GRAPH_TRANSACTION_TYPES.indexOf(props.transaction.name) != -1
62+
const contractCallWithTransfer = props.transaction.name === TransactionType.CONTRACTCALL
63+
&& (netAmount.value > 0 || hasTokenTransfers.value || hasNftTransfers.value)
64+
result = alwaysGraph || contractCallWithTransfer
65+
} else {
66+
result = false
67+
}
68+
return result
6069
})
6170
6271
const transactionAnalyzer = new TransactionAnalyzer(computed(() => props.transaction ?? null))
@@ -82,6 +91,9 @@ const transactionDetail = computed(() => {
8291
return props.transaction as TransactionDetail | undefined
8392
})
8493
94+
const netAmount = transactionAnalyzer.netAmount
95+
const hasTokenTransfers = transactionAnalyzer.hasTokenTransfers
96+
const hasNftTransfers = transactionAnalyzer.hasNftTransfers
8597
const isTokenAssociation = transactionAnalyzer.isTokenAssociation
8698
const isEthereumTransaction = transactionAnalyzer.isEthereumTransaction
8799
const tokens = transactionAnalyzer.tokens

src/components/transfer_graphs/TransferGraphSection.vue

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,38 @@
1010
<HbarTransferGraphC
1111
v-if="netAmount > 0"
1212
data-cy="hbarTransfers"
13-
v-bind:transaction="transaction"/>
13+
v-bind:transaction="transaction ?? undefined"/>
1414
</template>
1515
<template v-else>
1616
<HbarTransferGraphF
1717
data-cy="hbarTransfers"
1818
title="Hbar Transfers"
1919
v-bind:class="{'mb-4': displayRewardTransfers || displayNftTransfers || displayTokenTransfers}"
20-
v-bind:transaction="transaction"/>
20+
v-bind:transaction="transaction ?? undefined"/>
2121
</template>
2222

2323
<NftTransferGraph
2424
data-cy="nftTransfers"
2525
v-bind:class="{'mb-4': !compact && (displayTokenTransfers || displayRewardTransfers)}"
26-
v-bind:transaction="transaction"
26+
v-bind:transaction="transaction ?? undefined"
2727
v-bind:compact="compact"/>
2828

2929
<template v-if="compact">
3030
<TokenTransferGraphC
3131
data-cy="tokenTransfers"
32-
v-bind:transaction="transaction"/>
32+
v-bind:transaction="transaction ?? undefined"/>
3333
</template>
3434
<template v-else>
3535
<TokenTransferGraphF
3636
data-cy="tokenTransfers"
3737
v-bind:class="{'mb-4': displayRewardTransfers}"
38-
v-bind:transaction="transaction"/>
38+
v-bind:transaction="transaction ?? undefined"/>
3939
</template>
4040

4141
<template v-if="!compact">
4242
<RewardTransferGraph
4343
data-cy="rewardTransfers"
44-
v-bind:transaction="transaction"/>
44+
v-bind:transaction="transaction ?? undefined"/>
4545
</template>
4646

4747
</template>
@@ -52,31 +52,32 @@
5252

5353
<script setup lang="ts">
5454
55-
import {computed, PropType} from "vue";
55+
import {PropType, Ref} from "vue";
5656
import {TransactionDetail} from "@/schemas/MirrorNodeSchemas";
5757
import HbarTransferGraphC from "@/components/transfer_graphs/HbarTransferGraphC.vue";
5858
import HbarTransferGraphF from "@/components/transfer_graphs/HbarTransferGraphF.vue";
5959
import NftTransferGraph from "@/components/transfer_graphs/NftTransferGraph.vue";
6060
import TokenTransferGraphC from "@/components/transfer_graphs/TokenTransferGraphC.vue";
6161
import TokenTransferGraphF from "@/components/transfer_graphs/TokenTransferGraphF.vue";
62-
import {computeNetAmount} from "@/utils/TransactionTools";
6362
import RewardTransferGraph from "@/components/transfer_graphs/RewardTransferGraph.vue";
63+
import {TransactionAnalyzer} from "@/components/transaction/TransactionAnalyzer.ts";
6464
6565
const props = defineProps({
66-
transaction: Object as PropType<TransactionDetail>,
66+
analyzer: {
67+
type: Object as PropType<TransactionAnalyzer>,
68+
required: true
69+
},
6770
compact: {
6871
type: Boolean,
6972
default: false
7073
}
7174
})
7275
73-
const netAmount = computed(() => {
74-
return props.transaction ? computeNetAmount(props.transaction.transfers, props.transaction.charged_tx_fee) : 0
75-
})
76-
77-
const displayRewardTransfers = computed(() => props.transaction?.staking_reward_transfers && props.transaction?.staking_reward_transfers.length >= 1)
78-
const displayNftTransfers = computed(() => props.transaction?.nft_transfers && props.transaction?.nft_transfers.length >= 1)
79-
const displayTokenTransfers = computed(() => props.transaction?.token_transfers && props.transaction?.token_transfers.length >= 1)
76+
const transaction = props.analyzer.transaction as Ref<TransactionDetail | null>
77+
const netAmount = props.analyzer.netAmount
78+
const displayRewardTransfers = props.analyzer.hasRewardTransfers
79+
const displayNftTransfers = props.analyzer.hasNftTransfers
80+
const displayTokenTransfers = props.analyzer.hasTokenTransfers
8081
8182
</script>
8283

src/pages/TransactionDetails.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@
281281
</template>
282282
<template #content>
283283
<div>
284-
<TransferGraphSection :transaction="transaction ?? undefined"/>
284+
<TransferGraphSection :analyzer="transactionAnalyzer ?? undefined"/>
285285
</div>
286286
</template>
287287
</DashboardCardV2>

tests/unit/Mocks.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,10 +2011,6 @@ export const SAMPLE_BATCH_TRANSACTION: TransactionResponse = {
20112011
}
20122012
}
20132013

2014-
//
2015-
// https://mainnet-public.mirrornode.hedera.com/api/v1/transactions/0.0.48113503-1662470948-432078184
2016-
//
2017-
20182014
export const SAMPLE_PARENT_CHILD_TRANSACTIONS: TransactionResponse = {
20192015
"transactions":
20202016
[{
@@ -2035,11 +2031,11 @@ export const SAMPLE_PARENT_CHILD_TRANSACTIONS: TransactionResponse = {
20352031
"token_transfers": [],
20362032
"transaction_hash": "jthcv17LsslWUAzQkuIzeVMFpwJ3Uf5g6sSp1aZ8qqSWTz52XhPaMGAzt/5UgYob",
20372033
"transaction_id": "0.0.48113503-1662470948-432078184",
2038-
"transfers": [{"account": "0.0.98", "amount": 160800000, "is_approval": false}, {
2039-
"account": "0.0.48113503",
2040-
"amount": -5160800000,
2041-
"is_approval": false
2042-
}, {"account": "0.0.48193749", "amount": 5000000000, "is_approval": false}],
2034+
"transfers": [
2035+
{"account": "0.0.98", "amount": 160800000, "is_approval": false},
2036+
{"account": "0.0.48113503", "amount": -5160800000, "is_approval": false},
2037+
{"account": "0.0.48193749", "amount": 5000000000, "is_approval": false}
2038+
],
20432039
"valid_duration_seconds": "120",
20442040
"valid_start_timestamp": "1662470948.432078184"
20452041
}, {

tests/unit/transaction/TransactionByIdTable.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ describe("TransactionByIdTable.vue", () => {
5252

5353
expect(wrapper.find('thead').text()).toBe("Time Type Content Relationship Nonce".toUpperCase())
5454
expect(wrapper.find('tbody').text()).toBe(
55-
"1:29:17.0144 PMSep 6, 2022, UTCCONTRACT CALLContract ID: 0.0.48193749Parent0" +
56-
"1:29:17.0144 PMSep 6, 2022, UTCTOKEN MINTMINT\n\n0.0.48193741RSSE\n\n0.0.48113503Child1" +
57-
"1:29:17.0144 PMSep 6, 2022, UTCCRYPTO TRANSFER0.0.48113503\n\n0.0.48193741RSSE\n\n0.0.48193739Child2"
55+
"1:29:17.0144 PMSep 6, 2022, UTC" + "CONTRACT CALL" + "0.0.48113503\n\n" + "50.00000000ℏ\n\n" + "0.0.48193749" + "Parent" + "0" +
56+
"1:29:17.0144 PMSep 6, 2022, UTC" + "TOKEN MINT" + "MINT\n\n" + "0.0.48193741" + "RSSE\n\n" + "0.0.48113503" + "Child" + "1" +
57+
"1:29:17.0144 PMSep 6, 2022, UTC" + "CRYPTO TRANSFER" + "0.0.48113503\n\n" + "0.0.48193741" + "RSSE\n\n" + "0.0.48193739" + "Child" + "2"
5858
)
5959

6060
mock.restore()

0 commit comments

Comments
 (0)