Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yaki-tinker-fixes #53

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ const ProjectCard = (props: ProjectCardProps) => {
</div> : null}

<div
className={`relative stats-section grid grid-cols-1 gap-2 ${ mini ? '' : 'h-28' } overflow-y-scroll tinker-scrollbar scrollbar-thumb-amber-300 scrollbar-thin scrollbar pr-3`}
className={`relative stats-section grid grid-cols-1 gap-2 ${ mini ? '' : 'h-28' } overflow-y-scroll tinker-scrollbar scrollbar-thumb-amber-300 scrollbar pr-3`}
onScroll={(e) => {
// Update the stored scroll position
scrollPositionRef.current = (e.target as HTMLElement).scrollTop;
Expand Down
54 changes: 42 additions & 12 deletions src/modals/ManageStaking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,20 @@ const ManageStaking = (props: { isOpen: boolean; }) => {
if (!metadata) throw new Error(NO_METADATA_ERROR);

const availableBalance = new BigNumber(metadata.availableBalance as string)
.dividedBy(new BigNumber(10).pow(12))
.toString();
.dividedBy(new BigNumber(10).pow(12));

const balance = altBalance ? coreStakedBalance : availableBalance;
let balance = altBalance ? coreStakedBalance : availableBalance.toString();
// Remove commas before performing the subtraction
balance = balance.replace(/,/g, '');

// Subtract 1 TNKR to cover fees if balance is greater than 1
const balanceToStake = new BigNumber(balance).gte(new BigNumber(1))
? new BigNumber(balance).minus(new BigNumber(1)).toString()
: balance;

stakeForm.setValue(
"amount",
balance
balanceToStake
);

stakeForm.trigger("amount", {
Expand All @@ -287,11 +293,21 @@ const ManageStaking = (props: { isOpen: boolean; }) => {
const handleUnstakeMax = () => {
if (!metadata) throw new Error(NO_METADATA_ERROR);

const totalUserStaked = new BigNumber(metadata.totalUserStaked as string)
.dividedBy(new BigNumber(10).pow(12));

let balance = totalUserStaked.toString();
// Remove commas before performing the subtraction
balance = balance.replace(/,/g, '');

// Subtract 1 TNKR to cover fees if balance is greater than 1
const balanceToUnstake = new BigNumber(balance).gt(1)
? new BigNumber(balance).minus(1).toString()
: balance;

unstakeForm.setValue(
"amount",
new BigNumber(metadata.totalUserStaked as string)
.dividedBy(new BigNumber(10).pow(12))
.toString()
balanceToUnstake
);

unstakeForm.trigger("amount", {
Expand Down Expand Up @@ -367,11 +383,27 @@ const ManageStaking = (props: { isOpen: boolean; }) => {
const currentAmount = parseFloat(stakeForm.getValues('amount'));
const maxBalance = parseFloat(coreStakedBalance);
if (currentAmount > maxBalance) {
stakeForm.setValue('amount', maxBalance.toString());
stakeForm.setValue('amount', maxBalance.toString().replace(/,/g, ''));
}
}
}, [altBalance, coreStakedBalance, stakeForm]);

// Watch for changes in stakeForm.amount
useEffect(() => {
const value = stakeForm.getValues('amount');
if (value && !/^[0-9]*\.?[0-9]*$/.test(value)) {
stakeForm.setValue('amount', value.replace(/[^0-9.]/g, ''));
}
}, [stakeForm, watchedStakeAmount]);

// Watch for changes in unstakeForm.amount
useEffect(() => {
const value = unstakeForm.getValues('amount');
if (value && !/^[0-9]*\.?[0-9]*$/.test(value)) {
unstakeForm.setValue('amount', value.replace(/[^0-9.]/g, ''));
}
}, [unstakeForm, watchedUnstakeAmount]);

const RestakingDropdown = memo(() => {
const list = stakingCores.map(core => ({ id: core.key, userStaked: totalUserStakedData[core.key], name: core.metadata.name }) as SelectedCoreInfo);
if (!list || list.length === 0) return null;
Expand Down Expand Up @@ -491,8 +523,7 @@ const ManageStaking = (props: { isOpen: boolean; }) => {
<div className="relative flex flex-row items-center">
<Input {...stakeForm.register("amount", {
required: true,
})} type="text" id="stakeAmount"
/>
})} type="text" id="stakeAmount" />
<div className="absolute inset-y-0 right-0 flex flex-row items-center gap-4 transform -translate-x-1/2">
<span
className="block cursor-pointer text-white hover:text-tinkerYellow text-xs focus:outline-none"
Expand Down Expand Up @@ -534,8 +565,7 @@ const ManageStaking = (props: { isOpen: boolean; }) => {
<div className="relative flex flex-row items-center">
<Input {...unstakeForm.register("amount", {
required: true,
})} type="text" id="unstakeAmount"
/>
})} type="text" id="unstakeAmount" />
<div className="absolute inset-y-0 right-0 flex flex-row items-center gap-4 transform -translate-x-1/2">
<span
className="block cursor-pointer text-white hover:text-tinkerYellow text-xs focus:outline-none"
Expand Down
12 changes: 7 additions & 5 deletions src/routes/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ import { Link } from "react-router-dom";

const NotFound = () => {
return (
<>
<div className="mx-auto flex max-w-7xl flex-col gap-6 px-2 sm:px-8 xl:p-0">
<h1 className="text-4xl font-bold">Page not found</h1>
<div className="mx-auto w-full flex max-w-7xl flex-col justify-between p-4 sm:px-6 lg:px-8 mt-14 md:mt-0 gap-3">
<div className="z-10 w-full">
<h2 className="lg:text-xl font-bold mt-[8px] lg:mt-[12px] mb-[20px] lg:mb-[24px] flex flex-row items-center gap-4">
<span>Page not found</span>
</h2>

<span>
<span className="text-sm">
I think you&apos;re lost. Let&apos;s get you back on track.{" "}
<Link to="/" className="text-amber-400">
Go to Home
</Link>
</span>
</div>
</>
</div>
);
};

Expand Down