Buy Transaction Fee Preview - Implementation Complete - #748
Open
Just-Bamford wants to merge 3 commits into
Open
Conversation
- Display gross cost, protocol fee, creator fee, and total before confirmation - Confirm button disabled until price preview loads successfully - Inline error handling with retry capability for failed fetches - Fee breakdown calculation utility with comprehensive tests - BuyFeeBreakdown component showing loading, error, and success states - Debounced price preview fetching (200ms) to optimize requests - TradeDialog updated to manage and pass preview data - 83+ tests covering components, utilities, and integration - Full TypeScript type safety and accessibility compliance Fixes: Users now see complete fee breakdown before purchase, improving transparency and trust in the buying process.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
We've successfully implemented a comprehensive fee preview system for buy transactions in the AccessLayer client. Users now see a detailed breakdown of all costs—gross cost, protocol fees, creator fees, and total—before confirming their purchase. This prevents surprises and improves transparency in the buying process.
Closes #744
Problem Statement
Previously, users submitting buy transactions had no visibility into how their payment was structured. They would see only an approximate total without understanding the fee components. This lack of transparency could lead to:
Solution Summary
We built a complete fee preview system that displays a detailed cost breakdown in the buy modal before the user confirms their transaction. The implementation includes:
Technical Implementation
1. Price Preview Utility (
src/utils/pricePreview.utils.ts)The core calculation engine that computes fee breakdowns:
What it does:
key_price × quantitygross_cost × protocol_fee_bps / 10000gross_cost × creator_fee_bps / 10000Key types:
FeeBreakdown: Object containing gross cost, individual fees, fee percentages, and totalPricePreviewRequest: Input parameters for price calculation2. Fee Breakdown Component (
src/components/common/BuyFeeBreakdown.tsx)A React component that displays the fee breakdown to users with three states:
Loading State:
aria-live="polite"Error State:
role="alert"Success State:
Conditional Rendering:
3. TradeDialog Integration (
src/components/common/TradeDialog.tsx)Enhanced the existing buy/sell modal with fee preview functionality:
State Management:
pricePreview: Stores the fetched fee breakdownpreviewLoading: Tracks loading statepreviewError: Stores any fetch errorsPrice Preview Fetching:
Confirm Button Logic:
onConfirmcallback for transaction trackingProps Added:
protocolFeeBps: Protocol fee rate (defaults toFEE_BOUNDS.DEFAULT_FEE_BPS)creatorFeeBps: Creator fee rate (defaults toFEE_BOUNDS.DEFAULT_FEE_BPS)onConfirm Callback Updated:
pricePreview?: FeeBreakdown | null4. LandingPage Integration (
src/pages/LandingPage.tsx)Connected the fee preview system to the main trading flow:
protocolFeeBps={250}(2.5%) to TradeDialogcreatorFeeBps={250}(2.5%) to TradeDialoghandleConfirmTradesignature to work with new preview systemUser Experience Flow
User Opens Buy Modal
User Enters Quantity
Preview Fetches (after 200ms debounce)
Preview Loads Successfully
If Preview Fails
User Confirms
Acceptance Criteria Met
✅ Gross cost, protocol fee, creator fee, and total displayed before confirmation
✅ Confirm button disabled until preview loads
pricePreviewis not null AND not loading AND no error✅ Failed preview fetch shows inline error with retry
✅ Transaction submitted using previewed cost figure
onConfirmcallback✅ Fee breakdown unit tests pass for mock preview response
Test Coverage
BuyFeeBreakdown Component Tests (13 tests)
Price Preview Utility Tests (14 tests)
TradeDialog Tests (56 existing + updated)
Integration Tests (3 tests)
Total: 83+ tests, all passing ✅
Code Quality
Files Created
src/utils/pricePreview.utils.ts- Price calculation enginesrc/components/common/BuyFeeBreakdown.tsx- Fee display componentsrc/components/common/__tests__/BuyFeeBreakdown.test.tsx- Component testssrc/utils/__tests__/pricePreview.utils.test.ts- Utility testssrc/components/common/__tests__/TradeDialog.feePreview.integration.test.tsx- Integration testsFiles Modified
src/components/common/TradeDialog.tsx- Added fee preview fetching and state managementsrc/pages/LandingPage.tsx- Integrated fee preview propssrc/components/common/__tests__/TradeDialog.sellPayoutDisplay.test.tsx- Updated test expectationssrc/components/common/__tests__/TradeDialog.focusOrder.test.tsx- Updated obsolete test casesDependencies
All implementation uses existing project dependencies:
No new npm packages added.
Future Improvements
While the current implementation meets all acceptance criteria, potential enhancements could include:
Conclusion
The fee preview system provides users with complete transparency into transaction costs before purchase. The implementation is production-ready, fully tested, accessible, and maintains backward compatibility with existing buy/sell flows. Users now see exactly what they're paying for, reducing confusion and building trust in the platform.