mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
migrate Consume query
This commit is contained in:
parent
ca32de2dd7
commit
18d7223297
@ -20,13 +20,14 @@ import { Asset, FileMetadata } from '@oceanprotocol/lib'
|
||||
|
||||
const previousOrderQuery = gql`
|
||||
query PreviousOrder($id: String!, $account: String!) {
|
||||
tokenOrders(
|
||||
orders(
|
||||
first: 1
|
||||
where: { datatokenId: $id, payer: $account }
|
||||
orderBy: timestamp
|
||||
where: { token: $id, payer: $account }
|
||||
orderBy: createdTimestamp
|
||||
orderDirection: desc
|
||||
subgraphError: deny
|
||||
) {
|
||||
timestamp
|
||||
createdTimestamp
|
||||
tx
|
||||
}
|
||||
}
|
||||
@ -68,6 +69,7 @@ export default function Consume({
|
||||
|
||||
useEffect(() => {
|
||||
if (!ddo || !accountId) return
|
||||
|
||||
const context = getQueryContext(ddo.chainId)
|
||||
const variables = {
|
||||
id: ddo.services[0].datatokenAddress?.toLowerCase(),
|
||||
@ -82,18 +84,20 @@ export default function Consume({
|
||||
if (
|
||||
!data ||
|
||||
!assetTimeout ||
|
||||
data.tokenOrders.length === 0 ||
|
||||
data.orders.length === 0 ||
|
||||
!accountId ||
|
||||
!isAssetNetwork
|
||||
)
|
||||
return
|
||||
|
||||
const lastOrder = data.tokenOrders[0]
|
||||
const lastOrder = data.orders[0]
|
||||
if (assetTimeout === '0') {
|
||||
setPreviousOrderId(lastOrder.tx)
|
||||
setHasPreviousOrder(true)
|
||||
} else {
|
||||
const expiry = new BigNumber(lastOrder.timestamp).plus(assetTimeout)
|
||||
const expiry = new BigNumber(lastOrder.createdTimestamp).plus(
|
||||
assetTimeout
|
||||
)
|
||||
const unixTime = new BigNumber(Math.floor(Date.now() / 1000))
|
||||
if (unixTime.isLessThan(expiry)) {
|
||||
setPreviousOrderId(lastOrder.tx)
|
||||
|
Loading…
Reference in New Issue
Block a user