Skip to content

Commit

Permalink
APT-1617-conversion-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorginaShall committed Dec 27, 2024
1 parent 6dd294e commit c55d58e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
21 changes: 12 additions & 9 deletions src/components/stakingCalculator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const StakingCalculator: React.FC = () => {
const [zilToStake, setZilToStake] = useState<string>(formatUnits(stakingPoolForView?.stakingPool.definition.minimumStake || 0n, 18));

useEffect(() => {
setZilToStake("0.00");
setZilToStake("1");
}, [stakingPoolForView]);

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -48,7 +48,7 @@ const StakingCalculator: React.FC = () => {
};

const handleFocus = () => {
if (zilToStake === '0.00') setZilToStake('');
if (zilToStake === '') setZilToStake('1');
};

const handleBlur = () => {
Expand All @@ -62,7 +62,7 @@ const StakingCalculator: React.FC = () => {
}
setZilToStake(valueTemp.replace(/0*(\d+)/, '$1'));

if (zilToStake === '') setZilToStake('0.00');
if (zilToStake === '') setZilToStake('1');
};

const zilToStakeNumber = parseFloat(zilToStake);
Expand Down Expand Up @@ -102,11 +102,14 @@ const StakingCalculator: React.FC = () => {
<>
<span className="body1">
~
{convertZilValueInToken(
zilToStakeNumber,
stakingPoolForView.stakingPool.data
.zilToTokenRate
)}{' '}
{
!isNaN(zilToStakeNumber) && !isNaN(stakingPoolForView.stakingPool.data
.zilToTokenRate)
? convertZilValueInToken(zilToStakeNumber, stakingPoolForView.stakingPool.data
.zilToTokenRate)
: ""
}
{' '}
{
stakingPoolForView.stakingPool.definition
.tokenSymbol
Expand Down Expand Up @@ -164,7 +167,7 @@ const StakingCalculator: React.FC = () => {
<div className="base flex flex-col xl:flex-row xl:gap-5">
<div>Rate</div>
{stakingPoolForView!.stakingPool.data && (
<div>{`1 ZIL = ~${convertZilValueInToken(zilToStakeNumber, stakingPoolForView.stakingPool.data.zilToTokenRate)} ${stakingPoolForView.stakingPool.definition.tokenSymbol}`}</div>
<div>{`1 ZIL = ~${ stakingPoolForView.stakingPool.data.zilToTokenRate} ${stakingPoolForView.stakingPool.definition.tokenSymbol}`}</div>
)}
</div>
<div className=" regular-base text-aqua1 flex flex-row xl:gap-5">
Expand Down
11 changes: 6 additions & 5 deletions src/components/unstakingCalculator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const UnstakingCalculator: React.FC = () => {
};

const handleFocus = () => {
if (zilToUnstake === '0.00') setZilToUnstake('');
if (zilToUnstake === '') setZilToUnstake('1');
};

const handleBlur = () => {
Expand All @@ -44,11 +44,11 @@ const UnstakingCalculator: React.FC = () => {
valueTemp = zilToUnstake.slice(0, -1);
}
setZilToUnstake(valueTemp.replace(/0*(\d+)/, '$1'));
if (zilToUnstake === '') setZilToUnstake('0.00');
if (zilToUnstake === '') setZilToUnstake('1');
};

useEffect(() => {
setZilToUnstake('0.00');
setZilToUnstake('1');
}, [stakingPoolForView]);

const stakedTokenAvailable =
Expand Down Expand Up @@ -172,13 +172,14 @@ const UnstakingCalculator: React.FC = () => {
= ~
{formatUnitsToHumanReadable(
convertTokenToZil(
zilInWei,
parseEther('1'),
stakingPoolForView.stakingPool.data
.zilToTokenRate
),
18
)}
</>

</>
) : (
<div className="animated-gradient mr-1 h-[1.5em] w-[3em]"></div>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/misc/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function convertTokenToZil(tokenAmount: bigint, zilToTokenRate: number):
}

export function convertZilValueInToken(zilAmount: number, zilToTokenRate: number) {
return `${(zilAmount * zilToTokenRate).toFixed(2)}`
return `${(zilAmount * zilToTokenRate).toFixed(2)}`
}

export function formatUnitsToHumanReadable(value: bigint, decimals: number): string {
Expand Down

0 comments on commit c55d58e

Please sign in to comment.