feat(web-ui): detect and warn about API keys from other origins#175
feat(web-ui): detect and warn about API keys from other origins#175dorukardahan wants to merge 1 commit into0gfoundation:mainfrom
Conversation
When a user generates API keys from one browser origin (e.g., localhost:3090), those key strings are stored in origin-scoped localStorage. Accessing the WebUI from a different origin shows these slots as "available" instead of warning the user. Changes: - Add externalSlotCount heuristic to useOnChainTokens (generation counter + local key count) - Add 'unknown' slot status type to useSlotStatus for ambiguous slots - Add amber warning banner to ProviderApiKeyManager when external keys are detected - Add confirm dialog before key generation when slot collision is possible - Add unknown slot indicator to SlotStatusCompact header - Add yellow circle icon and legend entry for unknown slots in SlotManager grid Fixes 0gfoundation#174
|
@dorukardahan is attempting to deploy a commit to the 0g-Frontend Team on Vercel. A member of the Team first needs to authorize it. |
|
Self-review: improvements from a second pass Design decision — heuristic vs definitive detection:
The false positive after "Refresh All" is acceptable because: generation increments, bitmap resets, but some slots may legitimately be empty. The warning is informational, not blocking. Potential improvement for a follow-up PR: No breaking changes:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Summary
Why
API key strings are stored in origin-scoped
localStorage, while token slots are tracked on-chain. When a user generates keys from one origin (e.g.,localhost:3090) and later accesses the WebUI from a different origin, those slots appear as "available" instead of showing a warning. This can lead to silent key invalidation when the user generates a new key that reuses an occupied slot.Files changed
useOnChainTokens.tsexternalSlotCountreturn value using generation counter heuristicuseSlotStatus.ts'unknown'slot status type andunknowncount to SlotStatsProviderApiKeyManager.tsxSlotStatusCompact.tsxSlotManager.tsxHow the heuristic works
A slot is marked "unknown" (instead of "available") when ALL of these are true:
This prevents false positives for brand-new users (generation === 0, no keys) while catching the case where keys exist from another origin.
Edge cases handled
Test plan
Fixes #174