fix(swift-example-app): harden Withdraw Credits amount + address validation#3907
Conversation
…dation Two issues from review on PR #3906: - BLOCKING: parsedCredits could crash on large input. `Double(UInt64.max)` isn't exactly representable and rounds up to 2^64, so the `credits <= Double(UInt64.max)` guard admitted 2^64 and `UInt64(credits)` trapped — and parsedCredits recomputes on every keystroke, before submit-time re-validation. Switched the bound to strict `<` so 2^64 is rejected and the cast stays in range. - UX: the submit button enabled for any non-empty destination, so the user only learned an address was malformed/wrong-network after the Rust round-trip. Added `isValidDestinationAddress` using the existing `DashAddress.parse(_, network:)` bridge (Base58Check + network check in Rust) — `canSubmit` and the submit() guard now require a valid `.core` address, with an inline "not a valid <network> address" hint. No consensus logic in Swift; authoritative validation still runs in Rust on submit. Verified on the simulator (devnet): an invalid address keeps the button disabled + shows the hint; a huge amount (2e8 DASH) no longer crashes the sheet (button stays disabled). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 8 minutes and 31 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
✅ Review complete (commit 6ae7f99) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Tight, well-scoped UI hardening on SwiftExampleApp's Withdraw Credits sheet. Strict < against Double(UInt64.max) correctly avoids the rounding-to-2^64 trap on UInt64(credits), and the new isValidDestinationAddress delegates to the existing Rust-backed DashAddress.parse bridge while keeping authoritative validation in Rust on submit. Diff is confined to WithdrawCreditsView.swift; no FFI, consensus, or business-logic surface area is affected.
|
✅ DashSDKFFI.xcframework built for this PR.
SwiftPM (host the zip at a stable URL, then use): .binaryTarget(
name: "DashSDKFFI",
url: "https://your.cdn.example/DashSDKFFI.xcframework.zip",
checksum: "5fdc8698e53d69ec7b7089a9feb17eacdb1bbe2c4ec9aa38740bab1008a94eb6"
)Xcode manual integration:
|
Issue being fixed or feature implemented
Follow-up to #3906 (Withdraw Credits production UI, ID-10), which merged before review feedback from
thepastaclawwas addressed. Two issues inWithdrawCreditsView:parsedCreditscould crash on large input.Double(UInt64.max)isn't exactly representable and rounds up to 2^64, so thecredits <= Double(UInt64.max)guard admitted 2^64 andUInt64(credits)trapped.parsedCreditsrecomputes on every keystroke (before submit-time re-validation), so an amount scaling to ~2^64 credits would crash the sheet on input rather than show a friendly error. (Same shape exists in the mergedTransferCreditsView.parsedCredits— flagged separately as a follow-up.)What was done?
parsedCredits: switched the upper bound to strict<so 2^64 is rejected and theUInt64cast stays in range.isValidDestinationAddress, which uses the existingDashAddress.parse(_, network:)bridge (Base58Check + network validation in Rust) and accepts a.core(L1) result.canSubmitand thesubmit()guard now require a valid address, and an inline "Not a valid Dash address" hint explains the disabled state. No consensus logic added to Swift — authoritative validation still runs in Rust on submit, matching the file header.How Has This Been Tested?
./build_ios.sh-equivalent app build succeeds (0 errors, 0 code warnings). Driven on the simulator (devnet):Breaking Changes
None. UI-only validation hardening in the example app.
Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code