feat(extension-wallet): wire session key TTL refresh to AccountContract - #1215
Open
OZILSOLAR wants to merge 1 commit into
Open
Conversation
Integrate real contract interaction for refreshSessionKey hook (ancore-org#963) - Implement contract call to refreshSessionKeyTtl via AncoreClient - Maintain optimistic UI update with rollback on contract failure - Add proper loading state during contract interaction - Pass original session key expiresAt to contract for TTL extension - Add comprehensive test coverage for refresh functionality The refreshSessionKey hook now: 1. Optimistically updates local state with new expiry time 2. Calls client.refreshSessionKeyTtl() to extend Soroban TTL on-chain 3. Rolls back local changes if contract operation fails 4. Handles loading states and error messages properly This resolves the security vulnerability where users believed their session expiry was extended when only the frontend store was updated.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wire Session Keys UI Refresh TTL to AccountContract / Core-SDK
Summary
This PR integrates real smart contract interaction for the session key TTL refresh functionality, resolving a critical security vulnerability where
users believed their session expiry was extended when only the frontend state was updated. The
refreshSessionKeyhook now properly calls the@ancore/core-sdk'srefreshSessionKeyTtlmethod to extend the Soroban persistent storage TTL on-chain.Closes #963
Problem Statement
The
useSessionKeys.refreshSessionKeyhook was only modifying local UI state without actually calling the smart contract to refresh the session key TTLon-chain. This created a false sense of security:
Solution
Core Changes
1. Contract Integration in
useSessionKeys.tsAncoreClient.refreshSessionKeyTtl()to actually invoke the smart contractauthState.accountAddressto the dependency array for correct client initialization2. Implementation Flow
Optimistically update local state (instant UI feedback)
↓
Create AncoreClient with account contract ID
↓
Call client.refreshSessionKeyTtl(publicKey, expiresAt)
↓
Success: Contract extends Soroban TTL, UI shows new expiry
↓
Failure: Rollback local state, display error message
3. Comprehensive Test Suite
Created
useSessionKeys.test.tswith 10+ test cases covering:Key Features
Security
✅ Eliminates false security by ensuring actual on-chain state changes
✅ Proper validation of session key existence before contract call
✅ Error handling prevents misleading UI states
User Experience
✅ Optimistic UI updates provide instant feedback
✅ Loading state indicates ongoing contract operation
✅ Clear error messages on failures
✅ Automatic rollback prevents inconsistent UI/contract states
Code Quality
✅ Follows existing patterns in
addSessionKeyandrevokeSessionKey✅ Proper dependency management in useCallback
✅ Comprehensive test coverage
✅ Clear error handling with user-friendly messages
Files Changed
Modified
apps/extension-wallet/src/hooks/useSessionKeys.tsrefreshSessionKeycallback to callclient.refreshSessionKeyTtl()setIsLoading(true/false)authState.accountAddressto dependency arrayAdded
apps/extension-wallet/src/hooks/__tests__/useSessionKeys.test.ts(NEW)Technical Details
Contract Method Signature