fix: replace toast.promise with await to ensure state refresh after API calls

sonner's toast.promise() returns a toast ID (not a Promise), so
await resolves immediately and subsequent data refresh fetches stale
data. Users had to manually reload to see changes.

Fixed across AITradersPage, SettingsPage, and TraderConfigModal.
This commit is contained in:
shinchan-zhai
2026-03-21 00:54:36 +08:00
parent 58236ba8b5
commit 53ac52562f
3 changed files with 32 additions and 80 deletions

View File

@@ -120,11 +120,8 @@ export function SettingsPage() {
}])
),
}
await toast.promise(api.updateModelConfigs(request), {
loading: 'Saving model config...',
success: 'Model config saved',
error: 'Failed to save model config',
})
await api.updateModelConfigs(request)
toast.success('Model config saved')
const refreshed = await api.getModelConfigs()
setConfiguredModels(refreshed)
setShowModelModal(false)
@@ -198,11 +195,8 @@ export function SettingsPage() {
},
},
}
await toast.promise(api.updateExchangeConfigsEncrypted(request), {
loading: 'Updating exchange config...',
success: 'Exchange config updated',
error: 'Failed to update exchange config',
})
await api.updateExchangeConfigsEncrypted(request)
toast.success('Exchange config updated')
} else {
const createRequest = {
exchange_type: exchangeType,
@@ -221,11 +215,8 @@ export function SettingsPage() {
lighter_api_key_private_key: lighterApiKeyPrivateKey || '',
lighter_api_key_index: lighterApiKeyIndex || 0,
}
await toast.promise(api.createExchangeEncrypted(createRequest), {
loading: 'Creating exchange account...',
success: 'Exchange account created',
error: 'Failed to create exchange account',
})
await api.createExchangeEncrypted(createRequest)
toast.success('Exchange account created')
}
const refreshed = await api.getExchangeConfigs()
setExchanges(refreshed)
@@ -238,11 +229,8 @@ export function SettingsPage() {
const handleDeleteExchange = async (exchangeId: string) => {
try {
await toast.promise(api.deleteExchange(exchangeId), {
loading: 'Deleting exchange account...',
success: 'Exchange account deleted',
error: 'Failed to delete exchange account',
})
await api.deleteExchange(exchangeId)
toast.success('Exchange account deleted')
const refreshed = await api.getExchangeConfigs()
setExchanges(refreshed)
setShowExchangeModal(false)