Skip to content

Commit

Permalink
explorer: fix currency types
Browse files Browse the repository at this point in the history
  • Loading branch information
deuch13 committed May 17, 2024
1 parent 6dfa10e commit cff6208
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { afterAll, afterEach, describe, expect, it, vi } from "vitest";
import { cleanup, fireEvent, render } from "@testing-library/svelte";
import { apiTransaction } from "$lib/mock-data";
import { apiMarketData, apiTransaction } from "$lib/mock-data";
import { transformTransaction } from "$lib/chain-info";
import { TransactionDetails } from "../";

Expand All @@ -14,6 +14,10 @@ const baseProps = {
data: transformTransaction(apiTransaction.data[0]),
error: null,
loading: false,
market: {
currentPrice: apiMarketData.market_data.current_price,
marketCap: apiMarketData.market_data.market_cap,
},
payload:
"db0794770322802a22905c4364511f3186e6184085f875dbb9f11a3ae914766c020000000000000014bc23b875c67d0dbecfdd45f5964f3fea7188aff2035730c8802",
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ exports[`Block Details > renders the Block Details component 1`] = `
<dd
class="details-list__definition"
>
5
DUSK
5,000,000,000
</dd>
<!--&lt;ListItem&gt;-->
<dt
Expand Down Expand Up @@ -301,10 +300,8 @@ exports[`Block Details > renders the Block Details component 1`] = `
<dd
class="details-list__definition"
>
0.000580718
DUSK
580,718
<div
class="dusk-progress-bar block-details__gas-used"
role="progressbar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ exports[`Transaction Details > renders the Transaction Details component 1`] = `
<dd
class="details-list__definition"
>
487,166
<a
class="dusk-anchor transaction-details__list-anchor"
href="/some-base-path/blocks/block?id=3c6e4018cfa86723e50644e33d3990bc27fc794f6b49fbf6290e4d308e07bd2d"
>
487,166
</a>
<!--&lt;Anchor&gt;-->
<!--&lt;AppAnchor&gt;-->
</dd>
<!--&lt;ListItem&gt;-->
<dt
Expand Down Expand Up @@ -215,7 +222,10 @@ exports[`Transaction Details > renders the Transaction Details component 1`] = `
<dd
class="details-list__definition"
>
0.000290766 DUSK ($0.000145383)
0.000290766 DUSK ($0.0001071037)
<!--&lt;DataGuard&gt;-->
</dd>
<!--&lt;ListItem&gt;-->
<dt
Expand Down Expand Up @@ -243,7 +253,10 @@ exports[`Transaction Details > renders the Transaction Details component 1`] = `
<dd
class="details-list__definition"
>
0.000000001 DUSK ($0.000000001)
0.000000001 DUSK ($0.0000000004)
<!--&lt;DataGuard&gt;-->
</dd>
<!--&lt;ListItem&gt;-->
<dt
Expand Down Expand Up @@ -437,7 +450,14 @@ exports[`Transaction Details > renders the Transaction Details component with th
<dd
class="details-list__definition"
>
487,166
<a
class="dusk-anchor transaction-details__list-anchor"
href="/some-base-path/blocks/block?id=3c6e4018cfa86723e50644e33d3990bc27fc794f6b49fbf6290e4d308e07bd2d"
>
487,166
</a>
<!--&lt;Anchor&gt;-->
<!--&lt;AppAnchor&gt;-->
</dd>
<!--&lt;ListItem&gt;-->
<dt
Expand Down Expand Up @@ -568,7 +588,10 @@ exports[`Transaction Details > renders the Transaction Details component with th
<dd
class="details-list__definition"
>
0.000290766 DUSK ($0.000145383)
0.000290766 DUSK ($0.0001071037)
<!--&lt;DataGuard&gt;-->
</dd>
<!--&lt;ListItem&gt;-->
<dt
Expand Down Expand Up @@ -596,7 +619,10 @@ exports[`Transaction Details > renders the Transaction Details component with th
<dd
class="details-list__definition"
>
0.000000001 DUSK ($0.000000001)
0.000000001 DUSK ($0.0000000004)
<!--&lt;DataGuard&gt;-->
</dd>
<!--&lt;ListItem&gt;-->
<dt
Expand Down
4 changes: 2 additions & 2 deletions explorer/src/lib/components/block-details/BlockDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@
<ListItem tooltipText="The block gas limit">
<svelte:fragment slot="term">block gas limit</svelte:fragment>
<svelte:fragment slot="definition"
>{formatter(luxToDusk(data.transactions.stats.gasLimit))} DUSK</svelte:fragment
>{formatter(data.transactions.stats.gasLimit)}</svelte:fragment
>
</ListItem>

<!-- GAS USED -->
<ListItem tooltipText="The amount of gas used generating the block">
<svelte:fragment slot="term">gas used</svelte:fragment>
<svelte:fragment slot="definition">
{formatter(luxToDusk(data.transactions.stats.gasUsed))} DUSK
{formatter(data.transactions.stats.gasUsed)}

<ProgressBar
currentPercentage={(data.transactions.stats.gasUsed /
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
width: 100%;
}

.transaction-details__list-anchor {
text-decoration: none;
}

.transaction-details__list-timestamp {
text-transform: uppercase;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<svelte:options immutable={true} />

<script>
import { DataCard, DataGuard, ListItem } from "$lib/components";
import { AppAnchor, DataCard, DataGuard, ListItem } from "$lib/components";
import { Badge, Card, Switch } from "$lib/dusk/components";
import { createValueFormatter } from "$lib/dusk/value";
import {
Expand Down Expand Up @@ -33,8 +33,11 @@
/** @type {String | null} */
export let payload;
/** @type {MarketData}*/ //Can also be null
export let market;
const formatter = createValueFormatter("en");
const currencyFormatter = createCurrencyFormatter("en", "usd", 9);
const currencyFormatter = createCurrencyFormatter("en", "usd", 10);
const feeFormatter = createFeeFormatter("en");
/** @type {number} */
Expand Down Expand Up @@ -87,8 +90,12 @@
<!-- BLOCK HEIGHT -->
<ListItem tooltipText="The block height this transaction belongs to">
<svelte:fragment slot="term">block height</svelte:fragment>
<svelte:fragment slot="definition"
>{formatter(data.blockheight)}</svelte:fragment
<svelte:fragment slot="definition">
<AppAnchor
className="transaction-details__list-anchor"
href="/blocks/block?id={data.blockhash}"
>{formatter(data.blockheight)}</AppAnchor
></svelte:fragment
>
</ListItem>

Expand Down Expand Up @@ -131,17 +138,21 @@
<!-- TRANSACTION FEE -->
<ListItem tooltipText="The fee paid for the transaction">
<svelte:fragment slot="term">transaction fee</svelte:fragment>
<svelte:fragment slot="definition"
>{`${feeFormatter(luxToDusk(data.feepaid))} DUSK (${currencyFormatter(luxToDusk(data.feepaid) * 0.5)})`}</svelte:fragment
>
<svelte:fragment slot="definition">
<DataGuard data={market?.currentPrice.usd}>
{`${feeFormatter(luxToDusk(data.feepaid))} DUSK (${currencyFormatter(luxToDusk(data.feepaid) * market.currentPrice.usd)})`}
</DataGuard>
</svelte:fragment>
</ListItem>

<!-- GAS PRICE -->
<ListItem tooltipText="The transaction gas price">
<svelte:fragment slot="term">gas price</svelte:fragment>
<svelte:fragment slot="definition"
>{`${feeFormatter(luxToDusk(data.gasprice))} DUSK (${currencyFormatter(luxToDusk(data.gasprice) * 0.5)})`}</svelte:fragment
>
<svelte:fragment slot="definition">
<DataGuard data={market?.currentPrice.usd}>
{`${feeFormatter(luxToDusk(data.gasprice))} DUSK (${currencyFormatter(luxToDusk(data.gasprice) * market.currentPrice.usd)})`}
</DataGuard>
</svelte:fragment>
</ListItem>

<!-- GAS LIMIT -->
Expand Down
2 changes: 1 addition & 1 deletion explorer/src/lib/dusk/currency/createCurrencyFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const createFormatter = (locale, currency, digits) => {
? new Intl.NumberFormat(locale, { minimumFractionDigits: digits })
: new Intl.NumberFormat(locale, {
currency: currency,
maximumFractionDigits: 9,
maximumFractionDigits: 10,
minimumFractionDigits: 2,
style: "currency",
});
Expand Down
4 changes: 4 additions & 0 deletions explorer/src/routes/transactions/transaction/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
const dataStore = createDataStore(duskAPI.getTransaction);
const payloadStore = createDataStore(duskAPI.getTransactionDetails);
const marketStore = createDataStore(duskAPI.getMarketData);
const getTransaction = () => {
dataStore.getData($appStore.network, $page.url.searchParams.get("id"));
payloadStore.getData($appStore.network, $page.url.searchParams.get("id"));
marketStore.getData($appStore.network);
};
onNetworkChange(getTransaction);
$: ({ data, error, isLoading } = $dataStore);
$: ({ data: payloadData } = $payloadStore);
$: ({ data: marketData } = $marketStore);
onMount(() => {
getTransaction();
Expand All @@ -32,5 +35,6 @@
{error}
loading={isLoading}
payload={payloadData}
market={marketData}
/>
</section>

0 comments on commit cff6208

Please sign in to comment.