Skip to content

Commit

Permalink
Merge pull request #71 from oceanprotocol/approval-check
Browse files Browse the repository at this point in the history
Reinstating error message when user does not have approval
  • Loading branch information
jamiehewitt15 authored Oct 20, 2023
2 parents 0e98d64 + aa5773f commit 5bfbc99
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions app/controllers/upload.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,26 +290,16 @@ exports.upload = async (req, res) => {
)
if (allowance.lt(priceWei)) {
console.log(
`Allowance is less than current rate. Current rate: ${priceWei}, allowance: ${allowance}`
`Allowance is less than current rate. Current price in wei: ${priceWei}, current allowance: ${allowance}`
)
const checkAllowance = async () => {
while (true) {
try {
console.log('check allowance again')
allowance = await token.allowance(userAddress, wallet.address)
console.log(`allowance = ${allowance}`)

if (allowance.gte(priceWei)) {
break // Exit the loop if condition is met
}
} catch (err) {
console.log(`Error occurred while checking allowance.`)
}

await new Promise((resolve) => setTimeout(resolve, 2000)) // Wait for 2 seconds
}
}
checkAllowance()
errorResponse(
req,
res,
null,
400,
`Allowance is less than current rate. Current price in wei: ${priceWei}, current allowance: ${allowance}`
)
return
}

// Check that user has sufficient funds
Expand Down

0 comments on commit 5bfbc99

Please sign in to comment.