Successfully implemented complete automated airdrop claiming functionality with background OTP processing. The system provides a seamless user experience where claims are processed automatically after a single button click.
- airdrop_claim.rs: OTP request creation and Ed25519 signing
- commands.rs: New
send_otp_requestTauri command - WebSocket Integration: Leverages existing WebSocket infrastructure
- 4 Core Hooks: CSRF, claim status, OTP handling, background submission
- React Query Integration: Proper caching and error handling
- Toast Notifications: User feedback throughout the process
- Zustand Store: State management for claim process
- Ed25519 Signatures: All OTP requests cryptographically signed
- CSRF Protection: Tokens fetched and validated for each claim
- Replay Protection: Nonces and timestamps prevent replay attacks
- 3-minute Timeout: OTP requests timeout for security
- One-Click Claims: Complete automation after button press
- Loading States: Clear progress indication through each step
- Error Handling: Comprehensive error feedback with retry options
- Background Processing: No user intervention required during OTP flow
- Existing WebSocket: Reuses established connection infrastructure
- HTTP API: Follows existing
handleAirdropRequestpatterns - Toast System: Integrates with existing notification system
- Store Actions: Extends airdrop store with claim functionality
src-tauri/src/airdrop_claim.rs- Backend OTP handlingsrc/types/airdrop-claim.ts- TypeScript interfacessrc/hooks/airdrop/claim/useCsrfToken.ts- CSRF token managementsrc/hooks/airdrop/claim/useClaimStatus.ts- Claim eligibility checkingsrc/hooks/airdrop/claim/useAutomaticOtpClaim.ts- WebSocket OTP handlingsrc/hooks/airdrop/claim/useBackgroundClaimSubmission.ts- Complete flow orchestrationsrc/hooks/airdrop/claim/index.ts- Barrel exportssrc/components/airdrop/AirdropClaimButton.tsx- UI componentsrc/components/airdrop/AirdropClaimExample.tsx- Usage example
src-tauri/src/main.rs- Added module and command registrationsrc-tauri/src/commands.rs- Addedsend_otp_requestcommandsrc/store/useAirdropStore.ts- Added claim state interfacesrc/store/actions/airdropStoreActions.ts- Added claim actions
import { AirdropClaimButton } from '@app/components/airdrop/AirdropClaimButton';
import { useClaimStatus } from '@app/hooks/airdrop/claim';
export const MyComponent = () => {
const { data: claimStatus } = useClaimStatus();
return (
<div>
{claimStatus?.hasClaim && (
<AirdropClaimButton claimTarget="xtm">Claim {claimStatus.amount} XTM</AirdropClaimButton>
)}
</div>
);
};- User clicks claim button
- System fetches CSRF token via HTTP
- OTP request sent via WebSocket with Ed25519 signature
- Backend processes and forwards to airdrop API
- OTP received via WebSocket response
- Claim submitted automatically with OTP + CSRF token
- Success/error feedback via Toast notifications
- Rust Compilation: ✅ Clean (1 unused function warning)
- TypeScript Compilation: ✅ Clean
- Build Process: ✅ Successful
- Integration: ✅ All existing patterns followed
- Backend API Integration: Ensure airdrop API endpoints match implementation
- Error Message Localization: Add i18n support for error messages
- Rate Limiting: Implement client-side rate limiting for claim attempts
- Analytics: Add tracking for claim success/failure rates
- Testing: Unit tests for claim hooks and integration tests
- ✅ No sensitive data logged or persisted
- ✅ OTP timeout prevents stale claims
- ✅ Cryptographic signatures on all requests
- ✅ CSRF protection on API endpoints
- ✅ Proper error handling without information leakage
- ✅ React Query caching for CSRF tokens and claim status
- ✅ WebSocket connection reuse for OTP requests
- ✅ Automatic cleanup of event listeners and timeouts
- ✅ Minimal state updates to prevent unnecessary re-renders
This implementation provides a robust, secure, and user-friendly airdrop claiming system that integrates seamlessly with the existing codebase architecture.