Skip to content

Commit

Permalink
Merge pull request #181 from ensdomains/dev
Browse files Browse the repository at this point in the history
Fix floating point issues
  • Loading branch information
jefflau authored Apr 17, 2019
2 parents 798df83 + 1d398bf commit 5859cfa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
19 changes: 14 additions & 5 deletions src/components/SingleName/NameRegister/CTA.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function getCTA({
txHash,
setTxHash,
setTimerRunning,
isAboveMinDuration,
refetch
}) {
const CTAs = {
Expand All @@ -48,11 +49,17 @@ function getCTA({
incrementStep()
}}
>
{mutate => (
<Button data-testid="request-register-button" onClick={mutate}>
Request to register
</Button>
)}
{mutate =>
isAboveMinDuration ? (
<Button data-testid="request-register-button" onClick={mutate}>
Request to register
</Button>
) : (
<Button data-testid="request-register-button" type="disabled">
Request to register
</Button>
)
}
</Mutation>
),
COMMIT_SENT: (
Expand Down Expand Up @@ -116,6 +123,7 @@ const CTA = ({
duration,
label,
setTimerRunning,
isAboveMinDuration,
refetch
}) => {
const [txHash, setTxHash] = useState(undefined)
Expand All @@ -129,6 +137,7 @@ const CTA = ({
txHash,
setTxHash,
setTimerRunning,
isAboveMinDuration,
refetch
})}
</CTAContainer>
Expand Down
14 changes: 12 additions & 2 deletions src/components/SingleName/NameRegister/NameRegister.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ const NameRegister = ({ domain, waitTime, refetch }) => {
timerRunning ? 1000 : null
)

const duration = 31556952 * parseInt(years)
const parsedYears = parseFloat(years)
const yearInSeconds = 31556952
const duration = yearInSeconds * parsedYears
const oneMonthInSeconds = 2419200
const twentyEightDaysInYears = oneMonthInSeconds / yearInSeconds
const isAboveMinDuration = parsedYears > twentyEightDaysInYears
const waitPercentComplete = (secondsPassed / waitTime) * 100

return (
Expand All @@ -83,7 +88,11 @@ const NameRegister = ({ domain, waitTime, refetch }) => {
{({ data, loading }) => {
return (
<PricingContainer>
<Years years={years} setYears={setYears} />
<Years
years={years}
setYears={setYears}
yearInSeconds={yearInSeconds}
/>
<Chain />
<Price
price={loading ? 0 : data.getRentPrice}
Expand Down Expand Up @@ -112,6 +121,7 @@ const NameRegister = ({ domain, waitTime, refetch }) => {
secondsPassed={secondsPassed}
setTimerRunning={setTimerRunning}
refetch={refetch}
isAboveMinDuration={isAboveMinDuration}
/>
</NameRegisterContainer>
)
Expand Down

0 comments on commit 5859cfa

Please sign in to comment.