From 69ae411c75b3f0a80e6818ddbb7de6bcb7bfe55c Mon Sep 17 00:00:00 2001 From: Eric Su <60202455+GHesericsu@users.noreply.github.com> Date: Wed, 14 Dec 2022 00:32:25 +0000 Subject: [PATCH 1/4] Refactor: Update confirmTransaction strategy --- src/components/RequestAirdrop.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/RequestAirdrop.tsx b/src/components/RequestAirdrop.tsx index 179be7943..76f488628 100644 --- a/src/components/RequestAirdrop.tsx +++ b/src/components/RequestAirdrop.tsx @@ -19,8 +19,13 @@ export const RequestAirdrop: FC = () => { let signature: TransactionSignature = ''; try { - signature = await connection.requestAirdrop(publicKey, LAMPORTS_PER_SOL); - await connection.confirmTransaction(signature, 'confirmed'); + const signature = await connection.requestAirdrop(publicKey, LAMPORTS_PER_SOL); + const latestBlockHash = await connection.getLatestBlockhash(); + await connection.confirmTransaction({ + blockhash: latestBlockHash.blockhash, + lastValidBlockHeight: latestBlockHash.lastValidBlockHeight, + signature + }); notify({ type: 'success', message: 'Airdrop successful!', txid: signature }); getUserSOLBalance(publicKey, connection); From 60c2ac9beca37e7449cb3ba80509a2bd67f9a8a9 Mon Sep 17 00:00:00 2001 From: Eric Su <60202455+GHesericsu@users.noreply.github.com> Date: Wed, 14 Dec 2022 00:46:23 +0000 Subject: [PATCH 2/4] Refactor: refactor to use destructuring --- src/components/RequestAirdrop.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/RequestAirdrop.tsx b/src/components/RequestAirdrop.tsx index 76f488628..6a3ea7817 100644 --- a/src/components/RequestAirdrop.tsx +++ b/src/components/RequestAirdrop.tsx @@ -20,10 +20,10 @@ export const RequestAirdrop: FC = () => { try { const signature = await connection.requestAirdrop(publicKey, LAMPORTS_PER_SOL); - const latestBlockHash = await connection.getLatestBlockhash(); + const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash(); await connection.confirmTransaction({ - blockhash: latestBlockHash.blockhash, - lastValidBlockHeight: latestBlockHash.lastValidBlockHeight, + blockhash, + lastValidBlockHeight, signature }); notify({ type: 'success', message: 'Airdrop successful!', txid: signature }); From 44445f6f56d2e734f35dec1efbc921ebb7ecbdd6 Mon Sep 17 00:00:00 2001 From: Eric Su <60202455+GHesericsu@users.noreply.github.com> Date: Mon, 19 Dec 2022 20:00:43 +0000 Subject: [PATCH 3/4] refactor: update confirmTransaction strategy --- .vscode/settings.json | 6 ++++++ src/components/SendTransaction.tsx | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..f0a3cbd33 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "cSpell.words": [ + "Blockhash", + "txid" + ] +} \ No newline at end of file diff --git a/src/components/SendTransaction.tsx b/src/components/SendTransaction.tsx index 2d533a0fa..79a1d88eb 100644 --- a/src/components/SendTransaction.tsx +++ b/src/components/SendTransaction.tsx @@ -26,8 +26,13 @@ export const SendTransaction: FC = () => { signature = await sendTransaction(transaction, connection); - await connection.confirmTransaction(signature, 'confirmed'); - console.log(signature); + const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash(); + await connection.confirmTransaction({ + blockhash, + lastValidBlockHeight, + signature + }); + console.log('Transaction Signature:', signature); notify({ type: 'success', message: 'Transaction successful!', txid: signature }); } catch (error: any) { notify({ type: 'error', message: `Transaction failed!`, description: error?.message, txid: signature }); From 30f85a5e6425461d9db02fb9b0993f7c76b4420d Mon Sep 17 00:00:00 2001 From: Eric Su <60202455+GHesericsu@users.noreply.github.com> Date: Mon, 19 Dec 2022 20:02:06 +0000 Subject: [PATCH 4/4] delete vscode settings.json --- .vscode/settings.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index f0a3cbd33..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "cSpell.words": [ - "Blockhash", - "txid" - ] -} \ No newline at end of file