Skip to content

Commit

Permalink
fix(blockchain-link): show better message for solana expired txs
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBenc authored and tomasklim committed Oct 28, 2024
1 parent e9973e9 commit 74d5365
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions packages/blockchain-link/src/workers/solana/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type * as MessageTypes from '@trezor/blockchain-link-types/src/messages';
import { CustomError } from '@trezor/blockchain-link-types/src/constants/errors';
import { BaseWorker, ContextType, CONTEXT } from '../baseWorker';
import { MESSAGES, RESPONSES } from '@trezor/blockchain-link-types/src/constants';
import { Connection, Message, PublicKey } from '@solana/web3.js';
import { Connection, Message, PublicKey, SendTransactionError } from '@solana/web3.js';
import { solanaUtils } from '@trezor/blockchain-link-utils';
import { createLazy } from '@trezor/utils';

Expand Down Expand Up @@ -105,17 +105,35 @@ const pushTransaction = async (request: Request<MessageTypes.PushTransaction>) =
const { lastValidBlockHeight } = await api.getLatestBlockhash('finalized');

const txBuffer = Buffer.from(rawTx, 'hex');
const signature = await api.sendRawTransaction(txBuffer, {
skipPreflight: true,
maxRetries: 0,
});

await confirmTransactionWithResubmit(api, txBuffer, signature, lastValidBlockHeight);
try {
await api.sendRawTransaction(txBuffer, {
skipPreflight: true,
maxRetries: 0,
});

return {
type: RESPONSES.PUSH_TRANSACTION,
payload: signature,
} as const;
const signature = await api.sendRawTransaction(txBuffer, {
skipPreflight: true,
maxRetries: 0,
});

await confirmTransactionWithResubmit(api, txBuffer, signature, lastValidBlockHeight);

return {
type: RESPONSES.PUSH_TRANSACTION,
payload: signature,
} as const;
} catch (error) {
if (
error instanceof SendTransactionError &&
error?.transactionError?.message === 'Internal error'
) {
throw new Error(
'Please make sure that you submit the transaction within 1 minute after signing.',
);
}
throw error;
}
};

const getAccountInfo = async (request: Request<MessageTypes.GetAccountInfo>) => {
Expand Down

0 comments on commit 74d5365

Please sign in to comment.