1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

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 timeout?: number
): AccessDetails { ): AccessDetails {
const accessDetails = {} as AccessDetails const accessDetails = {} as AccessDetails
if ( if (tokenPrice && tokenPrice.orders && tokenPrice.orders.length > 0) {
tokenPrice &&
timeout &&
tokenPrice.orders &&
tokenPrice.orders.length > 0
) {
const order = tokenPrice.orders[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 accessDetails.validOrderTx = order.tx
} }

View File

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