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