Skip to content

Commit

Permalink
Merge pull request #231 from decentraland/fix/lands-recently-listed
Browse files Browse the repository at this point in the history
fix: sort the lands by recently listed correctly
  • Loading branch information
juanmahidalgo authored Dec 17, 2024
2 parents 14677d3 + 913a259 commit adc094d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/logic/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ export function fromMillisecondsToSeconds(timeInMilliseconds: number): number {
return Math.floor(timeInMilliseconds / 1000)
}

export function fromSecondsToMilliseconds(timeInSeconds: number): number {
return timeInSeconds * 1000
// it rounds the time to the nearest second since the trades are stored with a precision of milliseconds already
export function fromSecondsToMilliseconds(time: number): number {
if (time.toString().length <= 10) {
return Math.round(time * 1000)
}
return Math.round(time)
}
2 changes: 1 addition & 1 deletion src/ports/nfts/landQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getNFTsSortBy(sortBy?: NFTSortBy) {
case NFTSortBy.CHEAPEST:
return SQL` ORDER BY price ASC `
case NFTSortBy.RECENTLY_LISTED:
return SQL` ORDER BY created_at DESC NULLS LAST `
return SQL` ORDER BY order_created_at DESC NULLS LAST `
case NFTSortBy.RECENTLY_SOLD:
return SQL` ORDER BY sold_at DESC `
default:
Expand Down
7 changes: 4 additions & 3 deletions test/unit/orders-adapters.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ListingStatus, Network, NFTCategory, Order } from '@dcl/schemas'
import { fromDBOrderToOrder } from '../../src/adapters/orders'
import { fromSecondsToMilliseconds } from '../../src/logic/date'
import { DBOrder } from '../../src/ports/orders/types'
import { SquidNetwork } from '../../src/types'

Expand All @@ -14,7 +15,7 @@ describe('fromDBOrderToOrder', () => {
buyer: '0xdef',
price: '100',
status: ListingStatus.OPEN,
expires_at: Date.now() / 1000,
expires_at: Math.round(Date.now() / 1000),
created_at: Date.now() / 1000,
updated_at: Date.now() / 1000,
network: SquidNetwork.ETHEREUM,
Expand All @@ -36,8 +37,8 @@ describe('fromDBOrderToOrder', () => {
price: '100',
status: ListingStatus.OPEN,
expiresAt: dbOrder.expires_at,
createdAt: dbOrder.created_at * 1000,
updatedAt: dbOrder.updated_at * 1000,
createdAt: fromSecondsToMilliseconds(dbOrder.created_at),
updatedAt: fromSecondsToMilliseconds(dbOrder.updated_at),
network: Network.ETHEREUM,
chainId: 1,
issuedId: 'abc123',
Expand Down

0 comments on commit adc094d

Please sign in to comment.