Skip to content

Commit

Permalink
fix simple analytics value in block analytics tab
Browse files Browse the repository at this point in the history
  • Loading branch information
n1tranquilla committed Oct 14, 2024
1 parent 4a6ef3b commit 73d8ab3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
13 changes: 13 additions & 0 deletions cypress/e2e/analytics/block-spotlight.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { WHISPERIT_BLOCK_STATE_HASH } from "../constants";

suite(["@tier2"], "Block spotlight stats", () => {
it("are rendered", () => {
cy.visit(`/blocks/${WHISPERIT_BLOCK_STATE_HASH}/analytics`);
cy.assertAnalyticsSimplValueEquals("Total User Amounts Transferred", 215.5);
cy.assertAnalyticsSimplValueEquals(
"Total Internal Fees Transferred",
0.012,
);
cy.assertAnalyticsSimplValueEquals("Total SNARK Fees", "0.0");
});
});
9 changes: 9 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@

import { parseFormattedNumber } from "../e2e/helpers";

Cypress.Commands.add("assertAnalyticsSimplValueEquals", (label, value) => {
cy.get("span")
.contains(label)
.parent()
.parent()
.siblings()
.should("have.text", value);
});

Cypress.Commands.add(
"assertSortOrder",
(
Expand Down
23 changes: 18 additions & 5 deletions src/blocks/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,22 +222,35 @@ pub fn BlockAnalytics(block: BlocksQueryBlocks) -> impl IntoView {
<AnalyticsSmContainer>
<AnalyticsSimpleInfo
label=convert_to_span("Total User Amounts Transferred".into())
value=decorate_with_mina_tag(nanomina_to_mina(user_command_amount_total()))
subtext="In MINA"
value=convert_to_span(
format_number_helper(
&normalize_number_format(
&nanomina_to_mina(user_command_amount_total()),
)
.ok()
.unwrap(),
Some(1),
),
)
/>

</AnalyticsSmContainer>
<AnalyticsSmContainer>
<AnalyticsSimpleInfo
label=convert_to_span("Total Internal Fees Transferred".into())
value=decorate_with_mina_tag(get_transaction_fees(&block_sig.get()))
subtext="In MINA"
value=convert_to_span(
format_number_helper(&get_transaction_fees(&block_sig.get()), Some(5)),
)
/>
</AnalyticsSmContainer>
<AnalyticsSmContainer>
<AnalyticsSimpleInfo
label=convert_to_span("Total SNARK Fees".into())
value=wrap_in_pill(
decorate_with_mina_tag(get_snark_fees(&block_sig.get())),
ColorVariant::Blue,
subtext="In MINA"
value=convert_to_span(
format_number_helper(&get_snark_fees(&block_sig.get()), Some(5)),
)
/>
</AnalyticsSmContainer>
Expand Down
2 changes: 1 addition & 1 deletion src/common/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn get_browser_locale() -> String {
LANGUAGE.with(String::clone)
}

fn format_number_helper(number: &str, max_significant_digits: Option<u32>) -> String {
pub fn format_number_helper(number: &str, max_significant_digits: Option<u32>) -> String {
let locale_array = Array::new();
locale_array.push(&JsValue::from_str(&get_browser_locale()));

Expand Down

0 comments on commit 73d8ab3

Please sign in to comment.