Skip to content

Commit 5b646e0

Browse files
committed
propagate exception
1 parent 395d17d commit 5b646e0

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

platforms/solana/src/signer.ts

+30-32
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,12 @@ export async function getWritableAccounts(
403403
return msg.compiledInstructions
404404
.flatMap((ix) => ix.accountKeyIndexes)
405405
.map((k) => (msg.isAccountWritable(k) ? keys.get(k) : null))
406-
.filter((k) => !!k) as PublicKey[];
406+
.filter(Boolean) as PublicKey[];
407407
} else {
408408
return transaction.instructions
409409
.flatMap((ix) => ix.keys)
410410
.map((k) => (k.isWritable ? k.pubkey : null))
411-
.filter((k) => !!k) as PublicKey[];
411+
.filter(Boolean) as PublicKey[];
412412
}
413413
}
414414

@@ -481,6 +481,7 @@ interface RpcResponse {
481481

482482
// Helper function to calculate the priority fee using the Triton One API
483483
// See https://docs.triton.one/chains/solana/improved-priority-fees-api
484+
// NOTE: this is currently an experimental feature
484485
export async function determinePriorityFeeTritonOne(
485486
connection: Connection,
486487
transaction: Transaction | VersionedTransaction,
@@ -504,42 +505,39 @@ export async function determinePriorityFeeTritonOne(
504505
},
505506
];
506507

507-
try {
508-
const response = (await rpcRequest(
509-
'getRecentPrioritizationFees',
510-
args,
511-
)) as RpcResponse;
508+
const response = (await rpcRequest(
509+
'getRecentPrioritizationFees',
510+
args,
511+
)) as RpcResponse;
512512

513-
if (response.error) {
514-
throw new Error(response.error);
515-
}
513+
if (response.error) {
514+
// Allow the error to propagate so the caller can handle it and fall-back if needed
515+
throw new Error(response.error);
516+
}
516517

517-
const recentPrioritizationFees =
518-
response.result as RecentPrioritizationFees[];
518+
const recentPrioritizationFees =
519+
response.result as RecentPrioritizationFees[];
519520

520-
if (recentPrioritizationFees.length > 0) {
521-
const sortedFees = recentPrioritizationFees.sort(
522-
(a, b) => a.prioritizationFee - b.prioritizationFee,
523-
);
521+
if (recentPrioritizationFees.length > 0) {
522+
const sortedFees = recentPrioritizationFees.sort(
523+
(a, b) => a.prioritizationFee - b.prioritizationFee,
524+
);
524525

525-
// Calculate the median
526-
const half = Math.floor(sortedFees.length / 2);
527-
if (sortedFees.length % 2 === 0) {
528-
fee = Math.floor(
529-
(sortedFees[half - 1]!.prioritizationFee +
530-
sortedFees[half]!.prioritizationFee) /
531-
2,
532-
);
533-
} else {
534-
fee = sortedFees[half]!.prioritizationFee;
535-
}
526+
// Calculate the median
527+
const half = Math.floor(sortedFees.length / 2);
528+
if (sortedFees.length % 2 === 0) {
529+
fee = Math.floor(
530+
(sortedFees[half - 1]!.prioritizationFee +
531+
sortedFees[half]!.prioritizationFee) /
532+
2,
533+
);
534+
} else {
535+
fee = sortedFees[half]!.prioritizationFee;
536+
}
536537

537-
if (multiple > 0) {
538-
fee *= multiple;
539-
}
538+
if (multiple > 0) {
539+
fee *= multiple;
540540
}
541-
} catch (e) {
542-
console.error('Error fetching Triton One Solana recent fees', e);
543541
}
544542

545543
// Bound the return value by the parameters passed

0 commit comments

Comments
 (0)