Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/fee-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@ export interface FeeBreakdown {
estimatedUsd?: number;
}

const XLM_PRICE = 0.12; // Average XLM price in USD for estimation

/**
* Calculate fee breakdown from transaction simulation
* @param minResourceFee Minimum resource fee from simulation in stroops
* @param xlmPrice Current XLM price in USD (optional)
* @param xlmPrice Current XLM/USD price. Pass the live value from useTokenPrice;
* omit (or pass undefined) when no price is available and USD
* estimate should be suppressed.
* @returns Fee breakdown: base estimate, safety buffer, and total
*/
export function calculateFeeBreakdown(
minResourceFee: number,
xlmPrice: number = XLM_PRICE,
xlmPrice?: number,
): FeeBreakdown {
// Apply 15% buffer to ensure inclusion
const bufferMultiplier = 1.15;
const totalFee = Math.ceil(minResourceFee * bufferMultiplier);
const bufferFee = totalFee - minResourceFee;

const totalXlm = totalFee / 1e7;
const estimatedUsd = totalXlm * xlmPrice;
const estimatedUsd =
xlmPrice !== undefined ? totalXlm * xlmPrice : undefined;

return {
minFee: minResourceFee,
Expand Down
Loading