fix(pos-app): load default partner API key on first install#377
fix(pos-app): load default partner API key on first install#377ignaciosantise merged 1 commit intomainfrom
Conversation
Fix race condition where clearStaleSecureStorage() was deleting the default partner API key immediately after it was saved during store hydration. Also ensure the merchant flow hook refreshes the local API key state when the store updates via clearMerchantId(). Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Claude finished @ignaciosantise's task in 1m 3s —— View job Code ReviewTasks:
✅ No issues found Analysis Summary: Race condition fix (lines 303-305 in useSettingsStore.ts):
State refresh fix (line 78 in use-merchant-flow.ts):
Code removal (_layout.tsx lines 71-74 removed):
All changes correctly address the reported issues. Logic is sound, no edge cases identified. |
There was a problem hiding this comment.
Pull request overview
This PR fixes two critical issues that prevented the default partner API key from being properly loaded on first app install: a race condition where stale storage clearing happened after default values were set, and a state synchronization issue where the UI didn't refresh after resetting credentials.
Changes:
- Fixed race condition by moving
clearStaleSecureStorage()to execute at the start of store hydration, before default values are written - Added
isMerchantApiKeySetas a dependency to trigger API key state refresh in the merchant flow hook - Removed redundant
clearStaleSecureStorage()call from_layout.tsx
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
dapps/pos-app/store/useSettingsStore.ts |
Moved clearStaleSecureStorage() to run at the start of onRehydrateStorage callback to execute before default values are set |
dapps/pos-app/hooks/use-merchant-flow.ts |
Added isMerchantApiKeySet as a useEffect dependency to refresh local API key state when store updates |
dapps/pos-app/app/_layout.tsx |
Removed duplicate clearStaleSecureStorage() call that was causing the race condition |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Problem
On first app install, the default partner API key was not preloaded. Users had to manually navigate to Settings, clear the merchant ID, and save to trigger the default values. Additionally, after resetting to defaults, the Partner API Key field appeared empty until navigating away and back.
Root Causes
clearStaleSecureStorage()in_layout.tsxwas running afteronRehydrateStoragehad already saved the default API key, deleting it immediatelyclearMerchantIdsaved a new API key, theuseMerchantFlowhook's local state wasn't refreshed because theuseEffectdependency was stableSolution
clearStaleSecureStorage()to run at the start ofonRehydrateStorage(before defaults are set)isMerchantApiKeySetas a dependency to the API key loading effect to trigger state refresh after changesChanges
store/useSettingsStore.ts: CallclearStaleSecureStorage()at start of hydrationapp/_layout.tsx: Remove the now-redundantclearStaleSecureStorage()callhooks/use-merchant-flow.ts: Add dependency to refresh API key state on store updatesTesting