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

fix: Add is programmatic only when on dev #776

Merged
merged 2 commits into from
Sep 26, 2024
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: 3 additions & 1 deletion spec/mocks/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export const collectionFragmentMock: CollectionFragment = {
createdAt: toUnixTimestamp(dbCollectionMock.created_at),
}

export const thirdPartyFragmentMock: ThirdPartyFragment = {
export const thirdPartyFragmentMock: ThirdPartyFragment & {
isProgrammatic: boolean
} = {
id: dbTPCollectionMock.third_party_id,
root: 'aRoot',
managers: [wallet.address],
Expand Down
5 changes: 4 additions & 1 deletion src/ThirdParty/ThirdParty.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { env } from 'decentraland-commons'
import { thirdPartyAPI } from '../ethereum/api/thirdParty'
import { ItemCuration } from '../Curation/ItemCuration'
import { ThirdParty, ThirdPartyMetadata } from './ThirdParty.types'
Expand Down Expand Up @@ -74,8 +75,10 @@ export class ThirdPartyService {
// All third parties methods

static async getThirdParties(manager?: string): Promise<ThirdParty[]> {
const includeProgrammatic = env.isDevelopment()

const [fragments, virtualThirdParties] = await Promise.all([
thirdPartyAPI.fetchThirdPartiesByManager(manager),
thirdPartyAPI.fetchThirdPartiesByManager(includeProgrammatic, manager),
manager
? this.getVirtualThirdPartiesByManager(manager)
: ([] as ThirdParty[]),
Expand Down
2 changes: 1 addition & 1 deletion src/ThirdParty/ThirdParty.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LinkedContract, ThirdPartyFragment } from '../ethereum/api/fragments'

export type ThirdParty = Omit<ThirdPartyFragment, 'metadata'> &
ThirdPartyMetadata & { published: boolean }
ThirdPartyMetadata & { published: boolean; isProgrammatic: boolean }

export type ThirdPartyMetadata = {
name: string
Expand Down
4 changes: 2 additions & 2 deletions src/ThirdParty/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { VirtualThirdPartyAttributes } from './VirtualThirdParty.types'

describe('when converting a third party fragment into a third party', () => {
describe('when a complete fragment is supplied', () => {
let fragment: ThirdPartyFragment
let fragment: ThirdPartyFragment & { isProgrammatic: boolean }

beforeEach(() => {
fragment = {
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('when converting a third party fragment into a third party', () => {
})

describe('when the third party metadata is null', () => {
let fragment: ThirdPartyFragment
let fragment: ThirdPartyFragment & { isProgrammatic: boolean }

beforeEach(() => {
fragment = {
Expand Down
24 changes: 22 additions & 2 deletions src/ethereum/api/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const collectionFragment = () => gql`
}
`

export const thirdPartyFragment = () => gql`
export const thirdPartyWithProgrammaticFragment = () => gql`
fragment thirdPartyFragment on ThirdParty {
id
root
Expand All @@ -70,6 +70,27 @@ export const thirdPartyFragment = () => gql`
}
`

export const thirdPartyFragment = () => gql`
fragment thirdPartyFragment on ThirdParty {
id
root
managers
maxItems
isApproved
metadata {
type
thirdParty {
name
description
contracts {
address
network
}
}
}
}
`

export const thirdPartyItemFragment = () => gql`
fragment thirdPartyItemFragment on Item {
urn
Expand Down Expand Up @@ -171,7 +192,6 @@ export type ThirdPartyFragment = {
id: string
root: string
isApproved: boolean
isProgrammatic: boolean
managers: string[]
maxItems: string
metadata: ThirdPartyMetadata
Expand Down
14 changes: 10 additions & 4 deletions src/ethereum/api/thirdParty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
thirdPartyItemFragment,
ReceiptFragment,
receiptsFragment,
thirdPartyWithProgrammaticFragment,
} from './fragments'
import {
BaseGraphAPI,
Expand All @@ -32,13 +33,17 @@ const getThirdPartyQuery = () => gql`
${thirdPartyFragment()}
`

const getThirdPartiesByManagerQuery = () => gql`
const getThirdPartiesByManagerQuery = (includeProgrammatic: boolean) => gql`
query getThirdPartiesByManager(${PAGINATION_VARIABLES}, $managers: [String!]) {
thirdParties(${PAGINATION_ARGUMENTS}, where: { managers_contains: $managers }) {
thirdParties(${PAGINATION_ARGUMENTS}, where: { managers_contains_nocase: $managers }) {
...thirdPartyFragment
}
}
${thirdPartyFragment()}
${
includeProgrammatic
? thirdPartyWithProgrammaticFragment()
: thirdPartyFragment()
}
`

const getThirdPartyMaxItems = () => gql`
Expand Down Expand Up @@ -92,10 +97,11 @@ export class ThirdPartyAPI extends BaseGraphAPI {
}

fetchThirdPartiesByManager = async (
includeProgrammatic: boolean,
manager?: string
): Promise<ThirdPartyFragment[]> => {
return this.paginate(['thirdParties'], {
query: getThirdPartiesByManagerQuery(),
query: getThirdPartiesByManagerQuery(includeProgrammatic),
variables: { managers: manager ? [manager.toLowerCase()] : [] },
})
}
Expand Down
Loading