Skip to content

Commit 9832b66

Browse files
authored
fix: removed useless 0.0.800 branch in hbar transfer graph (#2169)
Signed-off-by: Eric Le Ponner <eric.leponner@icloud.com>
1 parent a34fb70 commit 9832b66

File tree

2 files changed

+113
-7
lines changed

2 files changed

+113
-7
lines changed

src/utils/TransactionTools.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import {StakingRewardTransfer, Transaction, TransactionType, Transfer} from "@/schemas/MirrorNodeSchemas";
44
import {TransactionID} from "@/utils/TransactionID";
55

6+
// eslint-disable-next-line max-lines-per-function, complexity
67
export function makeEntityType(row: Transaction): string | null {
78
let result: string | null
89

@@ -65,6 +66,7 @@ export function makeEntityType(row: Transaction): string | null {
6566
return result
6667
}
6768

69+
// eslint-disable-next-line max-lines-per-function, complexity
6870
export function makeTypeLabel(type: TransactionType | undefined): string {
6971
let result: string
7072
switch (type) {
@@ -291,6 +293,7 @@ export function computeNetAmount(transfers: Transfer[] | undefined, transactionF
291293
return result
292294
}
293295

296+
// eslint-disable-next-line complexity
294297
export function makeNetOfRewards(transfers: Transfer[] | undefined, rewards: StakingRewardTransfer[] | undefined): Transfer[] {
295298
let result = Array<Transfer>()
296299
let totalRewardAmount = 0
@@ -312,11 +315,13 @@ export function makeNetOfRewards(transfers: Transfer[] | undefined, rewards: Sta
312315
}
313316
}
314317
}
315-
result.push({
316-
amount: netAmount,
317-
account: t.account,
318-
is_approval: t.is_approval
319-
})
318+
if (netAmount != 0) {
319+
result.push({
320+
amount: netAmount,
321+
account: t.account,
322+
is_approval: t.is_approval
323+
})
324+
}
320325
}
321326
} else {
322327
result = transfers ?? []

tests/unit/transfer_graphs/layout/HbarTransferLayout.spec.ts

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,16 +768,117 @@ describe("HbarTransferLayout.vue", () => {
768768
expect(compactLayout.sources.length).toBe(1)
769769
expect(compactLayout.destinations.length).toBe(1)
770770

771-
const cs0 = fullLayout.sources[0]
771+
const cs0 = compactLayout.sources[0]
772772
expect(cs0.transfer.account).toBe("0.0.1859883")
773773
expect(cs0.transfer.amount).toBe(-9100185749)
774774
expect(cs0.description).toBe(null)
775775
expect(cs0.payload).toBe(true)
776776

777-
const cd0 = fullLayout.destinations[0]
777+
const cd0 = compactLayout.destinations[0]
778778
expect(cd0.transfer.account).toBe("0.0.2105083")
779779
expect(cd0.transfer.amount).toBe(+9100000000)
780780
expect(cd0.description).toBe("Transfer")
781781
expect(cd0.payload).toBe(true)
782782
})
783+
784+
785+
test("Transfer and payment of reward (take #2)", async () => {
786+
787+
const transaction = {
788+
"charged_tx_fee": 118031,
789+
"transfers": [
790+
{
791+
"account": "0.0.3",
792+
"amount": 4798,
793+
"is_approval": false
794+
},
795+
{
796+
"account": "0.0.98",
797+
"amount": 113233,
798+
"is_approval": false
799+
},
800+
{
801+
"account": "0.0.800",
802+
"amount": -231664272,
803+
"is_approval": false
804+
},
805+
{
806+
"account": "0.0.1784243",
807+
"amount": -118046,
808+
"is_approval": false
809+
},
810+
{
811+
"account": "0.0.1934439",
812+
"amount": 231664287,
813+
"is_approval": false
814+
}
815+
],
816+
"staking_reward_transfers": [
817+
{
818+
"account": "0.0.1934439",
819+
"amount": 231664272
820+
}
821+
]
822+
} as Transaction
823+
824+
//
825+
// FULL
826+
//
827+
828+
const fullLayout = new HbarTransferLayout(transaction, NETWORK_NODES)
829+
830+
expect(fullLayout.transaction).toBe(transaction)
831+
// expect(fullLayout.destinationAmount).toBe(+TransferTotal)
832+
expect(fullLayout.rowCount).toBe(3)
833+
expect(fullLayout.sources.length).toBe(1)
834+
expect(fullLayout.destinations.length).toBe(3)
835+
836+
const s0 = fullLayout.sources[0]
837+
expect(s0.transfer.account).toBe("0.0.1784243")
838+
expect(s0.transfer.amount).toBe(-118046)
839+
expect(s0.description).toBe(null)
840+
expect(s0.payload).toBe(true)
841+
842+
const d0 = fullLayout.destinations[0]
843+
expect(d0.transfer.account).toBe("0.0.1934439")
844+
expect(d0.transfer.amount).toBe(+15)
845+
expect(d0.description).toBe("Transfer")
846+
expect(d0.payload).toBe(true)
847+
848+
const d1 = fullLayout.destinations[1]
849+
expect(d1.transfer.account).toBe("0.0.3")
850+
expect(d1.transfer.amount).toBe(+4798)
851+
expect(d1.description).toBe("Node fee (Hedera)")
852+
expect(d1.payload).toBe(false)
853+
854+
const d2 = fullLayout.destinations[2]
855+
expect(d2.transfer.account).toBe("0.0.98")
856+
expect(d2.transfer.amount).toBe(+113233)
857+
expect(d2.description).toBe("Hedera fee collection account")
858+
expect(d2.payload).toBe(false)
859+
860+
//
861+
// COMPACT
862+
//
863+
864+
const compactLayout = new HbarTransferLayout(transaction, NETWORK_NODES, false)
865+
866+
expect(compactLayout.transaction).toBe(transaction)
867+
expect(compactLayout.destinationAmount).toBe(+15)
868+
expect(compactLayout.rowCount).toBe(1)
869+
expect(compactLayout.sources.length).toBe(1)
870+
expect(compactLayout.destinations.length).toBe(1)
871+
872+
const cs0 = compactLayout.sources[0]
873+
expect(cs0.transfer.account).toBe("0.0.1784243")
874+
expect(cs0.transfer.amount).toBe(-118046)
875+
expect(cs0.description).toBe(null)
876+
expect(cs0.payload).toBe(true)
877+
878+
const cd0 = compactLayout.destinations[0]
879+
expect(cd0.transfer.account).toBe("0.0.1934439")
880+
expect(cd0.transfer.amount).toBe(+15)
881+
expect(cd0.description).toBe("Transfer")
882+
expect(cd0.payload).toBe(true)
883+
})
783884
})

0 commit comments

Comments
 (0)