Skip to content

Commit

Permalink
optimise code
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemaccana committed Feb 5, 2024
1 parent adf9573 commit 8ee56c7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,18 @@ export const confirmTransaction = async (
signature: string,
): Promise<string> => {
const block = await connection.getLatestBlockhash();
const res = await connection.confirmTransaction({
const response = await connection.confirmTransaction({
signature,
...block,
});

/**
* note: `confirmTransaction` does not throw an error if the confirmation does not succeed,
* but rather a `TransactionError` object. so we handle that here
*
* https://solana-labs.github.io/solana-web3.js/classes/Connection.html#confirmTransaction.confirmTransaction-1
*/
if (!!res.value.err) throw Error(res.value.err.toString());
// Note: `confirmTransaction` does not throw an error if the confirmation does not succeed,
// but rather the response will have an `err` key with a `TransactionError` object | string.
// See https://solana-labs.github.io/solana-web3.js/classes/Connection.html#confirmTransaction.confirmTransaction-1
const error = response.value.err;
if (error) {
throw Error(error.toString());
}

return signature;
};
Expand Down

0 comments on commit 8ee56c7

Please sign in to comment.