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

compute jobs refetch and reuse order

This commit is contained in:
Bogdan Fazakas 2022-05-26 08:37:31 +03:00
parent 9ffa3419a6
commit 565e7bfa31
3 changed files with 36 additions and 3 deletions

View File

@ -38,6 +38,13 @@ const tokensPriceQuery = gql`
tx tx
serviceIndex serviceIndex
createdTimestamp createdTimestamp
reuses(orderBy: createdTimestamp, orderDirection: desc) {
id
caller
createdTimestamp
tx
block
}
} }
dispensers { dispensers {
id id
@ -103,6 +110,13 @@ const tokenPriceQuery = gql`
tx tx
serviceIndex serviceIndex
createdTimestamp createdTimestamp
reuses(orderBy: createdTimestamp, orderDirection: desc) {
id
caller
createdTimestamp
tx
block
}
} }
dispensers { dispensers {
id id
@ -157,12 +171,17 @@ function getAccessDetailsFromTokenPrice(
timeout?: number timeout?: number
): AccessDetails { ): AccessDetails {
const accessDetails = {} as AccessDetails const accessDetails = {} as AccessDetails
if (tokenPrice && tokenPrice.orders && tokenPrice.orders.length > 0) { if (tokenPrice && tokenPrice.orders && tokenPrice.orders.length > 0) {
const order = tokenPrice.orders[0] const order = tokenPrice.orders[0]
const reusedOrder =
order && order.reuses && order.reuses.length > 0 ? order.reuses[0] : null
console.log('order', order)
console.log('reusedOrder', reusedOrder)
// asset is owned if there is an order and asset has timeout 0 (forever) or if the condition is valid // asset is owned if there is an order and asset has timeout 0 (forever) or if the condition is valid
accessDetails.isOwned = accessDetails.isOwned =
timeout === 0 || Date.now() / 1000 - order.createdTimestamp < timeout timeout === 0 || Date.now() / 1000 - order.createdTimestamp < timeout
accessDetails.validOrderTx = order.tx accessDetails.validOrderTx = reusedOrder ? reusedOrder.tx : order.tx
} }
// TODO: fetch order fee from sub query // TODO: fetch order fee from sub query

View File

@ -102,6 +102,7 @@ export default function Compute({
useState<OrderPriceAndFees>() useState<OrderPriceAndFees>()
const [isRequestingAlgoOrderPrice, setIsRequestingAlgoOrderPrice] = const [isRequestingAlgoOrderPrice, setIsRequestingAlgoOrderPrice] =
useState(false) useState(false)
const [refatchJobs, setRefatchJobs] = useState(false)
// const [isProviderFeeValid, setIsProviderFeeValid] = useState(false) // const [isProviderFeeValid, setIsProviderFeeValid] = useState(false)
const isComputeButtonDisabled = const isComputeButtonDisabled =
isJobStarting === true || isJobStarting === true ||
@ -372,6 +373,8 @@ export default function Compute({
} }
LoggerInstance.log('[compute] Starting compute job response: ', response) LoggerInstance.log('[compute] Starting compute job response: ', response)
setIsPublished(true) setIsPublished(true)
console.log('setRefatchJobs true')
setRefatchJobs(!refatchJobs)
initPriceAndFees() initPriceAndFees()
} catch (error) { } catch (error) {
setError('Failed to start job!') setError('Failed to start job!')
@ -461,7 +464,11 @@ export default function Compute({
</footer> </footer>
{accountId && asset?.accessDetails?.datatoken && ( {accountId && asset?.accessDetails?.datatoken && (
<AssetActionHistoryTable title="Your Compute Jobs"> <AssetActionHistoryTable title="Your Compute Jobs">
<ComputeJobs minimal assetChainId={[asset?.chainId]} /> <ComputeJobs
minimal
assetChainId={[asset?.chainId]}
refatchJobs={refatchJobs}
/>
</AssetActionHistoryTable> </AssetActionHistoryTable>
)} )}
</> </>

View File

@ -71,10 +71,12 @@ const columns = [
export default function ComputeJobs({ export default function ComputeJobs({
minimal, minimal,
assetChainId assetChainId,
refatchJobs
}: { }: {
minimal?: boolean minimal?: boolean
assetChainId?: number[] assetChainId?: number[]
refatchJobs?: boolean
}): ReactElement { }): ReactElement {
const { accountId } = useWeb3() const { accountId } = useWeb3()
const { asset } = useAsset() const { asset } = useAsset()
@ -110,6 +112,11 @@ export default function ComputeJobs({
fetchJobs() fetchJobs()
}, [fetchJobs]) }, [fetchJobs])
useEffect(() => {
console.log('use effect ', refatchJobs)
fetchJobs()
}, [refatchJobs])
return accountId ? ( return accountId ? (
<> <>
{jobs?.length >= 0 && !minimal && ( {jobs?.length >= 0 && !minimal && (