fix: allow model switching without re-entering wallet key

Users with existing wallets could not switch AI models because the
"Start Trading" button required a valid private key even when one was
already configured. Now the button is enabled when hasExistingWallet
is true, and handleSubmit passes an empty key so the backend preserves
the existing key.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
shinchan-zhai
2026-04-12 11:42:02 +08:00
parent a1af4fec58
commit eef78b7987
@@ -77,8 +77,11 @@ export function ModelConfigModal({
const handleSubmit = (e: React.FormEvent) => { const handleSubmit = (e: React.FormEvent) => {
e.preventDefault() e.preventDefault()
if (!selectedModelId || !apiKey.trim()) return if (!selectedModelId) return
onSave(selectedModelId, apiKey.trim(), baseUrl.trim() || undefined, modelName.trim() || undefined) const key = apiKey.trim()
// Allow empty key when editing an existing model (backend preserves existing key)
if (!key && !editingModelId) return
onSave(selectedModelId, key, baseUrl.trim() || undefined, modelName.trim() || undefined)
} }
const availableModels = allModels || [] const availableModels = allModels || []
@@ -833,9 +836,9 @@ function Claw402ConfigForm({
</button> </button>
<button <button
type="submit" type="submit"
disabled={!isKeyValid} disabled={!isKeyValid && !hasExistingWallet}
className="flex-1 flex items-center justify-center gap-2 px-4 py-3 rounded-xl text-sm font-bold transition-all hover:scale-[1.02] disabled:opacity-50 disabled:cursor-not-allowed" className="flex-1 flex items-center justify-center gap-2 px-4 py-3 rounded-xl text-sm font-bold transition-all hover:scale-[1.02] disabled:opacity-50 disabled:cursor-not-allowed"
style={{ background: isKeyValid ? 'linear-gradient(135deg, #2563EB, #7C3AED)' : '#2B3139', color: '#fff' }} style={{ background: (isKeyValid || hasExistingWallet) ? 'linear-gradient(135deg, #2563EB, #7C3AED)' : '#2B3139', color: '#fff' }}
> >
{'🚀 ' + t('modelConfig.startTrading', language)} {'🚀 ' + t('modelConfig.startTrading', language)}
</button> </button>