Skip to content

feat(lib): add price utilities and expand time utilities#2570

Open
AdekunleBamz wants to merge 1 commit intodecentraland:masterfrom
AdekunleBamz:feat/add-price-and-time-utilities
Open

feat(lib): add price utilities and expand time utilities#2570
AdekunleBamz wants to merge 1 commit intodecentraland:masterfrom
AdekunleBamz:feat/add-price-and-time-utilities

Conversation

@AdekunleBamz
Copy link

Summary

Add comprehensive utility modules for marketplace price and time operations with full test coverage.

New: webapp/src/lib/price.ts

A complete price utility library for working with MANA prices in wei format:

Function Description
formatPrice Format wei to human-readable price with currency symbol
formatPriceCompact Compact notation for large values (1.5M, 25K)
calculatePriceChange Calculate percentage change between prices
formatPriceChange Format change with +/- prefix and % suffix
isPriceInRange Check if price falls within min/max bounds
isValidPriceInput Validate user price input strings
etherToWei / weiToEther Conversion utilities
calculateTotalPrice Multiply unit price by quantity
comparePrices Compare two prices (-1, 0, 1)
getMinPrice / getMaxPrice Find extremes in price arrays
getAveragePrice Calculate average from price array

Enhanced: webapp/src/lib/time.ts

Expanded the existing time module with additional utilities:

Function Description
fromSecondsToMilliseconds Inverse of existing function
isExpired / isExpiredSeconds Expiration checks for both formats
getTimeRemaining Calculate remaining time until expiration
formatTimeRemaining Human-readable duration (e.g., "2d 5h", "45m")
DURATION Constants for SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
addDaysToTimestamp Date arithmetic helper
getStartOfDay / getEndOfDay Day boundary utilities
daysBetween Calculate days between timestamps
isWithinLastDays Recency checks
formatRelativeTime Relative time strings ("2 hours ago", "in 3 days")

Testing

  • price.spec.ts: 25+ test cases covering all price functions
  • time.spec.ts: 30+ test cases covering all time functions
  • Follows existing project test patterns using Jest

Use Cases

  • Price Display: Format prices consistently across the marketplace UI
  • Price Comparison: Compare listings, calculate savings, show price changes
  • Order Expiration: Display time remaining, check if orders are expired
  • Analytics: Calculate average prices, price ranges for collections
  • Filtering: Validate price inputs, check price bounds

Add comprehensive utility modules for marketplace price and time operations.

New: webapp/src/lib/price.ts
- formatPrice: Format wei to human-readable price with currency symbol
- formatPriceCompact: Compact notation for large values (1.5M, 25K)
- calculatePriceChange: Calculate percentage change between prices
- formatPriceChange: Format change with +/- prefix and % suffix
- isPriceInRange: Check if price falls within min/max bounds
- isValidPriceInput: Validate user price input strings
- etherToWei / weiToEther: Conversion utilities
- calculateTotalPrice: Multiply unit price by quantity
- comparePrices: Compare two prices (-1, 0, 1)
- getMinPrice / getMaxPrice: Find extremes in price arrays
- getAveragePrice: Calculate average from price array

Enhanced: webapp/src/lib/time.ts
- Added fromSecondsToMilliseconds (inverse of existing function)
- Added isExpired / isExpiredSeconds for expiration checks
- Added getTimeRemaining to calculate remaining time
- Added formatTimeRemaining for human-readable duration (e.g., '2d 5h')
- Added DURATION constants (SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR)
- Added addDaysToTimestamp for date arithmetic
- Added getStartOfDay / getEndOfDay for day boundaries
- Added daysBetween to calculate days between timestamps
- Added isWithinLastDays for recency checks
- Added formatRelativeTime for relative time strings

Both modules include comprehensive test coverage following project patterns.
@vercel
Copy link

vercel bot commented Jan 9, 2026

Someone is attempting to deploy a commit to the Decentraland Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant