Skip to content
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
22 changes: 16 additions & 6 deletions react/lib/components/Widget/WidgetContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,16 @@ export const WidgetContainer: React.FunctionComponent<WidgetContainerProps> =
setSuccess(true);
onSuccess?.(transaction);
} else {
onTransaction?.(transaction);
// FIXME: Since the confirmed transactions are supported this could
// be called twice for the same transaction. In order to maintain
// the same behavior as before the confirmed transactions are
// supported we should only call onTransaction if the transaction is
// not confirmed. The proper fix would be to add a status so the
// callback know why it's called (added to mempool, finalized,
// confirmed, etc.). Fabien 2026-02-20
if (transaction.confirmed === false) {
onTransaction?.(transaction);
}
if (transactionText){
enqueueSnackbar(
`${
Expand Down Expand Up @@ -275,14 +284,15 @@ export const WidgetContainer: React.FunctionComponent<WidgetContainerProps> =

const handleNewTransaction = useCallback(
(tx: Transaction) => {
if (
tx.confirmed === false &&
isGreaterThanZero(resolveNumber(tx.amount))
) {
if (success) {
return;
}

if (isGreaterThanZero(resolveNumber(tx.amount))) {
handlePayment(tx);
}
},
[handlePayment],
[handlePayment, success],
);
Comment on lines +287 to 296
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

shiftCompleted is not guarded — altpayment onSuccess and success sound can fire twice.

The early-return at Line 278 only checks success, but the altpayment path in handlePayment sets shiftCompleted and calls onSuccess without setting success. This means when TX_CONFIRMED arrives after TX_ADDED_TO_MEMPOOL for an already-settled shift, success is still false, the guard is bypassed, and handlePayment runs again — re-playing the sound and re-invoking onSuccess.

🐛 Proposed fix
-      if (success) {
+      if (success || shiftCompleted) {
         return;
       }

And add shiftCompleted to the useCallback dependency array:

-      [handlePayment, success],
+      [handlePayment, success, shiftCompleted],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (success) {
return;
}
if (isGreaterThanZero(resolveNumber(tx.amount))) {
handlePayment(tx);
}
},
[handlePayment],
[handlePayment, success],
);
if (success || shiftCompleted) {
return;
}
if (isGreaterThanZero(resolveNumber(tx.amount))) {
handlePayment(tx);
}
},
[handlePayment, success, shiftCompleted],
);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@react/lib/components/Widget/WidgetContainer.tsx` around lines 278 - 287, The
callback that responds to transaction events currently only early-returns on
success, so shifts already completed via the altpayment path (shiftCompleted)
can trigger handlePayment and onSuccess again; update the early-return in the
useCallback that processes TX_CONFIRMED/TX_ADDED_TO_MEMPOOL to check both
success and shiftCompleted (e.g., if (success || shiftCompleted) return;) and
add shiftCompleted to the dependency array alongside handlePayment and success
so the callback sees updates to that flag.


const checkForTransactions = useCallback(async (): Promise<boolean> => {
Expand Down
3 changes: 2 additions & 1 deletion react/lib/util/chronik.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ export const parseWebsocketMessage = async (
}
const { msgType } = wsMsg;
switch (msgType) {
case 'TX_ADDED_TO_MEMPOOL': {
case 'TX_ADDED_TO_MEMPOOL':
case 'TX_CONFIRMED': {
const rawTransaction = await chronik.tx(wsMsg.txid);

const transaction = await getTransactionFromChronikTransaction(rawTransaction, address ?? '')
Expand Down