fix forever timeout for assets (#1445)

This commit is contained in:
Bogdan Fazakas 2022-05-19 19:48:13 +03:00 committed by GitHub
parent bf31cdfed5
commit f0b22ee8e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 10 deletions

View File

@ -152,14 +152,11 @@ function getAccessDetailsFromTokenPrice(
timeout?: number
): AccessDetails {
const accessDetails = {} as AccessDetails
if (
tokenPrice &&
timeout &&
tokenPrice.orders &&
tokenPrice.orders.length > 0
) {
if (tokenPrice && tokenPrice.orders && tokenPrice.orders.length > 0) {
const order = tokenPrice.orders[0]
accessDetails.isOwned = Date.now() / 1000 - order.createdTimestamp < timeout
// asset is owned if there is an order and asset has timeout 0 (forever) or if the condition is valid
accessDetails.isOwned =
timeout === 0 || Date.now() / 1000 - order.createdTimestamp < timeout
accessDetails.validOrderTx = order.tx
}

View File

@ -53,8 +53,9 @@ export default function Download({
useEffect(() => {
if (!asset?.accessDetails) return
setIsOwned(asset?.accessDetails?.isOwned)
setValidOrderTx(asset?.accessDetails?.validOrderTx)
asset?.accessDetails?.isOwned && setIsOwned(asset?.accessDetails?.isOwned)
asset?.accessDetails?.validOrderTx &&
setValidOrderTx(asset?.accessDetails?.validOrderTx)
// get full price and fees
async function init() {
@ -166,7 +167,6 @@ export default function Download({
if (!orderTx) {
throw new Error()
}
setIsOwned(true)
setValidOrderTx(orderTx.transactionHash)
}