Skip to content

Commit

Permalink
make sure deadlien is passsed and that previous attempt id is forward…
Browse files Browse the repository at this point in the history
…ed (#110)
  • Loading branch information
0xNe0x1 authored Dec 29, 2023
1 parent 2848fc1 commit 69982c4
Show file tree
Hide file tree
Showing 23 changed files with 750 additions and 652 deletions.
52 changes: 26 additions & 26 deletions dist/esm/index.bundle.js

Large diffs are not rendered by default.

198 changes: 107 additions & 91 deletions dist/esm/index.evm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/esm/index.evm.js.map

Large diffs are not rendered by default.

198 changes: 107 additions & 91 deletions dist/esm/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/esm/index.js.map

Large diffs are not rendered by default.

198 changes: 107 additions & 91 deletions dist/esm/index.solana.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/esm/index.solana.js.map

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions dist/umd/index.bundle.js

Large diffs are not rendered by default.

198 changes: 107 additions & 91 deletions dist/umd/index.evm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/umd/index.evm.js.map

Large diffs are not rendered by default.

198 changes: 107 additions & 91 deletions dist/umd/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/umd/index.js.map

Large diffs are not rendered by default.

198 changes: 107 additions & 91 deletions dist/umd/index.solana.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/umd/index.solana.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.evm.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/widgets-evm",
"moduleName": "DePayWidgets",
"version": "12.3.15",
"version": "12.3.16",
"description": "Web3 Payments with any token. DePay simplifies and improves Web3 Payments with the power of DeFi. Accept any token with on-the-fly conversion.",
"main": "./dist/umd/index.js",
"module": "./dist/esm/index.js",
Expand Down Expand Up @@ -33,7 +33,7 @@
"@depay/web3-blockchains": "^9.2.9",
"@depay/web3-client-evm": "^10.18.4",
"@depay/web3-exchanges-evm": "^13.7.0",
"@depay/web3-payments-evm": "^13.6.7",
"@depay/web3-payments-evm": "^13.6.8",
"@depay/web3-tokens-evm": "^10.3.0",
"@depay/web3-wallets-evm": "^16.3.6",
"@tanstack/react-virtual": "^3.0.0-beta.54",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/widgets",
"moduleName": "DePayWidgets",
"version": "12.3.15",
"version": "12.3.16",
"description": "Web3 Payments with any token. DePay simplifies and improves Web3 Payments with the power of DeFi. Accept any token with on-the-fly conversion.",
"main": "./dist/umd/index.js",
"module": "./dist/esm/index.js",
Expand Down Expand Up @@ -47,7 +47,7 @@
"@depay/web3-blockchains": "^9.2.9",
"@depay/web3-client": "^10.18.4",
"@depay/web3-exchanges": "^13.7.0",
"@depay/web3-payments": "^13.6.7",
"@depay/web3-payments": "^13.6.8",
"@depay/web3-tokens": "^10.3.0",
"@depay/web3-wallets": "^16.3.6",
"@tanstack/react-virtual": "^3.0.0-beta.54",
Expand Down
4 changes: 2 additions & 2 deletions package.solana.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/widgets-solana",
"moduleName": "DePayWidgets",
"version": "12.3.15",
"version": "12.3.16",
"description": "Web3 Payments with any token. DePay simplifies and improves Web3 Payments with the power of DeFi. Accept any token with on-the-fly conversion.",
"main": "./dist/umd/index.js",
"module": "./dist/esm/index.js",
Expand Down Expand Up @@ -34,7 +34,7 @@
"@depay/web3-blockchains": "^9.2.9",
"@depay/web3-client-solana": "^10.18.4",
"@depay/web3-exchanges-solana": "^13.7.0",
"@depay/web3-payments-solana": "^13.6.7",
"@depay/web3-payments-solana": "^13.6.8",
"@depay/web3-tokens-solana": "^10.3.0",
"@depay/web3-wallets-solana": "^16.3.6",
"@tanstack/react-virtual": "^3.0.0-beta.54",
Expand Down
7 changes: 3 additions & 4 deletions src/components/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default ()=>{
} else if(release) {
return(
<div>
<a className="Card transparent small" title="DePay has validated the payment" href={ "https://depay.com/docs/payments/validation" } target="_blank" rel="noopener noreferrer">
<a className="Card transparent small" title="DePay has validated the payment" href={ `https://status.depay.com/tx/${transaction.blockchain}/${transaction.id}` } target="_blank" rel="noopener noreferrer">
<div className="CardImage">
<div className="TextCenter Opacity05">
<Checkmark className="small"/>
Expand All @@ -93,7 +93,7 @@ export default ()=>{
} else {
return(
<div>
<a className="Card transparent small" title="DePay is validating payment" href={ "https://depay.com/docs/payments/validation" } target="_blank" rel="noopener noreferrer">
<a className="Card transparent small" title="DePay is validating the payment" href={ `https://status.depay.com/tx/${transaction.blockchain}/${transaction.id}` } target="_blank" rel="noopener noreferrer">
<div className="CardImage">
<div className="TextCenter">
<div className="Loading Icon"></div>
Expand Down Expand Up @@ -128,8 +128,7 @@ export default ()=>{
<div className="CardBody">
<div className="CardBodyWrapper">
<div className="Opacity05">
Confirm in your wallet
(<a href="https://depay.com/docs/payments/verify" target="_blank" rel="noopener noreferrer" style={{ textDecoration: 'none' }}>verify</a>)
Confirm in your wallet (<a href="https://depay.com/docs/payments/verify" target="_blank" rel="noopener noreferrer" style={{ textDecoration: 'none' }}>verify</a>)
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/SelectWalletDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default (props)=>{
{ showDropDown && <DropDown hide={()=>setShowDropDown(false)}
items={[
{ label: "What is a wallet?", action: ()=>{ navigate('WhatIsAWallet') } },
{ label: "Wallet missing?", action: ()=>{ window.open('mailto:[email protected]?subject=Add wallet&body=Can you please add the following wallet: [ENTER YOUR WALLET HERE]?', '_blank') } },
{ label: "Wallet missing?", action: ()=>{ window.open('mailto:[email protected]?subject=Add wallet&body=Please enter the name of the wallet you want us to add:', '_blank') } },
]}
/> }
</span>
Expand Down
10 changes: 5 additions & 5 deletions src/providers/PaymentProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ export default (props)=>{
setPaymentState('paying')
setUpdatable(false)
let currentBlock = await request({ blockchain: transaction.blockchain, method: 'latestBlockNumber' })
await trace(currentBlock, payment.route, transaction).then(async()=>{
await trace(currentBlock, payment.route, transaction, transaction?.params?.payment?.deadline).then(async()=>{
setClosable(false)
await wallet.sendTransaction(Object.assign({}, transaction, {
sent: (transaction)=>{
initializeTransactionTracking(transaction, currentBlock)
if(sent) { sent(transaction) }
sent: (sentTransaction)=>{
initializeTransactionTracking(sentTransaction, currentBlock, transaction?.params?.payment?.deadline)
if(sent) { sent(sentTransaction) }
},
succeeded: paymentSucceeded,
failed: paymentFailed
}))
.then((sentTransaction)=>{
setTransaction(sentTransaction)
initializePaymentTracking(sentTransaction, currentBlock, payment.route)
initializePaymentTracking(sentTransaction, currentBlock, payment.route, transaction?.params?.payment?.deadline)
})
.catch((error)=>{
console.log('error', error)
Expand Down
44 changes: 25 additions & 19 deletions src/providers/PaymentTrackingProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@ import ErrorContext from '../contexts/ErrorContext'
import getNonce from '../helpers/getNonce'
import NavigateContext from '../contexts/NavigateContext'
import PaymentTrackingContext from '../contexts/PaymentTrackingContext'
import React, { useEffect, useContext, useState } from 'react'
import React, { useEffect, useContext, useState, useRef } from 'react'
import WalletContext from '../contexts/WalletContext'
import { ethers } from 'ethers'

export default (props)=>{
const { errorCallback } = useContext(ErrorContext)
const { id: configurationId, track, validated, failed, integration, link, type } = useContext(ConfigurationContext)
const { account, wallet } = useContext(WalletContext)
const [ deadline, setDeadline ] = useState()
const [ transaction, setTransaction ] = useState()
const [ confirmationsRequired, setConfirmationsRequired ] = useState()
const [ confirmationsPassed, setConfirmationsPassed ] = useState()
const [ afterBlock, setAfterBlock ] = useState()
const [ socket, setSocket ] = useState()
const [ paymentRoute, setPaymentRoute ] = useState()
const [ attemptId, setAttemptId ] = useState()
const attemptIdRef = useRef(attemptId)
attemptIdRef.current = attemptId
const [ trackingInitialized, setTrackingInitialized ] = useState(false)
const [ synchronousTracking ] = useState(
!!configurationId ||
Expand Down Expand Up @@ -98,19 +101,19 @@ export default (props)=>{
}
}

const retryStartTracking = (transaction, afterBlock, paymentRoute, attempt)=> {
const retryStartTracking = (transaction, afterBlock, paymentRoute, deadline, attempt)=> {
attempt = parseInt(attempt || 1, 10)
if(attempt < (track?.attempts || 40)) {
setTimeout(()=>{
startTracking(transaction, afterBlock, paymentRoute, attempt+1)
startTracking(transaction, afterBlock, paymentRoute, deadline, attempt+1)
}, 3000)
} else {
navigate('TrackingFailed')
}
}

const continueTryTracking = ()=>{
retryStartTracking(transaction, afterBlock, paymentRoute, 1)
retryStartTracking(transaction, afterBlock, paymentRoute, deadline, 1)
}

const callTracking = (payment)=>{
Expand Down Expand Up @@ -146,7 +149,7 @@ export default (props)=>{
}
}

const startTracking = async(transaction, afterBlock, paymentRoute, attempt)=> {
const startTracking = async(transaction, afterBlock, paymentRoute, deadline, attempt)=> {
callTracking({
blockchain: transaction.blockchain,
transaction: transaction.id,
Expand All @@ -160,17 +163,18 @@ export default (props)=>{
to_amount: paymentRoute.toAmount.toString(),
to_decimals: paymentRoute.toDecimals,
fee_amount: paymentRoute?.feeAmount?.toString(),
deadline: transaction.deadline
trace_attempt_id: attemptIdRef.current,
deadline
})
.then((response)=>{
setTrackingInitialized(true)
})
.catch((error)=>{
retryStartTracking(transaction, afterBlock, paymentRoute, attempt)
retryStartTracking(transaction, afterBlock, paymentRoute, deadline, attempt)
})
}

const pollStatus = async(polling, transaction, afterBlock, paymentRoute, pollingInterval)=>{
const pollStatus = async(polling, transaction, afterBlock, paymentRoute, pollingInterval, attemptId)=>{
if(
!polling ||
transaction == undefined ||
Expand Down Expand Up @@ -242,11 +246,11 @@ export default (props)=>{
useEffect(()=>{
if(!polling) { return }
if(!synchronousTracking){ return }
let pollingInterval = setInterval(()=>pollStatus(polling, transaction, afterBlock, paymentRoute, pollingInterval), 5000)
let pollingInterval = setInterval(()=>pollStatus(polling, transaction, afterBlock, paymentRoute, pollingInterval, attemptId), 5000)
return ()=>{ clearInterval(pollingInterval) }
}, [polling, transaction, afterBlock, paymentRoute])
}, [polling, transaction, afterBlock, attemptId, paymentRoute])

const storePayment = async(transaction, afterBlock, paymentRoute)=>{
const storePayment = async(transaction, afterBlock, paymentRoute, deadline)=>{
fetch('https://public.depay.com/payments', {
headers: { 'Content-Type': 'application/json' },
method: 'POST',
Expand All @@ -271,33 +275,35 @@ export default (props)=>{
},
fee_amount: paymentRoute.fee ? ethers.utils.formatUnits(paymentRoute.feeAmount, paymentRoute.toDecimals) : null,
fee_receiver: paymentRoute.fee ? paymentRoute.fee.receiver : null,
deadline: transaction.deadline
deadline
})
})
.then((response)=>{
if(response.status == 200 || response.status == 201) {
} else {
setTimeout(()=>{ storePayment(transaction, afterBlock, paymentRoute) }, 3000)
setTimeout(()=>{ storePayment(transaction, afterBlock, paymentRoute, deadline) }, 3000)
}
})
.catch((error)=>{
setTimeout(()=>{ storePayment(transaction, afterBlock, paymentRoute) }, 3000)
setTimeout(()=>{ storePayment(transaction, afterBlock, paymentRoute, deadline) }, 3000)
})
}

const initializeTracking = (transaction, afterBlock, paymentRoute)=>{
storePayment(transaction, afterBlock, paymentRoute)
const initializeTracking = (transaction, afterBlock, paymentRoute, deadline)=>{
storePayment(transaction, afterBlock, paymentRoute, deadline)
if(synchronousTracking || (track && track.async == true)) {
startTracking(transaction, afterBlock, paymentRoute)
startTracking(transaction, afterBlock, paymentRoute, deadline)
}
if(synchronousTracking == false) { return }
setDeadline(deadline)
setTransaction(transaction)
setAfterBlock(afterBlock)
setPaymentRoute(paymentRoute)
openSocket(transaction)
}

const trace = (afterBlock, paymentRoute, transaction)=>{
const trace = (afterBlock, paymentRoute, transaction, deadline)=>{
setAttemptId() // reset attemptId in case payment is retried
if(!synchronousTracking && !asynchronousTracking) { return Promise.resolve() }
return new Promise(async(resolve, reject)=>{
let payment = {
Expand All @@ -312,7 +318,7 @@ export default (props)=>{
to_amount: paymentRoute.toAmount.toString(),
to_decimals: paymentRoute.toDecimals,
fee_amount: paymentRoute?.feeAmount?.toString(),
deadline: transaction.deadline
deadline
}
if(configurationId){
return fetch(`https://public.depay.com/configurations/${configurationId}/attempts`, {
Expand Down
17 changes: 7 additions & 10 deletions src/providers/TransactionTrackingProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ export default (props)=>{
}
}, [polling])

const createTracking = async (transaction, afterBlock, attempt)=> {
const createTracking = async (transaction, afterBlock, deadline, attempt)=> {
if(attempt > 3) {
console.log('TRANSACTION TRACKING FAILED AFTER 3 ATTEMPTS!')
return
}
fetch('https://public.depay.com/transactions', {
Expand All @@ -52,20 +51,18 @@ export default (props)=>{
after_block: afterBlock.toString(),
blockchain: transaction.blockchain,
sender: transaction.from,
nonce: await getNonce({ transaction, wallet, account })
nonce: await getNonce({ transaction, wallet, account }),
deadline
})
})
.then((response)=>{
if(response.status == 200 || response.status == 201) {
console.log('TRANSACTION TRACKING INITIALIZED')
} else {
console.log('TRANSACTION TRACKING FAILED', response)
setTimeout(()=>{ createTracking(transaction, afterBlock, attempt+1) }, 3000)
setTimeout(()=>{ createTracking(transaction, afterBlock, deadline, attempt+1) }, 3000)
}
})
.catch((error)=>{
console.log('TRANSACTION TRACKING FAILED', error)
setTimeout(()=>{ createTracking(transaction, afterBlock, attempt+1) }, 3000)
setTimeout(()=>{ createTracking(transaction, afterBlock, deadline, attempt+1) }, 3000)
})
}

Expand Down Expand Up @@ -104,10 +101,10 @@ export default (props)=>{
}
}

const initializeTracking = (transaction, afterBlock)=>{
const initializeTracking = (transaction, afterBlock, deadline)=>{
if(!supported.evm.includes(transaction.blockchain)){ return }
setGivenTransaction(transaction)
if(recover == undefined) { createTracking(transaction, afterBlock, 1) }
if(recover == undefined) { createTracking(transaction, afterBlock, deadline, 1) }
openSocket(transaction)
setPolling(true)
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1330,10 +1330,10 @@
"@depay/web3-blockchains" "^9.1.4"
ethers "^5.7.1"

"@depay/web3-payments@^13.6.7":
version "13.6.7"
resolved "https://registry.yarnpkg.com/@depay/web3-payments/-/web3-payments-13.6.7.tgz#63aaa6e6e197fe756ceb1afadc39e61299a7e6b5"
integrity sha512-dZCzCpyXOXzCmkS4g73uau/WDE/Z1Q5A/XfaRD7MeIWSOfutMxyvTDuP4rRyDkPgPPv4H/KKO5l2FlhTKc146w==
"@depay/web3-payments@^13.6.8":
version "13.6.8"
resolved "https://registry.yarnpkg.com/@depay/web3-payments/-/web3-payments-13.6.8.tgz#28bffa3a6b71d72b9aeed6602979e5cb5b760fe0"
integrity sha512-NpXi5UU6re/0jxFKbpssAfj5wAyAs1Df1apkYA+AJI/xOhVnmf9v9lhcFiOvP6PmX1ab0QhvxHZGNshIHuLTOg==

"@depay/web3-tokens@^10.3.0":
version "10.3.0"
Expand Down

0 comments on commit 69982c4

Please sign in to comment.