-
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
Changes from all commits
4240091
f40f76e
c499614
ca8624b
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 |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ struct TransferDashboardView: View { | |
| @State private var availableTokens: [SolanaSupportedToken] = [] | ||
| @State private var showTokenSelectionMenu: Bool = false | ||
| @State private var isSendingTransaction: Bool = false | ||
| @State private var currentIdempotencyKey: String = UUID().uuidString | ||
| @State private var idempotencyKeyTask: Task<Void, Never>? | ||
|
|
||
| var body: some View { | ||
| VStack(alignment: .leading, spacing: 16) { | ||
|
|
@@ -112,6 +114,37 @@ struct TransferDashboardView: View { | |
| selectedToken = availableTokens.first | ||
| } | ||
| }) | ||
| .onAppear { | ||
| idempotencyKeyTask?.cancel() | ||
| startIdempotencyKeyRotation() | ||
| } | ||
| .onDisappear { | ||
| idempotencyKeyTask?.cancel() | ||
| } | ||
| .onChange(of: amount) { _, _ in | ||
| resetIdempotencyKey() | ||
| } | ||
| .onChange(of: recipientWallet) { _, _ in | ||
| resetIdempotencyKey() | ||
| } | ||
| .onChange(of: selectedToken) { _, _ in | ||
| resetIdempotencyKey() | ||
| } | ||
| } | ||
|
|
||
| private func resetIdempotencyKey() { | ||
| currentIdempotencyKey = UUID().uuidString | ||
| } | ||
|
|
||
| private func startIdempotencyKeyRotation() { | ||
| idempotencyKeyTask = Task { | ||
| while !Task.isCancelled { | ||
| try? await Task.sleep(nanoseconds: 30_000_000_000) | ||
| await MainActor.run { | ||
| currentIdempotencyKey = UUID().uuidString | ||
|
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. might want to also trigger changing
Contributor
Author
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. Great suggestion! Added |
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private func triggerTransaction() async { | ||
|
|
@@ -137,7 +170,8 @@ struct TransferDashboardView: View { | |
| let summary = try await wallet.send( | ||
| recipientWallet, | ||
| "solana:\(selectedToken)", | ||
| amount | ||
| amount, | ||
| idempotencyKey: currentIdempotencyKey | ||
| ) | ||
|
|
||
| await MainActor.run { | ||
|
|
||
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
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
onAppearto prevent multiple rotation loops.