-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Changes from all commits
7fa6f83
42c81eb
b94a789
f69b718
ef5415c
2ab2e9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import Image from "next/image"; | ||
import React, { FC, useCallback, useState } from "react"; | ||
import * as sdk from "@vanilladefi/stake-sdk"; | ||
import { isAddress } from "@vanilladefi/core-sdk"; | ||
import { isAddress, juiceDecimals } from "@vanilladefi/core-sdk"; | ||
import { Row } from "react-table"; | ||
import { toast } from "react-toastify"; | ||
import { useSnapshot } from "valtio"; | ||
|
@@ -11,6 +11,7 @@ import { | |
emitEvent, | ||
findToken, | ||
getTransactionLink, | ||
filterJuiceAmount, | ||
parseJuice, | ||
} from "../../utils/helpers"; | ||
import Box from "../Box"; | ||
|
@@ -22,6 +23,7 @@ import Text from "../Text"; | |
|
||
import { PolygonScanIcon } from "../../assets"; | ||
import { BigNumber } from "ethers"; | ||
import { formatUnits } from "ethers/lib/utils"; | ||
|
||
export type ColumnType = { | ||
__typename?: "AssetPair"; | ||
|
@@ -54,7 +56,11 @@ const StakeSubRow: FC<SubRowProps> = ({ row, type = "make" }) => { | |
|
||
const staked = row.original.currentStake; | ||
|
||
const [stakeAmount, setStakeAmount] = useState(staked?.juiceValue || ""); | ||
const [stakeAmount, setStakeAmount] = useState( | ||
staked?.rawJuiceValue | ||
? formatUnits(staked.rawJuiceValue, juiceDecimals) | ||
: "" | ||
); | ||
const [stakePosition, setStakePosition] = useState<"long" | "short">( | ||
staked?.sentiment || "long" | ||
); | ||
|
@@ -65,9 +71,8 @@ const StakeSubRow: FC<SubRowProps> = ({ row, type = "make" }) => { | |
const closingDisabled = stakePending; | ||
|
||
const stakeUnchanged = | ||
staked?.sentiment === stakePosition | ||
? staked?.juiceValue === stakeAmount | ||
: false; | ||
staked?.sentiment === stakePosition && | ||
parseJuice(stakeAmount).eq(staked.rawJuiceValue); | ||
|
||
const handleStake = useCallback( | ||
async (type: "close" | "modify" = "modify") => { | ||
|
@@ -227,15 +232,15 @@ const StakeSubRow: FC<SubRowProps> = ({ row, type = "make" }) => { | |
disabled={stakePending} | ||
autoFocus | ||
size="lg" | ||
type="number" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
placeholder="0.0" | ||
value={stakeAmount} | ||
onChange={(e) => setStakeAmount(e.target.value)} | ||
onChange={(e) => setStakeAmount(filterJuiceAmount(e.target.value))} | ||
css={{ | ||
width: "100%", | ||
minWidth: "30px", | ||
maxWidth: "140px", | ||
textAlign: "right", | ||
fontSize: stakeAmount.length > 8 ? "$sm" : "$lg", | ||
mx: "$3", | ||
}} | ||
/> | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.