• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

decentraland / marketplace / 7106317436

05 Dec 2023 08:40PM UTC coverage: 43.446% (+0.02%) from 43.428%
7106317436

Pull #2069

github

web-flow
Merge cb0a6e4ae into 84c8b4379
Pull Request #2069: feat: add notifications to marketplace

2670 of 7393 branches covered (0.0%)

Branch coverage included in aggregate %.

4681 of 9527 relevant lines covered (49.13%)

24.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

51.11
/webapp/src/modules/collection/sagas.ts
1
import { call, takeEvery, put, select } from '@redux-saga/core/effects'
2
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
3
import { isErrorWithMessage } from '../../lib/error'
4
import { fetchCollectionItemsRequest } from '../item/actions'
5
import { getItemsByContractAddress } from '../item/selectors'
6
import { collectionAPI } from '../vendor/decentraland'
7
import { CollectionResponse } from '../vendor/decentraland/collection/types'
8
import {
9
  fetchCollectionsFailure,
10
  FetchCollectionsRequestAction,
11
  fetchCollectionsSuccess,
12
  fetchSingleCollectionFailure,
13
  FetchSingleCollectionRequestAction,
14
  fetchSingleCollectionSuccess,
15
  FETCH_COLLECTIONS_REQUEST,
16
  FETCH_SINGLE_COLLECTION_REQUEST
17
} from './actions'
18

19
export function* collectionSaga() {
20
  yield takeEvery(FETCH_COLLECTIONS_REQUEST, handleFetchCollectionsRequest)
441✔
21
  yield takeEvery(
441✔
22
    FETCH_SINGLE_COLLECTION_REQUEST,
23
    handleFetchSingleCollectionRequest
24
  )
25
}
26

27
export function* handleFetchCollectionsRequest(
28
  action: FetchCollectionsRequestAction
29
) {
30
  const { filters, shouldFetchItems } = action.payload
3✔
31

32
  try {
3✔
33
    const { data: collections, total }: CollectionResponse = yield call(
3✔
34
      [collectionAPI, collectionAPI.fetch],
35
      filters
36
    )
37

38
    yield put(fetchCollectionsSuccess(collections, total))
2✔
39

40
    if (shouldFetchItems) {
2✔
41
      const itemsByContractAddress: ReturnType<typeof getItemsByContractAddress> = yield select(
1✔
42
        getItemsByContractAddress
43
      )
44

45
      for (let collection of collections) {
1✔
46
        const items = itemsByContractAddress[collection.contractAddress]
3✔
47

48
        if (!items || items.length !== collection.size) {
3✔
49
          yield put(
2✔
50
            fetchCollectionItemsRequest({
51
              first: collection.size,
52
              contractAddresses: [collection.contractAddress]
53
            })
54
          )
55
        }
56
      }
57
    }
58
  } catch (error) {
59
    yield put(
1✔
60
      fetchCollectionsFailure(
61
        isErrorWithMessage(error) ? error.message : t('global.unknown_error')
1!
62
      )
63
    )
64
  }
65
}
66

67
export function* handleFetchSingleCollectionRequest(
68
  action: FetchSingleCollectionRequestAction
69
) {
70
  const { contractAddress, shouldFetchItems } = action.payload
18✔
71

72
  try {
18✔
73
    const { data: collections }: CollectionResponse = yield call(
18✔
74
      [collectionAPI, collectionAPI.fetch],
75
      { contractAddress }
76
    )
77

78
    if (collections.length === 0) {
×
79
      yield put(
×
80
        fetchSingleCollectionFailure(
81
          `Could not get Collection "${contractAddress}"`
82
        )
83
      )
84
      return
×
85
    }
86

87
    const [collection] = collections
×
88

89
    if (shouldFetchItems) {
×
90
      const itemsByContractAddress: ReturnType<typeof getItemsByContractAddress> = yield select(
×
91
        getItemsByContractAddress
92
      )
93

94
      const items = itemsByContractAddress[collection.contractAddress]
×
95

96
      if (!items || items.length !== collection.size) {
×
97
        yield put(
×
98
          fetchCollectionItemsRequest({
99
            first: collection.size,
100
            contractAddresses: [collection.contractAddress]
101
          })
102
        )
103
      }
104
    }
105
    yield put(fetchSingleCollectionSuccess(collection))
×
106
  } catch (error) {
107
    yield put(
×
108
      fetchSingleCollectionFailure(
109
        isErrorWithMessage(error) ? error.message : t('global.unknown_error')
×
110
      )
111
    )
112
  }
113
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc