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

decentraland / marketplace / 6970244998

23 Nov 2023 01:18PM UTC coverage: 43.312% (+2.4%) from 40.865%
6970244998

Pull #2042

github

juanmahidalgo
feat: add missing select token and chain events
Pull Request #2042: feat: use squid to calculate route between two chains and tokens

2626 of 7307 branches covered (0.0%)

Branch coverage included in aggregate %.

277 of 382 new or added lines in 20 files covered. (72.51%)

1 existing line in 1 file now uncovered.

4634 of 9455 relevant lines covered (49.01%)

23.67 hits per line

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

95.38
/webapp/src/modules/item/actions.ts
1
import { ChainId, Item, ItemFilters } from '@dcl/schemas'
2
import { NFTPurchase } from 'decentraland-dapps/dist/modules/gateway/types'
3
import {
4
  buildTransactionWithFromPayload,
5
  buildTransactionWithReceiptPayload
6
} from 'decentraland-dapps/dist/modules/transaction/utils'
7
import { action } from 'typesafe-actions'
8
import { formatWeiMANA } from '../../lib/mana'
9
import { Route } from '../../lib/xchain'
10
import { getAssetName } from '../asset/utils'
11
import { ItemBrowseOptions } from './types'
12

13
// Fetch Items
14

15
export const FETCH_ITEMS_REQUEST = '[Request] Fetch Items'
42✔
16
export const FETCH_ITEMS_SUCCESS = '[Success] Fetch Items'
42✔
17
export const FETCH_ITEMS_FAILURE = '[Failure] Fetch Items'
42✔
18
export const FETCH_ITEMS_CANCELLED_ERROR_MESSAGE = '[Cancelled] Fetch Items'
42✔
19

20
export const fetchItemsRequest = (options: ItemBrowseOptions) =>
42✔
21
  action(FETCH_ITEMS_REQUEST, options)
26✔
22

23
export const fetchItemsSuccess = (
42✔
24
  items: Item[],
25
  total: number,
26
  options: ItemBrowseOptions,
27
  timestamp: number
28
) => action(FETCH_ITEMS_SUCCESS, { items, total, options, timestamp })
17✔
29

30
export const fetchItemsFailure = (error: string, options: ItemBrowseOptions) =>
42✔
31
  action(FETCH_ITEMS_FAILURE, { error, options })
9✔
32

33
export type FetchItemsRequestAction = ReturnType<typeof fetchItemsRequest>
34
export type FetchItemsSuccessAction = ReturnType<typeof fetchItemsSuccess>
35
export type FetchItemsFailureAction = ReturnType<typeof fetchItemsFailure>
36

37
// Fetch trending Items
38

39
export const FETCH_TRENDING_ITEMS_REQUEST = '[Request] Fetch Trending Items'
42✔
40
export const FETCH_TRENDING_ITEMS_SUCCESS = '[Success] Fetch Trending Items'
42✔
41
export const FETCH_TRENDING_ITEMS_FAILURE = '[Failure] Fetch Trending Items'
42✔
42

43
export const fetchTrendingItemsRequest = (size?: number) =>
42✔
44
  action(FETCH_TRENDING_ITEMS_REQUEST, { size })
10✔
45

46
export const fetchTrendingItemsSuccess = (items: Item[]) =>
42✔
47
  action(FETCH_TRENDING_ITEMS_SUCCESS, { items })
7✔
48

49
export const fetchTrendingItemsFailure = (error: string) =>
42✔
50
  action(FETCH_TRENDING_ITEMS_FAILURE, { error })
3✔
51

52
export type FetchTrendingItemsRequestAction = ReturnType<
53
  typeof fetchTrendingItemsRequest
54
>
55
export type FetchTrendingItemsSuccessAction = ReturnType<
56
  typeof fetchTrendingItemsSuccess
57
>
58
export type FetchTrendingItemsFailureAction = ReturnType<
59
  typeof fetchTrendingItemsFailure
60
>
61

62
// Fetch Collection Items
63

64
export const FETCH_COLLECTION_ITEMS_REQUEST = '[Request] Fetch Collection Items'
42✔
65
export const FETCH_COLLECTION_ITEMS_SUCCESS = '[Success] Fetch Collection Items'
42✔
66
export const FETCH_COLLECTION_ITEMS_FAILURE = '[Failure] Fetch Collection Items'
42✔
67

68
export const fetchCollectionItemsRequest = (
42✔
69
  options: Pick<ItemFilters, 'first' | 'contractAddresses'>
70
) => action(FETCH_COLLECTION_ITEMS_REQUEST, options)
11✔
71

72
export const fetchCollectionItemsSuccess = (items: Item[]) =>
42✔
73
  action(FETCH_COLLECTION_ITEMS_SUCCESS, { items })
4✔
74

75
export const fetchCollectionItemsFailure = (error: string) =>
42✔
76
  action(FETCH_COLLECTION_ITEMS_FAILURE, { error })
4✔
77

78
export type FetchCollectionItemsRequestAction = ReturnType<
79
  typeof fetchCollectionItemsRequest
80
>
81
export type FetchCollectionItemsSuccessAction = ReturnType<
82
  typeof fetchCollectionItemsSuccess
83
>
84
export type FetchCollectionItemsFailureAction = ReturnType<
85
  typeof fetchCollectionItemsFailure
86
>
87

88
// Buy Item
89
export const BUY_ITEM_REQUEST = '[Request] Buy item'
42✔
90
export const BUY_ITEM_SUCCESS = '[Success] Buy item'
42✔
91
export const BUY_ITEM_FAILURE = '[Failure] Buy item'
42✔
92

93
export const buyItemRequest = (item: Item) => action(BUY_ITEM_REQUEST, { item })
42✔
94

95
export const buyItemSuccess = (chainId: ChainId, txHash: string, item: Item) =>
42✔
96
  action(BUY_ITEM_SUCCESS, {
5✔
97
    item,
98
    txHash,
99
    ...buildTransactionWithReceiptPayload(chainId, txHash, {
100
      itemId: item.itemId,
101
      contractAddress: item.contractAddress,
102
      network: item.network,
103
      name: getAssetName(item),
104
      price: formatWeiMANA(item.price)
105
    })
106
  })
107

108
export const buyItemFailure = (error: string) =>
42✔
109
  action(BUY_ITEM_FAILURE, { error })
6✔
110

111
export type BuyItemRequestAction = ReturnType<typeof buyItemRequest>
112
export type BuyItemSuccessAction = ReturnType<typeof buyItemSuccess>
113
export type BuyItemFailureAction = ReturnType<typeof buyItemFailure>
114

115
// Buy Item Cross Chain
116
export const BUY_ITEM_CROSS_CHAIN_REQUEST = '[Request] Buy item cross-chain'
42✔
117
export const BUY_ITEM_CROSS_CHAIN_SUCCESS = '[Success] Buy item cross-chain'
42✔
118
export const BUY_ITEM_CROSS_CHAIN_FAILURE = '[Failure] Buy item cross-chain'
42✔
119

120
export const buyItemCrossChainRequest = (item: Item, route: Route) =>
42✔
NEW
121
  action(BUY_ITEM_CROSS_CHAIN_REQUEST, { item, route })
×
122

123
export const buyItemCrossChainSuccess = (
42✔
124
  route: Route,
125
  chainId: ChainId,
126
  txHash: string,
127
  item: Item
128
) =>
NEW
129
  action(BUY_ITEM_CROSS_CHAIN_SUCCESS, {
×
130
    route,
131
    item,
132
    txHash,
133
    ...buildTransactionWithReceiptPayload(chainId, txHash, {
134
      itemId: item.itemId,
135
      contractAddress: item.contractAddress,
136
      network: item.network,
137
      name: getAssetName(item),
138
      price: formatWeiMANA(item.price)
139
    })
140
  })
141

142
export const buyItemCrossChainFailure = (error: string) =>
42✔
NEW
143
  action(BUY_ITEM_CROSS_CHAIN_FAILURE, { error })
×
144

145
export type BuyItemCrossChainRequestAction = ReturnType<
146
  typeof buyItemCrossChainRequest
147
>
148
export type BuyItemCrossChainSuccessAction = ReturnType<
149
  typeof buyItemCrossChainSuccess
150
>
151
export type BuyItemCrossChainFailureAction = ReturnType<
152
  typeof buyItemCrossChainFailure
153
>
154

155
// Buy Item With Card
156
export const BUY_ITEM_WITH_CARD_REQUEST = '[Request] Buy Item with Card'
42✔
157
export const BUY_ITEM_WITH_CARD_SUCCESS = '[Success] Buy Item with Card'
42✔
158
export const BUY_ITEM_WITH_CARD_FAILURE = '[Failure] Buy Item with Card'
42✔
159

160
export const buyItemWithCardRequest = (item: Item) =>
42✔
161
  action(BUY_ITEM_WITH_CARD_REQUEST, { item })
7✔
162
export const buyItemWithCardSuccess = (
42✔
163
  chainId: ChainId,
164
  txHash: string,
165
  item: Item,
166
  purchase: NFTPurchase
167
) =>
168
  action(BUY_ITEM_WITH_CARD_SUCCESS, {
4✔
169
    item,
170
    purchase,
171
    ...buildTransactionWithFromPayload(chainId, txHash, purchase.address, {
172
      itemId: item.itemId,
173
      contractAddress: item.contractAddress,
174
      network: item.network,
175
      name: getAssetName(item),
176
      price: purchase.nft.cryptoAmount.toString()
177
    })
178
  })
179
export const buyItemWithCardFailure = (error: string) =>
42✔
180
  action(BUY_ITEM_WITH_CARD_FAILURE, { error })
13✔
181

182
export type BuyItemWithCardRequestAction = ReturnType<
183
  typeof buyItemWithCardRequest
184
>
185
export type BuyItemWithCardSuccessAction = ReturnType<
186
  typeof buyItemWithCardSuccess
187
>
188
export type BuyItemWithCardFailureAction = ReturnType<
189
  typeof buyItemWithCardFailure
190
>
191

192
// Fetch Item
193

194
export const FETCH_ITEM_REQUEST = '[Request] Fetch Item'
42✔
195
export const FETCH_ITEM_SUCCESS = '[Success] Fetch Item'
42✔
196
export const FETCH_ITEM_FAILURE = '[Failure] Fetch Item'
42✔
197

198
export const fetchItemRequest = (contractAddress: string, tokenId: string) =>
42✔
199
  action(FETCH_ITEM_REQUEST, { contractAddress, tokenId })
17✔
200
export const fetchItemSuccess = (item: Item) =>
42✔
201
  action(FETCH_ITEM_SUCCESS, { item })
8✔
202
export const fetchItemFailure = (
42✔
203
  contractAddress: string,
204
  tokenId: string,
205
  error: string
206
) => action(FETCH_ITEM_FAILURE, { contractAddress, tokenId, error })
3✔
207

208
export type FetchItemRequestAction = ReturnType<typeof fetchItemRequest>
209
export type FetchItemSuccessAction = ReturnType<typeof fetchItemSuccess>
210
export type FetchItemFailureAction = ReturnType<typeof fetchItemFailure>
211

212
export const CLEAR_ITEM_ERRORS = 'Clear Item Errors'
42✔
213
export const clearItemErrors = () => action(CLEAR_ITEM_ERRORS)
42✔
214
export type ClearItemErrorsAction = ReturnType<typeof clearItemErrors>
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