Change Insufficient Allowance message to High network fee
This commit is contained in:
@@ -109,11 +109,16 @@ public class InsufficientFundsException : Exception
|
||||
"Your wallet doesn't have enough ETH to pay for transaction gas fees.\n" +
|
||||
"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 =>
|
||||
// "❌ 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 =>
|
||||
"❌ High Network Fee\n" +
|
||||
"The gas fee for this position is too high.\n" +
|
||||
"Position opening rejected.",
|
||||
|
||||
InsufficientFundsType.InsufficientBalance =>
|
||||
"❌ Insufficient Token Balance\n" +
|
||||
"Your wallet doesn't have enough tokens for this trade.\n" +
|
||||
|
||||
@@ -770,6 +770,34 @@ export const openGmxPositionImpl = async (
|
||||
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
|
||||
console.log('⛽ Checking gas fees before opening position...');
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,7 +588,6 @@ const TradeChart = ({
|
||||
paneCount++
|
||||
}
|
||||
|
||||
console.log(indicatorsValues)
|
||||
if (indicatorsValues?.MacdCross != null) {
|
||||
console.log(indicatorsValues.MacdCross)
|
||||
const histogramSeries = chart.current.addHistogramSeries({
|
||||
|
||||
Reference in New Issue
Block a user