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

fix: Use default expiration date when order expires at is past #2034

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 9 additions & 10 deletions webapp/src/components/SellPage/SellModal/SellModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useState } from 'react'
import { ethers } from 'ethers'
import addDays from 'date-fns/addDays'
import isPast from 'date-fns/isPast'
import formatDate from 'date-fns/format'
import isValid from 'date-fns/isValid'
import { getNetworkProvider } from 'decentraland-dapps/dist/lib/eth'
Expand Down Expand Up @@ -50,20 +51,18 @@ const SellModal = (props: Props) => {

const isUpdate = order !== null
const [price, setPrice] = useState<string>(
isUpdate ? ethers.utils.formatEther(order!.price) : ''
isUpdate && order ? ethers.utils.formatEther(order.price) : ''
)

const [expiresAt, setExpiresAt] = useState(() => {
let exp = order?.expiresAt
if (order) {
const expiresAt =
order.expiresAt.toString().length === 10
? order.expiresAt * 1000
: order.expiresAt

if (isUpdate && exp) {
// If the order's expiration is in seconds, convert it to milliseconds
if (exp.toString().length === 10) {
exp = exp * 1000
}

if (isValid(exp)) {
return formatDate(addDays(exp, 1), INPUT_FORMAT)
if (isValid(expiresAt) && !isPast(expiresAt)) {
return formatDate(addDays(expiresAt, 1), INPUT_FORMAT)
}
}

Expand Down
Loading