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

Attempt to search for signature transaction status if confirm fails #369

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function buildOptimalTransactionImpl(
0,
)
averagePrioritizationFee = Math.ceil(
(averagePrioritizationFee / recentPrioritizationFees.length) * 1.5,
(averagePrioritizationFee / recentPrioritizationFees.length) * 2000,
)

tx.instructions.unshift(
Expand Down
35 changes: 28 additions & 7 deletions packages/huma-widget/src/components/SolanaTxSendModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SolanaChainEnum } from '@huma-finance/shared'
import { sleep, SolanaChainEnum } from '@huma-finance/shared'
import React, { useEffect, useState } from 'react'
import {
buildOptimalTransactionFromConnection,
Expand Down Expand Up @@ -34,6 +34,7 @@ export function SolanaTxSendModal({
return
}

let signatureResult = ''
try {
// Optimize transaction
const lockedWritableAccounts = extractWritableAccounts(tx)
Expand All @@ -42,20 +43,40 @@ export function SolanaTxSendModal({
lockedWritableAccounts,
connection,
)
const signature = await sendTransaction(optimizedTx, connection, {
maxRetries: 5,
signatureResult = await sendTransaction(optimizedTx, connection, {
preflightCommitment: 'confirmed',
skipPreflight: true,
})
setSignature(signature)
dispatch(setSolanaSignature(signature))
setSignature(signatureResult)
dispatch(setSolanaSignature(signatureResult))
await connection.confirmTransaction({
blockhash: optimizedTx.recentBlockhash!,
lastValidBlockHeight: optimizedTx.lastValidBlockHeight!,
signature,
signature: signatureResult,
})
handleSuccess({ signature })
handleSuccess({ signature: signatureResult })
} catch (error: unknown) {
let signatureStatusRetries = 0

while (signatureStatusRetries < 5) {
// Attempt to load the signature status using transaction history
// eslint-disable-next-line no-await-in-loop
await sleep(1000)
// eslint-disable-next-line no-await-in-loop
const result = await connection.getSignatureStatus(signatureResult, {
searchTransactionHistory: true,
})
if (
result?.value?.confirmationStatus === 'finalized' ||
result?.value?.confirmationStatus === 'confirmed'
) {
handleSuccess({ signature: signatureResult })
return
}

signatureStatusRetries += 1
}

const err = error as Error
dispatch(setError({ errorMessage: err?.message || '' }))
}
Expand Down
Loading