1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 01:34:57 +01:00

check previousValidOrders

This commit is contained in:
alexcos20 2020-10-23 00:55:54 -07:00
parent b0d9821535
commit 21257bba13
2 changed files with 22 additions and 4 deletions

View File

@ -29,7 +29,7 @@ export default function Compute({
}): ReactElement {
const { marketFeeAddress } = useSiteMetadata()
const { ocean } = useOcean()
const { ocean, account } = useOcean()
const { compute, isLoading, computeStepText, computeError } = useCompute()
const { buyDT, dtSymbol } = usePricing(ddo)
@ -54,6 +54,14 @@ export default function Compute({
!isBalanceSufficient
const hasDatatoken = Number(dtBalance) >= 1
const previousOrder = ocean.datatokens.getPreviousValidOrders(
ddo.dataToken,
computeService.attributes.main.cost,
computeService.index,
computeService.attributes.main.timeout,
account.getId()
)
const hasPreviousOrder = !!previousOrder
const onDrop = async (files: File[]) => {
setFile(files[0])
const fileText = await readFileContent(files[0])
@ -136,7 +144,7 @@ export default function Compute({
onClick={() => startJob()}
disabled={isComputeButtonDisabled}
>
{hasDatatoken ? 'Start job' : 'Buy'}
{hasDatatoken || hasPreviousOrder ? 'Start job' : 'Buy'}
</Button>
)}
</div>

View File

@ -21,7 +21,7 @@ export default function Consume({
isBalanceSufficient: boolean
dtBalance: string
}): ReactElement {
const { ocean } = useOcean()
const { ocean, account } = useOcean()
const { marketFeeAddress } = useSiteMetadata()
const {
dtSymbol,
@ -39,6 +39,16 @@ export default function Consume({
pricingIsLoading
const hasDatatoken = Number(dtBalance) >= 1
const service = ddo.findServiceByType('access')
const previousOrder = ocean.datatokens.getPreviousValidOrders(
ddo.dataToken,
service.attributes.main.cost,
service.index,
service.attributes.main.timeout,
account.getId()
)
const hasPreviousOrder = !!previousOrder
async function handleConsume() {
!hasDatatoken && (await buyDT('1'))
await consume(ddo.id, ddo.dataToken, 'access', marketFeeAddress)
@ -56,7 +66,7 @@ export default function Consume({
<Loader message={consumeStepText || pricingStepText} />
) : (
<Button style="primary" onClick={handleConsume} disabled={isDisabled}>
{hasDatatoken ? 'Download' : 'Buy'}
{hasDatatoken || hasPreviousOrder ? 'Download' : 'Buy'}
</Button>
)}
</div>