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

Change StakeSubRow input value to use BigInt instead of rounded value #78

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jonijuup
Copy link
Collaborator

@jonijuup jonijuup commented Mar 4, 2022

Refrences #77

@vercel
Copy link

vercel bot commented Mar 4, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/equilibriumco/vanilla-stake/BLQbWPFKxmjKB9GvQP1FXGK1EK4A
✅ Preview: https://vanilla-stake-git-fix-bigint-in-stake-input-equilibriumco.vercel.app

@jonijuup jonijuup requested a review from muzam1l March 4, 2022 10:56
@jonijuup
Copy link
Collaborator Author

jonijuup commented Mar 4, 2022

I get this error if I put too many decimals:

image

Copy link
Member

@JaniAnttonen JaniAnttonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments :)

const [stakeAmount, setStakeAmount] = useState(staked?.juiceValue || "");
const [stakeAmount, setStakeAmount] = useState(
staked?.rawJuiceValue
? formatUnits(staked.rawJuiceValue, juiceDecimals)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this basically exactly the same as before?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, but staked.juiceValue truncates the value to 3 decimals?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, basically juiceValue is also locale formatted (toLocaleString). Which adds commas/dots accordingly and rounds off to 3 digits.

utils/helpers.ts Outdated
@@ -36,4 +36,13 @@ export const getTransactionLink = (txHash: string) => {
}
const transactionLink = `${explorerUrl}/tx/${txHash}`
return transactionLink;
}

export const limitJuiceAmount = (str: string) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit hacky as it is, but seems to work. This said, there could be another feature that would remove spaces (Could be fixable by making the input a number type too btw <input type="number" />:

I tried copypasting my unstaked amount right into the stake box. It didn't work because of the spaces between numbers, so I had to manually remove them.

Copy link
Member

@muzam1l muzam1l Mar 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be fixable by making the input a number type too btw

I believe that is already the case!

But yeah, we can remove spaces here, chrome does it automatically, but others are not that smart!

@@ -232,10 +232,9 @@ const StakeSubRow: FC<SubRowProps> = ({ row, type = "make" }) => {
disabled={stakePending}
autoFocus
size="lg"
type="number"
Copy link
Member

@muzam1l muzam1l Mar 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After banging my head for some time, turns out this was culprit. On non-chromiums if number input gets a non-number, it just gives empty string to target.value but sets the original string in element, so react state and input state would go out of sync. Didn't know if that was even possible :).

Copy link
Member

@muzam1l muzam1l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if we wanna show full raw value in input.

@muzam1l
Copy link
Member

muzam1l commented Apr 29, 2022

Should be closed in favor of #87 and #89. filterJuiceAmount touch can be added in another pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants