Skip to content

Commit

Permalink
Merge pull request #361 from dappforce/deploy/send
Browse files Browse the repository at this point in the history
Fix Timeout For Nonce
  • Loading branch information
olehmell authored Aug 30, 2023
2 parents 4dd6913 + fe270ff commit 7e4af68
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/pages/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function AccountPage() {
routeReplace.current(returnUrl)
})
sendEvent('login', { eventSource: 'share_session_link' })
}, [login, isInitialized])
}, [login, isInitialized, sendEvent])

return <DefaultLayout />
}
2 changes: 1 addition & 1 deletion src/pages/api/version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextApiRequest, NextApiResponse } from 'next'

const VERSION = '5'
const VERSION = '6'

export default function handler(_: NextApiRequest, res: NextApiResponse) {
res.status(200).json(VERSION)
Expand Down
32 changes: 25 additions & 7 deletions src/subsocial-query/subsocial/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,32 @@ const noncePromise = generatePromiseQueue()
async function getNonce(substrateApi: ApiPromise, address: string) {
const previousQueue = noncePromise.addQueue()

const timeoutId = setTimeout(() => {
throw new Error('Timeout: Cannot get nonce for the next transaction.')
}, 10_000)
await previousQueue
clearTimeout(timeoutId)
return new Promise<{ nonce: number; nonceResolver: () => void }>(
(resolve, reject) => {
async function getNonce() {
try {
const timeoutId = setTimeout(() => {
reject(
new Error('Timeout: Cannot get nonce for the next transaction.')
)
}, 10_000)

const nonce = await substrateApi.rpc.system.accountNextIndex(address)
return { nonce, nonceResolver: noncePromise.resolveQueue }
await previousQueue
clearTimeout(timeoutId)

const nonce = await substrateApi.rpc.system.accountNextIndex(address)
resolve({
nonce: nonce.toNumber(),
nonceResolver: noncePromise.resolveQueue,
})
} catch (err) {
console.log('Error getting nonce', err)
reject(new Error('Failed to get nonce'))
}
}
getNonce()
}
)
}

function generateTxCallbacks<Data, Context>(
Expand Down

0 comments on commit 7e4af68

Please sign in to comment.