Change Insufficient Allowance message to High network fee

This commit is contained in:
2025-10-17 14:45:21 +07:00
parent 3f1b5f09e0
commit acea43ec71
3 changed files with 48 additions and 5 deletions

View File

@@ -109,10 +109,15 @@ public class InsufficientFundsException : Exception
"Your wallet doesn't have enough ETH to pay for transaction gas fees.\n" + "Your wallet doesn't have enough ETH to pay for transaction gas fees.\n" +
"Please add ETH to your wallet and try again.", "Please add ETH to your wallet and try again.",
// InsufficientFundsType.InsufficientAllowance =>
// "❌ Insufficient Token Allowance\n" +
// "The trading contract doesn't have permission to spend your tokens.\n" +
// "Please approve token spending in your wallet and try again.",
InsufficientFundsType.InsufficientAllowance => InsufficientFundsType.InsufficientAllowance =>
"❌ Insufficient Token Allowance\n" + "❌ High Network Fee\n" +
"The trading contract doesn't have permission to spend your tokens.\n" + "The gas fee for this position is too high.\n" +
"Please approve token spending in your wallet and try again.", "Position opening rejected.",
InsufficientFundsType.InsufficientBalance => InsufficientFundsType.InsufficientBalance =>
"❌ Insufficient Token Balance\n" + "❌ Insufficient Token Balance\n" +

View File

@@ -770,6 +770,34 @@ export const openGmxPositionImpl = async (
direction: direction direction: direction
}); });
// Check and handle token allowance for GMX contracts
console.log('🔐 Checking token allowances for position opening...');
await approveTokenForContract(
sdk,
"USDC", // Using USDC as collateral
collateralToken,
collateralAmount,
"OrderVault"
);
await approveTokenForContract(
sdk,
"USDC", // Using USDC as collateral
collateralToken,
collateralAmount,
"ExchangeRouter"
);
await approveTokenForContract(
sdk,
"USDC", // Using USDC as collateral
collateralToken,
collateralAmount,
"SyntheticsRouter"
);
console.log('✅ Token allowances verified, proceeding with position opening...');
// Check gas fees before opening position // Check gas fees before opening position
console.log('⛽ Checking gas fees before opening position...'); console.log('⛽ Checking gas fees before opening position...');
const estimatedGasFee = await estimatePositionGasFee(sdk); const estimatedGasFee = await estimatePositionGasFee(sdk);
@@ -881,6 +909,17 @@ export async function openGmxPosition(
}; };
} }
// Handle approval-specific errors with better messaging
if (error instanceof Error && error.message.includes('Failed to handle token allowance')) {
reply.status(400);
return {
success: false,
error: error.message,
errorType: 'APPROVAL_FAILED',
suggestion: 'Token approval failed. Please ensure you have sufficient funds and try again, or manually approve the GMX contracts to spend your USDC tokens.'
};
}
return handleError(this, reply, error, 'gmx/open-position'); return handleError(this, reply, error, 'gmx/open-position');
} }
} }

View File

@@ -588,7 +588,6 @@ const TradeChart = ({
paneCount++ paneCount++
} }
console.log(indicatorsValues)
if (indicatorsValues?.MacdCross != null) { if (indicatorsValues?.MacdCross != null) {
console.log(indicatorsValues.MacdCross) console.log(indicatorsValues.MacdCross)
const histogramSeries = chart.current.addHistogramSeries({ const histogramSeries = chart.current.addHistogramSeries({