Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure the nonce lock is always released #108

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions src/SmartTransactionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,25 +568,28 @@ export default class SmartTransactionsController extends BaseController<
console.error('ethers error', e);
}
const nonceLock = await this.getNonceLock(txParams?.from);
const nonce = hexlify(nonceLock.nextNonce);
if (txParams && !txParams?.nonce) {
txParams.nonce = nonce;
}
const { nonceDetails } = nonceLock;
try {
const nonce = hexlify(nonceLock.nextNonce);
if (txParams && !txParams?.nonce) {
txParams.nonce = nonce;
}
const { nonceDetails } = nonceLock;

this.updateSmartTransaction({
chainId,
nonceDetails,
metamaskNetworkId,
preTxBalance,
status: SmartTransactionStatuses.PENDING,
time,
txParams,
uuid: data.uuid,
cancellable: true,
});
this.updateSmartTransaction({
chainId,
nonceDetails,
metamaskNetworkId,
preTxBalance,
status: SmartTransactionStatuses.PENDING,
time,
txParams,
uuid: data.uuid,
cancellable: true,
});
} finally {
nonceLock.releaseLock();
}

nonceLock.releaseLock();
return data;
}

Expand Down