Skip to content

Commit

Permalink
better parsing of number of tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
mjadach-iv committed Jan 14, 2025
1 parent 32fd9c4 commit 16a9c79
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/pages/node/configuration.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react';
import { useAppDispatch, useAppSelector } from '../../store';
import { formatEther } from 'viem';
import { rounder } from '../../utils/functions';
import { rounder, rounder2 } from '../../utils/functions';

// HOPR Components
import { SubpageTitle } from '../../components/SubpageTitle';
Expand Down Expand Up @@ -29,15 +29,16 @@ interface StrategyConfig {
}

const calculateTickets = (value: string, ticketPrice: string) => {
const valueBigInt = BigInt(value) * DECIMALS_MULTIPLIER;
console.log({value, ticketPrice})
const valueBigInt = BigInt(value);
const ticketBigInt = BigInt(ticketPrice);
return valueBigInt / ticketBigInt;
};

const updateStrategyString = (originalString: string, key: string, value: string, tickets: bigint): string => {
const stringToReplace = `"${key}": "${value} HOPR"`;
const formattedEther = formatEther(BigInt(value));
const replacement = `"${key}": "${value}" // ${formattedEther} HOPR, tickets: ${rounder(Number(tickets))}`;
const replacement = `"${key}": "${value}" // = ${formattedEther} HOPR (${rounder(Number(tickets))} tickets)`;

return originalString.includes(stringToReplace + ',')
? originalString.replace(stringToReplace + ',', replacement + ',')
Expand Down
2 changes: 2 additions & 0 deletions src/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function rounder(value: number | string | null | undefined, charLength: n
if (!value) return '-';
if (value == 0) return '0';
let splitted = ['', ''];
console.log('value', value)
if (typeof value === 'string') {
if (value.includes('.')) {
splitted = value.split('.');
Expand All @@ -52,6 +53,7 @@ export function rounder(value: number | string | null | undefined, charLength: n
} else {
splitted = [`${value}`, '0'];
}
console.log('splitted', splitted)
const wholes = splitted[0];
const decimas = splitted[1];
let rez: string | null = null;
Expand Down

0 comments on commit 16a9c79

Please sign in to comment.