Skip to content

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

Open
jonijuup wants to merge 6 commits into
mainfrom
fix/bigint-in-stake-input
Open

Change StakeSubRow input value to use BigInt instead of rounded value#78
jonijuup wants to merge 6 commits into
mainfrom
fix/bigint-in-stake-input

Conversation

@jonijuup

@jonijuup jonijuup commented Mar 4, 2022

Copy link
Copy Markdown
Collaborator

Refrences #77

@vercel

vercel Bot commented Mar 4, 2022

Copy link
Copy Markdown

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

jonijuup commented Mar 4, 2022

Copy link
Copy Markdown
Collaborator Author

I get this error if I put too many decimals:

image

@JaniAnttonen JaniAnttonen left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread utils/helpers.ts Outdated
return transactionLink;
}

export const limitJuiceAmount = (str: string) => {

Copy link
Copy Markdown
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.

@muzam1l muzam1l Mar 7, 2022

Copy link
Copy Markdown
Member

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!

disabled={stakePending}
autoFocus
size="lg"
type="number"

@muzam1l muzam1l Mar 7, 2022

Copy link
Copy Markdown
Member

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 :).

@muzam1l muzam1l left a comment

Copy link
Copy Markdown
Member

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

muzam1l commented Apr 29, 2022

Copy link
Copy Markdown
Member

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