Skip to content

Commit

Permalink
Revert get nonce to main's version
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Aug 31, 2023
1 parent bb02dc3 commit 6a64d7c
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions src/subsocial-query/subsocial/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,26 +197,44 @@ const noncePromise = generatePromiseQueue()
* @param substrateApi Substrate API
* @param address Address of the account
*/

async function getNonce(substrateApi: ApiPromise, address: string) {
useMessageData.getState().setDoing('Getting nonce...')
const previousQueue = noncePromise.addQueue()

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

useMessageData.getState().setDoing('Waiting prev nonce...')
await previousQueue

useMessageData.getState().setDoing('Waiting prev nonce...')
await previousQueue
useMessageData
.getState()
.setDoing('getting nonce... ' + substrateApi.isConnected)
const nonce = await substrateApi.rpc.system.accountNextIndex(address)
useMessageData
.getState()
.setDoing('getting nonce... ' + substrateApi.isConnected)
const nonce = await substrateApi.rpc.system.accountNextIndex(address)
resolve({
nonce: nonce.toNumber(),
nonceResolver: noncePromise.resolveQueue,
})

useMessageData.getState().setDoing('nonce done')
clearTimeout(timeoutId)
return { nonce, nonceResolver: noncePromise.resolveQueue }
useMessageData.getState().setDoing('nonce done')
clearTimeout(timeoutId)
} 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 6a64d7c

Please sign in to comment.