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: add contract address to orders #36

Merged
merged 5 commits into from
Dec 6, 2021
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: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ type Item = {
type Order = {
id: string
nftId: string
marketplaceAddress: string
contractAddress: string
tokenId: string
owner: string
Expand All @@ -139,6 +140,7 @@ type Order = {
- `first`: Limit the number of results. Type: `number`.
- `skip`: Skip results. Type: `number`.
- `sortBy`: Sort results. Possible values: `recently_listed`, `recently_updated`, `cheapest`.
- `marketplaceAddress`: Filter results by marketplace contract address. It supports multiple values by adding the query param multiple times. Type: `address`.
- `owner`: Filter by owner. Type: `address`.
- `buyer`: Filter by buyer. Type: `address`.
- `contractAddress`: Filter results by contract address. It supports multiple values by adding the query param multiple times. Type: `address`.
Expand All @@ -155,6 +157,7 @@ type Order = {
```ts
type Bid = {
id: string
bidAddress: string
bidder: string
seller: string
price: string
Expand All @@ -177,6 +180,7 @@ type Bid = {
- `first`: Limit the number of results. Type: `number`.
- `skip`: Skip results. Type: `number`.
- `sortBy`: Sort results. Possible values: `recently_offered`, `recently_updated`, `most_expensive`.
- `bidAddress`: Filter results by bid contract address. It supports multiple values by adding the query param multiple times. Type: `address`.
- `bidder`: Filter by bidder. Type: `address`.
- `seller`: Filter by seller. Type: `address`.
- `contractAddress`: Filter results by contract address. It supports multiple values by adding the query param multiple times. Type: `address`.
Expand Down
19 changes: 7 additions & 12 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": "^2.2.0",
"@dcl/schemas": "^3.0.0",
"@types/sqlite3": "^3.1.7",
"@well-known-components/env-config-provider": "^1.0.0",
"@well-known-components/http-server": "^1.0.0",
Expand Down
2 changes: 2 additions & 0 deletions src/adapters/handlers/bids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function createBidsHandler(
const sortBy = params.getValue<BidSortBy>('sortBy', BidSortBy)
const bidder = params.getAddress('bidder')
const seller = params.getAddress('seller')
const bidAddress = params.getAddress('bidAddress')
const contractAddress = params.getAddress('contractAddress')
const tokenId = params.getString('tokenId')
const status = params.getValue<ListingStatus>('status', ListingStatus)
Expand All @@ -29,6 +30,7 @@ export function createBidsHandler(
sortBy,
bidder,
seller,
bidAddress,
contractAddress,
tokenId,
status,
Expand Down
2 changes: 2 additions & 0 deletions src/adapters/handlers/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function createOrdersHandler(
const sortBy = params.getValue<OrderSortBy>('sortBy', OrderSortBy)
const owner = params.getAddress('owner')
const buyer = params.getAddress('buyer')
const marketplaceAddress = params.getAddress('marketplaceAddress')
const contractAddress = params.getAddress('contractAddress')
const tokenId = params.getString('tokenId')
const status = params.getValue<ListingStatus>('status', ListingStatus)
Expand All @@ -28,6 +29,7 @@ export function createOrdersHandler(
sortBy,
owner,
buyer,
marketplaceAddress,
contractAddress,
tokenId,
status,
Expand Down
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,18 @@ async function initComponents(): Promise<AppComponents> {
chainId: marketplaceChainId,
})

const collectionsBids = createBidsComponent({
subgraph: collectionsSubgraph,
network: Network.MATIC,
chainId: collectionsChainId,
})


const bids = createMergerComponent<Bid, BidFilters, BidSortBy>({
sources: [createBidsSource(marketplaceBids)],
sources: [
createBidsSource(marketplaceBids),
createBidsSource(collectionsBids)
],
defaultSortBy: BID_DEFAULT_SORT_BY,
directions: {
[BidSortBy.RECENTLY_OFFERED]: SortDirection.DESC,
Expand Down
3 changes: 2 additions & 1 deletion src/ports/bids/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ export interface IBidsComponent {

export type BidFragment = {
id: string
bidAddress: string
bidder: string
seller: string
price: string
fingerprint: string
fingerprint?: string
status: ListingStatus
blockchainId: string
blockNumber: string
Expand Down
28 changes: 18 additions & 10 deletions src/ports/bids/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export function fromBidFragment(
): Bid {
const bid: Bid = {
id: fragment.id,
bidAddress: fragment.bidAddress,
bidder: fragment.bidder,
seller: fragment.seller,
price: fragment.price,
fingerprint: fragment.fingerprint,
fingerprint: fragment.fingerprint || '0x',
status: fragment.status,
blockchainId: fragment.blockchainId,
blockNumber: fragment.blockNumber,
Expand All @@ -36,14 +37,15 @@ export function fromBidFragment(
return bid
}

export const getBidFields = () => `
export const getBidFields = (withFingerprint: boolean) => `
fragment bidFields on Bid {
id
bidAddress
blockchainId
bidder
seller
price
fingerprint
${withFingerprint ? 'fingerprint' : ''}
status
blockNumber
expiresAt
Expand All @@ -52,31 +54,37 @@ export const getBidFields = () => `
}
`

export const getBidFragment = () => `
export const getBidFragment = (withFingerprint: boolean) => `
fragment bidFragment on Bid {
...bidFields
nft {
contractAddress
tokenId
}
}
${getBidFields()}
${getBidFields(withFingerprint)}
`

export function getBidsQuery(filters: BidFilters, isCount = false) {
const {
first,
skip,
sortBy,
bidAddress,
contractAddress,
tokenId,
bidder,
seller,
status,
network,
} = filters

const where: string[] = []

if (bidAddress) {
where.push(`bidAddress: "${bidAddress}""`)
}

if (contractAddress) {
where.push(`nftAddress: "${contractAddress}"`)
}
Expand Down Expand Up @@ -132,14 +140,14 @@ export function getBidsQuery(filters: BidFilters, isCount = false) {
return `
query Bids {
bids(
first: ${total},
orderBy: ${orderBy},
orderDirection: ${orderDirection},
first: ${total},
orderBy: ${orderBy},
orderDirection: ${orderDirection},
where: {
${where.join('\n')}
})
})
{ ${isCount ? 'id' : `...bidFragment`} }
}
${isCount ? '' : getBidFragment()}
${isCount ? '' : getBidFragment(network === Network.ETHEREUM)}
`
}
1 change: 1 addition & 0 deletions src/ports/orders/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface IOrdersComponent {

export type OrderFragment = {
id: string
marketplaceAddress: string
nftAddress: string
owner: string
buyer: string | null
Expand Down
23 changes: 15 additions & 8 deletions src/ports/orders/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const ORDER_DEFAULT_SORT_BY = OrderSortBy.RECENTLY_LISTED
export const getOrderFields = () => `
fragment orderFields on Order {
id
marketplaceAddress
nftAddress
owner
buyer
Expand All @@ -38,6 +39,7 @@ export const getOrdersQuery = (filters: OrderFilters, isCount = false) => {
first,
skip,
sortBy,
marketplaceAddress,
contractAddress,
tokenId,
buyer,
Expand All @@ -47,6 +49,10 @@ export const getOrdersQuery = (filters: OrderFilters, isCount = false) => {

const where: string[] = []

if (marketplaceAddress) {
where.push(`marketplaceAddress : "${marketplaceAddress}"`)
}

if (contractAddress) {
where.push(`nftAddress: "${contractAddress}"`)
}
Expand Down Expand Up @@ -74,10 +80,10 @@ export const getOrdersQuery = (filters: OrderFilters, isCount = false) => {
const total = isCount
? max
: typeof first !== 'undefined'
? typeof skip !== 'undefined'
? skip + first
: first
: max
? typeof skip !== 'undefined'
? skip + first
: first
: max

let orderBy: string
let orderDirection: string
Expand All @@ -102,12 +108,12 @@ export const getOrdersQuery = (filters: OrderFilters, isCount = false) => {
return `
query Orders {
orders(
first: ${total},
orderBy: ${orderBy},
orderDirection: ${orderDirection},
first: ${total},
orderBy: ${orderBy},
orderDirection: ${orderDirection},
where: {
${where.join('\n')}
})
})
{ ${isCount ? 'id' : `...orderFragment`} }
}
${isCount ? '' : getOrderFragment()}
Expand All @@ -121,6 +127,7 @@ export function fromOrderFragment(
): Order {
const order: Order = {
id: fragment.id,
marketplaceAddress: fragment.marketplaceAddress,
contractAddress: fragment.nftAddress,
tokenId: fragment.nft.tokenId,
owner: fragment.owner,
Expand Down