forked from mico/idle_moloch
Tweaked formatting fn a bit plus per second counter is also formatted now
This commit is contained in:
parent
b41a453dda
commit
0dd53f9c1f
@ -12,8 +12,10 @@ const calculateBalance = (balance: bigint, perSecond: bigint, lastRaidedAt: bigi
|
||||
/ BigInt(1000) /* deduct milliseconds*/))
|
||||
}
|
||||
|
||||
export const toReadable = (value: bigint) => {
|
||||
value = value / BigInt(10000);
|
||||
export const toReadable = (value: bigint, applyTokenDivision?: boolean) => {
|
||||
if (applyTokenDivision) {
|
||||
value = value / BigInt(10000);
|
||||
}
|
||||
const suffixes = [
|
||||
{ value: BigInt('1000'), suffix: 'thousand' },
|
||||
{ value: BigInt('1000000'), suffix: 'million' },
|
||||
@ -35,13 +37,16 @@ export const toReadable = (value: bigint) => {
|
||||
{ value: BigInt('1000000000000000000000000000000000000000000000000000000'), suffix: 'septendecillion' },
|
||||
];
|
||||
|
||||
console.log(value)
|
||||
|
||||
for (let i = 0; i < suffixes.length; i++) {
|
||||
if (value < suffixes[i].value) {
|
||||
if (i == 0) {
|
||||
return value.toString();
|
||||
} else {
|
||||
const divided = value / suffixes[i - 1].value;
|
||||
const remainder = value % suffixes[i - 1].value;
|
||||
const numStr = (value % suffixes[i - 0].value).toString().slice(0, 3);
|
||||
const remainder = parseInt(numStr.replace(/0+$/, ''), 10);
|
||||
return `${divided.toString()}.${remainder.toString()} ${suffixes[i - 1].suffix}`;
|
||||
}
|
||||
}
|
||||
@ -61,8 +66,8 @@ const Counter = () => {
|
||||
balance,
|
||||
army?.profit_per_second ?? BigInt(0),
|
||||
player?.last_raided_at ?? BigInt(0)
|
||||
)).toString();
|
||||
availableBalance.current = toReadable(balance);
|
||||
), true);
|
||||
availableBalance.current = toReadable(balance, true);
|
||||
render();
|
||||
}, 100);
|
||||
return () => clearInterval(tickInterval)
|
||||
|
||||
@ -3,7 +3,7 @@ import styles from "../styles/Header.module.css"
|
||||
import { usePlayer } from "../providers/PlayerProvider";
|
||||
import { useAccount } from 'wagmi';
|
||||
import dynamic from "next/dynamic";
|
||||
import Counter from "./Counter";
|
||||
import Counter, { toReadable } from "./Counter";
|
||||
|
||||
const Header = () => {
|
||||
const { isConnected } = useAccount();
|
||||
@ -24,8 +24,10 @@ const Header = () => {
|
||||
}, [isRegistered])
|
||||
|
||||
const perSecondParagraph = useMemo(() => {
|
||||
const perSecond = toReadable(army?.profit_per_second ?? BigInt(0))
|
||||
console.log(perSecond, army?.profit_per_second)
|
||||
return (isRegistered) ?
|
||||
<p className={styles.counter_per_seconds}>per second: {army?.profit_per_second.toString()}</p>
|
||||
<p className={styles.counter_per_seconds}>per second: {perSecond}</p>
|
||||
: null
|
||||
}, [isRegistered, army?.profit_per_second])
|
||||
|
||||
|
||||
@ -79,6 +79,7 @@ contract RaidGeld is ERC20, Ownable {
|
||||
// Helper so we can use it when buying units too
|
||||
function performRaid(address player) private {
|
||||
uint256 time_past = block.timestamp - players[player].last_raided_at;
|
||||
|
||||
uint256 new_geld = armies[player].profit_per_second * time_past * 10 ** decimals();
|
||||
|
||||
// TODO: Pink noise, make it so sometimes its better than expected
|
||||
|
||||
Loading…
Reference in New Issue
Block a user