Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/rich-lizards-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@relayprotocol/relay-svm-wallet-adapter': patch
---

Poll for signature instead of waiting for confirmation
48 changes: 34 additions & 14 deletions packages/relay-svm-wallet-adapter/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,44 @@ export const adaptSolanaWallet = (
// So we don't need to handle onReplaced and onCancelled
assertBase58TransactionSignature(txHash)

const { blockhash, lastValidBlockHeight } =
await connection.getLatestBlockhash('confirmed')
const INITIAL_INTERVAL_MS = 200
const MAX_INTERVAL_MS = 1000
const MAX_POLL_DURATION_MS = 120_000
const start = Date.now()
let attempt = 0

const result = await connection.confirmTransaction({
blockhash: blockhash,
lastValidBlockHeight: lastValidBlockHeight,
signature: txHash
})
while (Date.now() - start < MAX_POLL_DURATION_MS) {
const { value } = await connection.getSignatureStatuses([txHash], {
searchTransactionHistory: attempt >= 5
})
const status = value?.[0]

if (result.value.err) {
throw new Error(`Transaction failed: ${result.value.err}`)
}
if (status?.err) {
throw new Error(`Transaction failed: ${JSON.stringify(status.err)}`)
}

if (
status?.confirmationStatus === 'confirmed' ||
status?.confirmationStatus === 'finalized'
) {
return {
blockHash: status.slot.toString(),
blockNumber: status.slot,
txHash
}
}

return {
blockHash: result.context.slot.toString(),
blockNumber: result.context.slot,
txHash
const interval = Math.min(
INITIAL_INTERVAL_MS * Math.pow(2, attempt),
MAX_INTERVAL_MS
)
await new Promise((resolve) => setTimeout(resolve, interval))
attempt++
}

throw new Error(
`Transaction confirmation timeout: ${txHash} was not confirmed within ${MAX_POLL_DURATION_MS / 1000}s`
)
},
switchChain: (chainId: number) => {
_chainId = chainId
Expand Down
Loading