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

decentraland / marketplace / 9604252205

20 Jun 2024 08:55PM UTC coverage: 66.593% (+0.09%) from 66.499%
9604252205

push

github

web-flow
fix location error (#2263)

2606 of 5072 branches covered (51.38%)

Branch coverage included in aggregate %.

30 of 40 new or added lines in 7 files covered. (75.0%)

1 existing line in 1 file now uncovered.

7606 of 10263 relevant lines covered (74.11%)

77.63 hits per line

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

71.43
/webapp/src/modules/nft/selectors.ts
1
import { createMatchSelector } from 'connected-react-router'
40✔
2
import { AnyAction } from 'redux'
3
import { createSelector } from 'reselect'
40✔
4
import { getAddress } from 'decentraland-dapps/dist/modules/wallet/selectors'
40✔
5
import { RootState } from '../reducer'
6
import { locations } from '../routing/locations'
40✔
7
import { View } from '../ui/types'
8
import { FETCH_NFTS_REQUEST, FetchNFTsRequestAction } from './actions'
40✔
9
import { NFTState } from './reducer'
10
import { NFT } from './types'
11
import { getNFT } from './utils'
40✔
12

13
export const getState = (state: RootState) => state.nft
44✔
14
export const getData = (state: RootState) => getState(state).data
126✔
15
export const getLoading = (state: RootState) => getState(state).loading
40✔
16
export const getError = (state: RootState) => getState(state).error
40✔
17

18
const nftDetailMatchSelector = createMatchSelector<
40✔
19
  RootState,
20
  {
21
    contractAddress: string
22
    tokenId: string
23
  }
24
>(locations.nft(':contractAddress', ':tokenId'))
25

26
const isFetchNftsRequestAction = (action: AnyAction): action is FetchNFTsRequestAction => action.type === FETCH_NFTS_REQUEST
40✔
27

28
export const isLoadingNftsByView = (state: RootState, view: View | undefined) =>
40✔
29
  getLoading(state).filter((action: AnyAction) => isFetchNftsRequestAction(action) && action.payload?.options?.view === view)
×
30

31
export const getContractAddress = createSelector<RootState, ReturnType<typeof nftDetailMatchSelector>, string | null>(
40✔
32
  nftDetailMatchSelector,
NEW
33
  match => match?.params.contractAddress.toLowerCase() || null
×
34
)
35

36
export const getTokenId = createSelector<RootState, ReturnType<typeof nftDetailMatchSelector>, string | null>(
40✔
37
  nftDetailMatchSelector,
NEW
38
  match => match?.params.tokenId || null
×
39
)
40

41
export const getCurrentNFT = createSelector<RootState, string | null, string | null, NFTState['data'], NFT | null>(
40✔
NEW
42
  state => getContractAddress(state),
×
NEW
43
  state => getTokenId(state),
×
UNCOV
44
  state => getData(state),
×
NEW
45
  (contractAddress, tokenId, nfts) => getNFT(contractAddress, tokenId, nfts)
×
46
)
47

48
export const getNFTsByOwner = createSelector<RootState, NFTState['data'], Record<string, NFT[]>>(
40✔
49
  state => getData(state),
1✔
50
  data => {
51
    const nftsByOwner: Record<string, NFT[]> = {}
1✔
52
    for (const id of Object.keys(data)) {
1✔
53
      const nft = data[id]
8✔
54
      const key = nft.owner.toLowerCase()
8✔
55
      if (!nftsByOwner[key]) {
8✔
56
        nftsByOwner[key] = []
1✔
57
      }
58
      nftsByOwner[key].push(nft)
8✔
59
    }
60
    return nftsByOwner
1✔
61
  }
62
)
63

64
export const getWalletNFTs = createSelector<RootState, Record<string, NFT[]>, string | undefined, NFT[]>(
40✔
65
  state => getNFTsByOwner(state),
1✔
66
  state => getAddress(state),
1✔
67
  (nftsByOwner, address) => {
68
    if (address && address.toLowerCase() in nftsByOwner) {
1✔
69
      return nftsByOwner[address.toLowerCase()]
1✔
70
    }
71
    return []
×
72
  }
73
)
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