Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: converted single contract address filter into multiple #137

Merged
merged 1 commit into from
Oct 5, 2022
Merged
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
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ type Item = {
- `emoteCategory`: Filter results by `EmoteCategory`. Possible values: `dance`, `stunt`, `greetings`, `fun`, `poses`, `reactions`, `horror`, `miscellaneous`.
- `emoteGender`: Filter results by `WearableGender`. It supports multiple values by adding the query param multiple times. Possible values: `male`, `female`.
- `emotePlayMode`: Filter results by `EmotePlayMode`. Possible values: `simple`, `loop`
- `contractAddress`: Filter results by contract address. Type: `address`.
- `contractAddress`: Filter results by contract address. It supports multiple values by adding the query param multiple times. Type: `address`.
- `itemId`: Filter results by `itemId`. Type: `string`.
- `network`: Filter results by `Network`. Possible values: `ETHEREUM`, `MATIC`.

Expand Down Expand Up @@ -459,5 +459,3 @@ type RankingItem = {
- `first`: Limit the number of results. Type: number.
- `rarity`: Filter the results by the rarity. Possible values: `unique`, `mythic`, `legendary`, `epic`, `rare`, `uncommon`, `common`.
- `category`: Filter the results by wearable category. Possible values: `eyebrows`,`eyes`,`facial_hair`,`hair`,`mouth`,`upper_body`,`lower_body`,`feet`,`earring`,`eyewear`,`hat`,`helmet`,`mask`,`tiara`,`top_head`, `skin`.

.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"printWidth": 80
},
"dependencies": {
"@dcl/schemas": "^5.20.0",
"@dcl/schemas": "^5.21.0",
"@types/sqlite3": "^3.1.7",
"@well-known-components/env-config-provider": "^1.1.1",
"@well-known-components/http-server": "^1.0.0",
Expand Down
9 changes: 6 additions & 3 deletions src/adapters/handlers/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ export function createItemsHandler(
'emoteGender',
WearableGender
)
const emotePlayMode = params.getValue<EmotePlayMode>('emotePlayMode', EmotePlayMode)
const contractAddress = params.getAddress('contractAddress')
const emotePlayMode = params.getValue<EmotePlayMode>(
'emotePlayMode',
EmotePlayMode
)
const contractAddresses = params.getList('contractAddress')
const itemId = params.getString('itemId')
const network = params.getValue<Network>('network', Network)

Expand All @@ -71,7 +74,7 @@ export function createItemsHandler(
emoteCategory,
emoteGenders,
emotePlayMode,
contractAddress,
contractAddresses,
itemId,
isWearableSmart,
network,
Expand Down
10 changes: 7 additions & 3 deletions src/ports/items/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function getItemsQuery(filters: ItemFilters, isCount = false) {
wearableGenders,
emoteCategory,
emoteGenders,
contractAddress,
contractAddresses,
itemId,
} = filters as ItemFilters

Expand Down Expand Up @@ -192,8 +192,12 @@ export function getItemsQuery(filters: ItemFilters, isCount = false) {
where.push(`searchText_contains: "${search.trim().toLowerCase()}"`)
}

if (contractAddress) {
where.push(`collection: "${contractAddress}"`)
if (contractAddresses) {
where.push(
`collection_in: [${contractAddresses
.map((contractAddress) => `"${contractAddress}"`)
.join(',')}]`
)
}

if (itemId) {
Expand Down
10 changes: 8 additions & 2 deletions src/ports/trendings/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function createTrendingsComponent(
Object.keys(trendingSales).map((key) => {
const [contractAddress, itemId] = key.split('-')
return itemsComponent.fetch({
contractAddress,
contractAddresses: [contractAddress],
itemId: itemId || undefined,
})
})
Expand Down Expand Up @@ -103,7 +103,13 @@ export function createTrendingsComponent(
[...Object.entries(trendingSales)].sort((a, b) => {
const itemA = findItemByItemId(items, a[0])
const itemB = findItemByItemId(items, b[0])
return !!itemA && !!itemB && new BN(itemB.price)
if (!itemA) {
return 1
}
if (!itemB) {
return -1
}
return new BN(itemB.price)
.mul(new BN(b[1]))
.gt(new BN(itemA.price).mul(new BN(a[1])))
? 1
Expand Down
4 changes: 2 additions & 2 deletions src/tests/ports/trendings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ test('trendings component', function ({ components }) {

jest
.spyOn(items, 'fetch')
.mockImplementation(({ contractAddress, itemId }) =>
Promise.resolve([getItem(contractAddress!, itemId!)])
.mockImplementation(({ contractAddresses, itemId }) =>
Promise.resolve([getItem(contractAddresses![0], itemId!)])
)
})

Expand Down