Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions __tests__/lib/fee-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ describe("calculateBatchFees", () => {
expect(result.totalEstimated).toBeGreaterThan(0);
expect(result.minFee + result.bufferFee).toBe(result.totalEstimated);
});

it("omits estimatedUsd when xlmPrice is not provided", () => {
const result = calculateBatchFees(3, 40_000);
expect(result.estimatedUsd).toBeUndefined();
});

it("calculates estimatedUsd when xlmPrice is provided", () => {
const operationCount = 5;
const feePerOperation = 50_000;
const xlmPrice = 0.5;
const result = calculateBatchFees(operationCount, feePerOperation, xlmPrice);
const expectedTotal = Math.ceil(operationCount * feePerOperation * 1.15);
const expectedUsd = (expectedTotal / 1e7) * xlmPrice;
expect(result.estimatedUsd).toBeCloseTo(expectedUsd, 5);
});
});

describe("TYPICAL_FEES", () => {
Expand Down
3 changes: 2 additions & 1 deletion lib/fee-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export function formatFee(stroops: number, decimals: number = 7): string {
export function calculateBatchFees(
operationCount: number,
feePerOperation: number,
xlmPrice?: number,
): FeeBreakdown {
const totalFee = feePerOperation * operationCount;
return calculateFeeBreakdown(totalFee);
return calculateFeeBreakdown(totalFee, xlmPrice);
}
Loading