bitcoindevkit / bitcoindevkit/BDKSwiftExampleWallet

Make transaction sending fully async so the UI only reports success after broadcast completes

Đang mở
#360 0 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Swift
Star
31
Fork
16
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

## Summary

The current send flow can report success before the transaction has actually been broadcast.

`BDKClient.send` is exposed as a synchronous throwing API, but the live implementation immediately starts an internal `Task` and returns without waiting for the async broadcast to finish. Because of that, the UI continues as if the send succeeded even though the real network operation is still in progress.

## Why This Matters

This creates a user-facing correctness bug:

- The app can show a success state before the transaction is actually broadcast.
- Broadcast failures may be surfaced too late, or not in the right screen context.
- The user can be navigated away from the send screen even if the transaction was rejected.
- A wallet app should never optimistically confirm a send before the backend confirms success.

## Current Behavior

- `BuildTransactionViewModel.send()` calls `bdkClient.send(...)`.
- The live `BDKClient.send` implementation starts a background `Task` and returns immediately.
- `BuildTransactionViewModel` then posts `TransactionSent` right away.
- `BuildTransactionView` waits one second and assumes success if no error has appeared yet.

This means success is based on timing, not on the actual result of the broadcast.

## Expected Behavior

The send flow should only report success after signing and broadcasting have completed successfully.

## Proposed Fix

- Change the send API from synchronous to `async throws` across the stack.
- Make `BDKClient.send` await `BDKService.send(...)` directly instead of wrapping it in a detached `Task`.
- Update `BuildTransactionViewModel.send()` to be `async`.
- In `BuildTransactionView`, await the send call and only show the success UI after it returns successfully.
- Remove the one-second timer-based success heuristic.
- Post wallet update notifications only after the async send has actually succeeded.

## Suggested Acceptance Criteria

- A failed broadcast does not show the success checkmark.
- The user remains on the send screen when send fails.
- A successful broadcast shows success only after the async operation completes.
- No send-related state depends on fixed delays or race-prone background fire-and-forget tasks.

## References

- `BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift`
- `BDKSwiftExampleWallet/View Model/Send/BuildTransactionViewModel.swift`
- `BDKSwiftExampleWallet/View/Send/BuildTransactionView.swift`

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start with BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift and trace the send flow through BuildTransactionViewModel.swift and BuildTransactionView.swift. Update the flow so signing and broadcasting complete before success is reported, remove the fixed-delay heuristic, and verify that failures stay on the send screen while successful broadcasts show success afterward.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
swift
Lĩnh vực
mobile
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.