Skip to content

Commit

Permalink
Merge pull request #2376 from dusk-network/feature-2362
Browse files Browse the repository at this point in the history
explorer: Add `memo` and `isDeploy` fields in transactions
  • Loading branch information
ascartabelli authored Sep 12, 2024
2 parents bdc7cec + e93798e commit 6cbca76
Show file tree
Hide file tree
Showing 16 changed files with 502 additions and 138 deletions.
2 changes: 2 additions & 0 deletions explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add accessible name to the nav bar button on mobile [#2036]
- Implement warning for stale market data [#1892]
- Add tooltip to current and pending stake showing the exact amount [#2363]
- Add `memo` and `isDeploy` fields in transactions [#2362]

### Changed

Expand Down Expand Up @@ -62,6 +63,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#2159]: https://github.com/dusk-network/rusk/issues/2159
[#2220]: https://github.com/dusk-network/rusk/issues/2220
[#2348]: https://github.com/dusk-network/rusk/issues/2348
[#2362]: https://github.com/dusk-network/rusk/issues/2362
[#2363]: https://github.com/dusk-network/rusk/issues/2363

<!-- VERSIONS -->
Expand Down
4 changes: 2 additions & 2 deletions explorer/src/lib/chain-info/__tests__/transformBlock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ describe("transformBlock", () => {
blockhash:
"bd5c99bb720b03500e89f103fe66113ba62f2e124ed9651563f38fd15977719f",
blockheight: 495868,
contract: "Transfer",
date: new Date(blockData.transactions[0].blockTimestamp * 1000),
feepaid: 290866,
gaslimit: 500000000,
gasprice: 1,
gasspent: 290866,
memo: blockData.transactions[0].tx.memo,
method: "transfer",
success: true,
txerror: "",
Expand All @@ -43,12 +43,12 @@ describe("transformBlock", () => {
blockhash:
"bd5c99bb720b03500e89f103fe66113ba62f2e124ed9651563f38fd15977719f",
blockheight: 495868,
contract: "Transfer",
date: new Date(blockData.transactions[1].blockTimestamp * 1000),
feepaid: 289852,
gaslimit: 500000000,
gasprice: 1,
gasspent: 289852,
memo: blockData.transactions[1].tx.memo,
method: "transfer",
success: true,
txerror: "",
Expand Down
32 changes: 30 additions & 2 deletions explorer/src/lib/chain-info/__tests__/transformTransaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ describe("transformTransaction", () => {
blockhash:
"3c6e4018cfa86723e50644e33d3990bc27fc794f6b49fbf6290e4d308e07bd2d",
blockheight: 487166,
contract: "Transfer",
date: new Date(txData.blockTimestamp * 1000),
feepaid: 290766,
gaslimit: 500000000,
gasprice: 1,
gasspent: 290766,
memo: gqlTransaction.tx.tx.memo,
method: "transfer",
success: true,
txerror: "",
Expand All @@ -40,13 +40,41 @@ describe("transformTransaction", () => {
};
const expected = {
...expectedTx,
contract: "Stake",
method: "stake",
};

expect(transformTransaction(data)).toStrictEqual(expected);
});

it('should use "deploy" as method, if the related property is `true`, regardless of the `callData.fnName` value', () => {
const dataA = {
...txData,
tx: {
...txData.tx,
callData: {
contractId:
"0200000000000000000000000000000000000000000000000000000000000000",
fnName: "transfer",
},
isDeploy: true,
},
};
const dataB = {
...txData,
tx: {
...txData.tx,
isDeploy: true,
},
};
const expected = {
...expectedTx,
method: "deploy",
};

expect(transformTransaction(dataA)).toStrictEqual(expected);
expect(transformTransaction(dataB)).toStrictEqual(expected);
});

it("should set the success property to `false` if the an error is present and use the message in the `txerror` property", () => {
const data = {
...txData,
Expand Down
2 changes: 1 addition & 1 deletion explorer/src/lib/chain-info/chain-info.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ type SearchResult = {
type Transaction = {
blockhash: string;
blockheight: number;
contract: string;
date: Date;
feepaid: number;
gaslimit: number;
gasprice: number;
gasspent: number;
memo: string;
method: string;
success: boolean;
txerror: string;
Expand Down
7 changes: 2 additions & 5 deletions explorer/src/lib/chain-info/transformTransaction.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { unixTsToDate } from "$lib/dusk/date";

/** @param {string} [s] */
const capitalize = (s) => (s ? `${s[0].toUpperCase()}${s.slice(1)}` : "");

/** @type {(v: GQLTransaction) => Transaction} */
const transformTransaction = (tx) => ({
blockhash: tx.blockHash,
blockheight: tx.blockHeight,
contract: tx.tx.callData ? capitalize(tx.tx.callData.fnName) : "Transfer",
date: unixTsToDate(tx.blockTimestamp),
feepaid: tx.gasSpent * tx.tx.gasPrice,
gaslimit: tx.tx.gasLimit,
gasprice: tx.tx.gasPrice,
gasspent: tx.gasSpent,
method: tx.tx.callData?.fnName ?? "transfer",
memo: tx.tx.memo ?? "",
method: tx.tx.isDeploy ? "deploy" : tx.tx.callData?.fnName ?? "transfer",
success: tx.err === null,
txerror: tx.err ?? "",
txid: tx.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,33 @@ exports[`Transaction Details > renders the Transaction Details component 1`] = `
>
290766
</dd>
<dt
class="details-list__term"
>
<svg
class="dusk-icon dusk-icon--size--normal detail-list__help"
data-tooltip-id="main-tooltip"
data-tooltip-place="top"
data-tooltip-text="Transaction reference and additional notes"
data-tooltip-type="info"
role="graphics-symbol"
viewBox="0 0 24 24"
>
<path
d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z"
/>
</svg>
memo
</dt>
<dd
class="details-list__definition"
>
some notes about the transaction
</dd>
<dt
class="details-list__term"
>
Expand Down Expand Up @@ -610,6 +637,33 @@ exports[`Transaction Details > renders the Transaction Details component with th
>
290766
</dd>
<dt
class="details-list__term"
>
<svg
class="dusk-icon dusk-icon--size--normal detail-list__help"
data-tooltip-id="main-tooltip"
data-tooltip-place="top"
data-tooltip-text="Transaction reference and additional notes"
data-tooltip-type="info"
role="graphics-symbol"
viewBox="0 0 24 24"
>
<path
d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z"
/>
</svg>
memo
</dt>
<dd
class="details-list__definition"
>
some notes about the transaction
</dd>
<dt
class="details-list__term"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@
<svelte:fragment slot="definition">{data.gasspent}</svelte:fragment>
</ListItem>

<!-- MEMO -->
<ListItem tooltipText="Transaction reference and additional notes">
<svelte:fragment slot="term">memo</svelte:fragment>
<svelte:fragment slot="definition"
><DataGuard data={data.memo}>{data.memo}</DataGuard></svelte:fragment
>
</ListItem>

<!-- PAYLOAD -->
<ListItem tooltipText="The payload">
<svelte:fragment slot="term">
Expand Down
8 changes: 6 additions & 2 deletions explorer/src/lib/mock-data/gql-block.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
"id": "3a3f6f90a1012ae751b4448bcb8e98def0ba2b18170239bd69fcf8e2e37f0602",
"tx": {
"callData": null,
"isDeploy": false,
"gasLimit": 500000000,
"gasPrice": 1,
"id": "3a3f6f90a1012ae751b4448bcb8e98def0ba2b18170239bd69fcf8e2e37f0602"
"id": "3a3f6f90a1012ae751b4448bcb8e98def0ba2b18170239bd69fcf8e2e37f0602",
"memo": ""
}
},
{
Expand All @@ -39,7 +41,9 @@
"callData": null,
"gasLimit": 500000000,
"gasPrice": 1,
"id": "07bfabea1d94c16f2dc3697fa642f6cecea6e81bf76b9644efbb6e2723b76d00"
"id": "07bfabea1d94c16f2dc3697fa642f6cecea6e81bf76b9644efbb6e2723b76d00",
"isDeploy": false,
"memo": "some notes about the transaction"
}
}
]
Expand Down
16 changes: 12 additions & 4 deletions explorer/src/lib/mock-data/gql-blocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,9 @@
"callData": null,
"gasLimit": 500000000,
"gasPrice": 1,
"id": "befe14f664fe1cb95f89b7500cc8a8368b3cd8ab58f4897dd3c0132cbebde004"
"id": "befe14f664fe1cb95f89b7500cc8a8368b3cd8ab58f4897dd3c0132cbebde004",
"isDeploy": false,
"memo": ""
}
}
]
Expand Down Expand Up @@ -1273,7 +1275,9 @@
"callData": null,
"gasLimit": 500000000,
"gasPrice": 1,
"id": "dd9249849db6143ae4bf3420da9a2bf90b402807f0ef4843d51dd06db35e2a0a"
"id": "dd9249849db6143ae4bf3420da9a2bf90b402807f0ef4843d51dd06db35e2a0a",
"isDeploy": false,
"memo": ""
}
}
]
Expand Down Expand Up @@ -1400,7 +1404,9 @@
"callData": null,
"gasLimit": 500000000,
"gasPrice": 1,
"id": "1466ebfcaefcff92b8bb88feb86aab902a73d6062731de52d3f22d502136fc01"
"id": "1466ebfcaefcff92b8bb88feb86aab902a73d6062731de52d3f22d502136fc01",
"isDeploy": false,
"memo": ""
}
}
]
Expand Down Expand Up @@ -1447,7 +1453,9 @@
"callData": null,
"gasLimit": 500000000,
"gasPrice": 1,
"id": "15af4e04d4f34b89a77601945aaec5c284ff71ed076ba3e4c7b6db1c7cddb80d"
"id": "15af4e04d4f34b89a77601945aaec5c284ff71ed076ba3e4c7b6db1c7cddb80d",
"isDeploy": false,
"memo": ""
}
}
]
Expand Down
2 changes: 2 additions & 0 deletions explorer/src/lib/mock-data/gql-chain-info.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ type GQLTransaction = {
gasLimit: number;
gasPrice: number;
id: string;
isDeploy: boolean;
memo: string;
};
};
Loading

0 comments on commit 6cbca76

Please sign in to comment.