import {
isKimiaPerpError,
KIMIA_PERP_ERROR__STALE_ORACLE,
KIMIA_PERP_ERROR__INSUFFICIENT_FREE_COLLATERAL,
KIMIA_PERP_ERROR__SLIPPAGE_EXCEEDED,
} from '@/app/generated/perp/errors';
export function toUserMessage(err: unknown): string {
if (isKimiaPerpError(err, KIMIA_PERP_ERROR__STALE_ORACLE)) {
return 'Price feed is stale. Please try again.';
}
if (isKimiaPerpError(err, KIMIA_PERP_ERROR__INSUFFICIENT_FREE_COLLATERAL)) {
return 'Not enough free collateral. Cancel open orders or deposit more.';
}
if (isKimiaPerpError(err, KIMIA_PERP_ERROR__SLIPPAGE_EXCEEDED)) {
return 'Price moved too much before filling. Raise max slippage or reduce size.';
}
// ... fall-through cases
return 'Transaction failed. See logs for details.';
}