-
Notifications
You must be signed in to change notification settings - Fork 24
fix: prevent swap autoclaim race between service worker and UI #558
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,16 +51,25 @@ export default function AppBoltzSwap() { | |
| const [processing, setProcessing] = useState<boolean>(false) | ||
| const [opDone, setOpDone] = useState(false) | ||
| const [success, setSuccess] = useState<boolean>(false) | ||
| const [swapManagerProcessing, setSwapManagerProcessing] = useState(false) | ||
|
|
||
| // Subscribe to real-time updates for this swap | ||
| useEffect(() => { | ||
| if (!swapManager || !swapInfo) return | ||
|
|
||
| let unsub: (() => void) | null = null | ||
| let cancelled = false | ||
|
|
||
| swapManager.isProcessing(swapInfo.id).then((p) => { | ||
| if (!cancelled) setSwapManagerProcessing(p) | ||
| }) | ||
|
|
||
| swapManager | ||
| .subscribeToSwapUpdates(swapInfo.id, (updatedSwap) => { | ||
| setSwapInfo(updatedSwap) | ||
| swapManager.isProcessing(updatedSwap.id).then((p) => { | ||
| if (!cancelled) setSwapManagerProcessing(p) | ||
| }) | ||
| }) | ||
| .then((unsubscribe) => { | ||
| if (cancelled) { | ||
|
|
@@ -147,11 +156,15 @@ export default function AppBoltzSwap() { | |
|
|
||
| const isRefundable = isSubmarineSwapRefundable(swapInfo) || isChainSwapRefundable(swapInfo) | ||
| const isClaimable = isReverseSwapClaimable(swapInfo) || isChainSwapClaimable(swapInfo) | ||
| const buttonLabel = isClaimable ? 'Complete swap' : 'Refund swap' | ||
| const buttonLabel = swapManagerProcessing ? 'Claiming...' : isClaimable ? 'Complete swap' : 'Refund swap' | ||
| const refunded = swapInfo.status === 'transaction.refunded' | ||
|
|
||
| const buttonHandler = async () => { | ||
| try { | ||
| if (swapManager) { | ||
| const alreadyProcessing = await swapManager.isProcessing(swapInfo.id) | ||
| if (alreadyProcessing) return | ||
| } | ||
|
Comment on lines
+159
to
+167
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scope the guard to claims and sync stale UI on early return. The current 🐛 Proposed fix- const buttonLabel = swapManagerProcessing ? 'Claiming...' : isClaimable ? 'Complete swap' : 'Refund swap'
+ const claimInProgress = swapManagerProcessing && !isRefundable
+ const buttonLabel = claimInProgress ? 'Claiming...' : isClaimable ? 'Complete swap' : 'Refund swap'
const refunded = swapInfo.status === 'transaction.refunded'
const buttonHandler = async () => {
try {
- if (swapManager) {
+ if (isClaimable && swapManager) {
const alreadyProcessing = await swapManager.isProcessing(swapInfo.id)
- if (alreadyProcessing) return
+ if (alreadyProcessing) {
+ setSwapManagerProcessing(true)
+ return
+ }
}- {!success && (isRefundable || isClaimable || swapManagerProcessing) ? (
+ {!success && (isRefundable || isClaimable || claimInProgress) ? (
<ButtonsOnBottom>
- <Button onClick={buttonHandler} label={buttonLabel} disabled={processing || swapManagerProcessing} />
+ <Button onClick={buttonHandler} label={buttonLabel} disabled={processing || claimInProgress} />
</ButtonsOnBottom>
) : null}Also applies to: 233-235 🤖 Prompt for AI Agents |
||
| setProcessing(true) | ||
| if (isReverseSwapClaimable(swapInfo)) { | ||
| await claimVHTLC(swapInfo) | ||
|
|
@@ -217,9 +230,9 @@ export default function AppBoltzSwap() { | |
| )} | ||
| </Padded> | ||
| </Content> | ||
| {!success && (isRefundable || isClaimable) ? ( | ||
| {!success && (isRefundable || isClaimable || swapManagerProcessing) ? ( | ||
| <ButtonsOnBottom> | ||
| <Button onClick={buttonHandler} label={buttonLabel} disabled={processing} /> | ||
| <Button onClick={buttonHandler} label={buttonLabel} disabled={processing || swapManagerProcessing} /> | ||
| </ButtonsOnBottom> | ||
| ) : null} | ||
| </> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# First, let's check the actual file and its imports head -50 src/screens/Apps/Boltz/Swap.tsxRepository: arkade-os/wallet
Length of output: 2284
🏁 Script executed:
Repository: arkade-os/wallet
Length of output: 1106
🏁 Script executed:
Repository: arkade-os/wallet
Length of output: 1187
🏁 Script executed:
Repository: arkade-os/wallet
Length of output: 218
Handle failed processing-state checks with proper error containment.
Both
isProcessing()calls (lines 63–65 and 70–72) lack.catch()handlers, which leaves unhandled promise rejections and staleswapManagerProcessingstate if the swap-manager check fails. This can freeze the claim/refund button UI. Extract a helper function to centralize error handling, log the failure, and reset state to a safe default.🛡️ Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents