forked from mico/idle_moloch
Added available on chain counter
This commit is contained in:
parent
b47db1f359
commit
b41a453dda
@ -12,7 +12,7 @@ const calculateBalance = (balance: bigint, perSecond: bigint, lastRaidedAt: bigi
|
|||||||
/ BigInt(1000) /* deduct milliseconds*/))
|
/ BigInt(1000) /* deduct milliseconds*/))
|
||||||
}
|
}
|
||||||
|
|
||||||
const toReadable = (value: bigint) => {
|
export const toReadable = (value: bigint) => {
|
||||||
value = value / BigInt(10000);
|
value = value / BigInt(10000);
|
||||||
const suffixes = [
|
const suffixes = [
|
||||||
{ value: BigInt('1000'), suffix: 'thousand' },
|
{ value: BigInt('1000'), suffix: 'thousand' },
|
||||||
@ -38,7 +38,7 @@ const toReadable = (value: bigint) => {
|
|||||||
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;
|
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 remainder = value % suffixes[i - 1].value;
|
||||||
@ -54,7 +54,7 @@ const Counter = () => {
|
|||||||
const { balance, army, player } = usePlayer();
|
const { balance, army, player } = usePlayer();
|
||||||
const [, render] = useReducer(p => !p, false);
|
const [, render] = useReducer(p => !p, false);
|
||||||
const balanceCount = useRef(balance.toString() ?? "0")
|
const balanceCount = useRef(balance.toString() ?? "0")
|
||||||
|
const availableBalance = useRef(balance.toString() ?? "0")
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const tickInterval = setInterval(() => {
|
const tickInterval = setInterval(() => {
|
||||||
balanceCount.current = toReadable(calculateBalance(
|
balanceCount.current = toReadable(calculateBalance(
|
||||||
@ -62,14 +62,18 @@ const Counter = () => {
|
|||||||
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();
|
)).toString();
|
||||||
|
availableBalance.current = toReadable(balance);
|
||||||
render();
|
render();
|
||||||
}, 100);
|
}, 100);
|
||||||
return () => clearInterval(tickInterval)
|
return () => clearInterval(tickInterval)
|
||||||
}, [balance, army?.profit_per_second, player?.last_raided_at])
|
}, [balance, army?.profit_per_second, player?.last_raided_at])
|
||||||
|
|
||||||
return <p className={styles.counter}>
|
return <>
|
||||||
{balanceCount.current} GELD
|
<p className={styles.counter}>
|
||||||
</p>
|
{balanceCount.current} GELD
|
||||||
|
</p>
|
||||||
|
<p className={styles.counter_available}>available on chain: {availableBalance.current} GELD</p>
|
||||||
|
</>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Counter
|
export default Counter
|
||||||
|
|||||||
@ -19,3 +19,8 @@
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
.counter_available {
|
||||||
|
font-size: 1rem;
|
||||||
|
margin: 0;
|
||||||
|
opacity: 0.76;
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user