Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

Fix transaction fee display precision (C7E-764)

Issue

Controller fee estimate rounds numbers (to 2 decimal places) but execution doesn't use the rounded values. For example, users see "$5.13 USDC" but are actually charged "$5.125 USDC".

Changes

  • Added exactPrecision parameter to convertTokenAmountToUSD function
  • Modified the function to display exact values when exactPrecision is true
  • Updated the Fees component to use the exact precision parameter for fee display

This change ensures that the fee amount displayed to users matches exactly what they'll be charged, eliminating confusion.

Testing

  • Verified that the changes pass linting and formatting checks

Link to Devin run: https://app.devin.ai/sessions/f4b189805d3d45f6ac135aca3ec613ef
Requested by: Tarrence van As ([email protected])

@devin-ai-integration
Copy link
Contributor Author

Original prompt from Tarrence:

Hey Devin,

I need your help fixing a UX issue with our transaction fee display in the Cartridge controller (ticket C7E-764). Currently, there's a discrepancy between the fee amounts shown to users and what they're actually charged.

**Issue**: Controller fee estimate rounds numbers (to 2 decimal places) but execution doesn't use the rounded values. For example, users see "$5.13 USDC" but are actually charged "$5.125 USDC".

**Repository**: cartridge-gg/controller

**Core files to modify**:
- `packages/keychain/src/hooks/tokens.tsx` - Contains the `convertTokenAmountToUSD` function that handles fee display formatting
- `packages/keychain/src/components/Fees.tsx` - Uses the formatted fee values for display

**Recommended approach**: Modify the `convertTokenAmountToUSD` function to display exact precise values for transaction fees instead of rounding them. This will ensure users see exactly what they'll be charged.

**Implementation details**:
1. Update the `convertTokenAmountToUSD` function in `packages/keychain/src/hooks/tokens.tsx` to add a parameter for exact precision:
```typescript
export function convertTokenAmountToUSD(
  amount: bigint,
  decimals: number,
  price: { amount: string; decimals: number },
  exactPrecision = false, // Added parameter for fee display
) {
  // Existing calculation logic...
  
  // For transaction fees, show exact precision
  if (exactPrecision) {
    // Show all significant digits for fee displays
    return "$" + valueInUsd.toString();
  }
  
  // Regular display formatting for other cases
  const formatted = valueInUsd.toFixed(2);
  // Rest of the existing function...
}
  1. Update the fee display component in packages/keychain/src/components/Fees.tsx to use exact precision:
if (maxFee && maxFee.overall_fee && token.price) {
  const formatted = convertTokenAmountToUSD(
    maxFee.overall_fee,
    18,
    token.price,
    true, // Enable exact precision for fees
  );
  setFormattedFee(formatted);
}
  1. The execution logic in packages/keychain/src/utils/controller.ts can remain unchanged since we're adapting the display to match the execution rather than vice versa.

This change will ensure that the fee amount displayed to users matches exactly what they'll be charged, eliminating confusion.

Once you've made these changes, please:

  1. Test the changes to ensure the displayed fees now show the exact amounts
  2. Create a PR with a brief description of the change and include the ticket ID "C7E-764" in the PR description

Thanks for your help!

@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@vercel
Copy link

vercel bot commented May 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
controller-example-next ✅ Ready (Inspect) Visit Preview May 15, 2025 10:57pm
keychain ✅ Ready (Inspect) Visit Preview May 15, 2025 10:57pm
keychain-storybook ✅ Ready (Inspect) Visit Preview May 15, 2025 10:57pm
profile ✅ Ready (Inspect) Visit Preview May 15, 2025 10:57pm

maxFee.overall_fee,
18,
token.price,
true, // Enable exact precision for fees
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to modify packages/keychain/src/components/starterpack/total-cost.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants