-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add x-idempotency-key header to transfer endpoint #41
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
feat: add x-idempotency-key header to transfer endpoint #41
Conversation
Original prompt from [email protected] |
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…tating key to demo app Co-Authored-By: [email protected] <[email protected]>
| } | ||
| }) | ||
| .onAppear { | ||
| startIdempotencyKeyRotation() |
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.
this hook can fire multiple times, might want to change to
idempotencyKeyTask?.cancel()
startIdempotencyKeyRotation()
to prevent multiple key rotation tasks
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.
Good catch! Fixed - now cancelling any existing task before starting a new one in onAppear to prevent multiple rotation loops.
| while !Task.isCancelled { | ||
| try? await Task.sleep(nanoseconds: 30_000_000_000) | ||
| await MainActor.run { | ||
| currentIdempotencyKey = UUID().uuidString |
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.
might want to also trigger changing currentIdempotencyKey any time recipient, token locator, or amount is changed
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.
Great suggestion! Added onChange handlers for amount, recipientWallet, and selectedToken that reset the idempotency key when any of these parameters change. This makes sense semantically since a different recipient/token/amount represents a new transaction that should have its own idempotency key.
brendanw
left a comment
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.
looks good aside from minor comments
…-sdk-coverage Resolved conflicts by combining: - Logging statements from current branch - Idempotency key functionality from PR #41
Summary
Adds an
x-idempotency-keyheader with a unique UUID to requests made to the token transfer endpoint (/api/2025-06-09/wallets/{walletLocator}/tokens/{tokenLocator}/transfers). This prevents duplicate transaction creation when the same transfer request is accidentally sent multiple times.Updates since last revision:
idempotencyKeyparameter onWallet.send()method, allowing callers to provide their own key for retry scenariosThe implementation mirrors the approach taken in the Kotlin SDK (PR #45).
Test plan
x-idempotency-keyheader is present in the outgoing requestwallet.send()without providingidempotencyKey- should auto-generate a UUIDwallet.send()with a customidempotencyKey- should use the provided valueReview & Testing Checklist for Human
x-idempotency-key(lowercase) - confirm this matches the API specificationsendAPI) still works correctlyNotes
send(token:recipient:amount:)method which doesn't expose the idempotency key parameter