Skip to content

Commit

Permalink
Merge pull request #99 from oceanprotocol/quote-amount-buffer
Browse files Browse the repository at this point in the history
Adding buffer to the quote amount
  • Loading branch information
jamiehewitt15 authored Oct 20, 2023
2 parents 44b324e + a4c8c12 commit cc6fda2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"dependencies": {
"@ethersproject/units": "^5.7.0",
"@oceanprotocol/typographies": "^0.1.0",
"@oceanprotocol/uploader": "^0.0.2-alpha.33",
"@oceanprotocol/uploader": "^0.0.2-alpha.34",
"@tippyjs/react": "^4.2.6",
"@types/react": "^17.0.59",
"ajv": "^8.12.0",
Expand Down
19 changes: 12 additions & 7 deletions src/components/TabsFile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default function TabsFile({
console.log('balance wmatic: ', balanceData)
// Mocked data quote
const [quote, setQuote] = useState<any>()
const [quoteWithBuffer, setQuoteWithBuffer] = useState<string>()
const [uploadStatusResponse, setUploadStatusResponse] = useState<any>('')
const [ddoLink, setDDOLink] = useState('')

Expand Down Expand Up @@ -222,9 +223,14 @@ export default function TabsFile({
console.log('quoteResult.tokenAmount', quoteResult.tokenAmount)
console.log('quote tokenAmount', quote)

// Add buffer to the quote amount
const newQuoteFee =
BigInt(quoteResult.tokenAmount) + BigInt(50000000000000000)

setQuoteWithBuffer(String(newQuoteFee))

// Check if user has wrapped matic in their wallet
const quotePrice = BigInt(quoteResult.tokenAmount)
if (wmaticBalance < quotePrice) {
if (wmaticBalance < newQuoteFee) {
console.log('User does not have enough wMatic')
setStep('wrapMatic')
} else {
Expand Down Expand Up @@ -290,11 +296,10 @@ export default function TabsFile({
try {
console.log('uploading: ', { quoteId, payment, quoteFee, files, type })
console.log('String(quoteFee)', String(quoteFee))
const newQuoteFee = BigInt(quoteFee) + BigInt(3000000000000000)
const quoteAndUploadResult: any = await uploaderClient.uploadBrowser(
quoteId,
payment,
String(newQuoteFee),
String(quoteFee),
files as FileList,
type
)
Expand Down Expand Up @@ -366,7 +371,7 @@ export default function TabsFile({
await getUpload({
quoteId: quote.quoteId,
payment: quote.tokenAddress,
quoteFee: String(quote.tokenAmount),
quoteFee: String(quoteWithBuffer),
files: [file] as unknown as FileList,
type: items[tabIndex].type
})
Expand Down Expand Up @@ -512,7 +517,7 @@ export default function TabsFile({
}}
disabled={false}
>
{`${formatEther(`${quote.tokenAmount}`)} ${
{`${formatEther(`${quoteWithBuffer}`)} ${
items[tabIndex].payment
.filter(
(item: any) => item.chainId === chain?.id.toString()
Expand Down Expand Up @@ -560,7 +565,7 @@ export default function TabsFile({
{step === 'wrapMatic' ? (
<WrapMatic
setStep={setStep}
amount={BigInt(quote.tokenAmount)}
amount={BigInt(quoteWithBuffer as string)}
name={item.type}
handleFileChange={handleFileChange}
handleUpload={handleUpload}
Expand Down

0 comments on commit cc6fda2

Please sign in to comment.