Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import Value from '$lib/components/ui/Value.svelte';
import { ICP_TOP_UP_FEE } from '$lib/constants/token.constants';
import { i18n } from '$lib/stores/app/i18n.store';
import { formatTCycles, icpToCycles } from '$lib/utils/cycles.utils';
import {
formatTCycles,
icpE8sToCycles,

Check warning on line 12 in src/frontend/src/lib/components/canister/top-up/CanisterTopUpFormIcp.svelte

View workflow job for this annotation

GitHub Actions / lint

'icpE8sToCycles' is defined but never used. Allowed unused vars must match /^_/u
icpNumberToCycles,
icpToCycles

Check warning on line 14 in src/frontend/src/lib/components/canister/top-up/CanisterTopUpFormIcp.svelte

View workflow job for this annotation

GitHub Actions / lint

'icpToCycles' is defined but never used. Allowed unused vars must match /^_/u
} from '$lib/utils/cycles.utils';

interface Props {
balance: bigint;
Expand All @@ -26,7 +31,7 @@

let convertedCycles = $derived(
nonNullish(trillionRatio) && !isNaN(Number(amount)) && notEmptyString(amount)
? icpToCycles({ icp: BigInt(amount), trillionRatio })
? icpNumberToCycles({ icp: Number(amount), trillionRatio })
: undefined
);

Expand All @@ -35,6 +40,8 @@
? `${formatTCycles(BigInt(convertedCycles ?? 0))}`
: undefined;
});

$inspect(amount, displayTCycles, convertedCycles);

Check warning on line 44 in src/frontend/src/lib/components/canister/top-up/CanisterTopUpFormIcp.svelte

View workflow job for this annotation

GitHub Actions / lint

Do not use $inspect directive
</script>

<div class="group-cycles">
Expand Down
8 changes: 8 additions & 0 deletions src/frontend/src/lib/utils/cycles.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export const icpToCycles = ({
trillionRatio: bigint;
}): bigint => icp * trillionRatio;

export const icpNumberToCycles = ({
icp,
trillionRatio
}: {
icp: number;
trillionRatio: bigint;
}): bigint => BigInt(Math.trunc(icp * Number(trillionRatio)));

export const formatCyclesToHTML = ({ e12s, bold }: { e12s: bigint; bold: boolean }): string => {
const tag = bold ? 'strong' : 'span';
return `<${tag}>${formatTCycles(e12s)} <small>T Cycles</small></${tag}>`;
Expand Down
Loading