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

decentraland / marketplace / 7022713254

28 Nov 2023 06:06PM UTC coverage: 40.865%. Remained the same
7022713254

Pull #2061

github

web-flow
Merge f7103b09a into f9b03c5d7
Pull Request #2061: fix: basepath for subdomains

2271 of 6975 branches covered (0.0%)

Branch coverage included in aggregate %.

1 of 2 new or added lines in 1 file covered. (50.0%)

15 existing lines in 1 file now uncovered.

4298 of 9100 relevant lines covered (47.23%)

18.59 hits per line

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

25.0
/webapp/src/modules/store.ts
1
import { applyMiddleware, compose, createStore } from 'redux'
2
import createSagasMiddleware from 'redux-saga'
3
import { routerMiddleware } from 'connected-react-router'
4
import { createLogger } from 'redux-logger'
5
import { Env } from '@dcl/ui-env'
6
import { createStorageMiddleware } from 'decentraland-dapps/dist/modules/storage/middleware'
7
import { storageReducerWrapper } from 'decentraland-dapps/dist/modules/storage/reducer'
8
import { createTransactionMiddleware } from 'decentraland-dapps/dist/modules/transaction/middleware'
9
import { createAnalyticsMiddleware } from 'decentraland-dapps/dist/modules/analytics/middleware'
10
import { CLEAR_TRANSACTIONS } from 'decentraland-dapps/dist/modules/transaction/actions'
11

12
import { config } from '../config'
13
import { createRootReducer, RootState } from './reducer'
14
import { rootSaga } from './sagas'
15
import { fetchTilesRequest } from './tile/actions'
16
import { ARCHIVE_BID, UNARCHIVE_BID } from './bid/actions'
17
import { SET_IS_TRYING_ON } from './ui/preview/actions'
18
import { getCurrentIdentity } from './identity/selectors'
19
import { AuthIdentity } from 'decentraland-crypto-fetch'
20
import { createMemoryHistory, createBrowserHistory, History } from 'history'
21

22
export const createHistory = () =>
21✔
NEW
23
  createBrowserHistory({
×
24
    basename: /^decentraland.(zone|org|today)$/.test(window.location.host)
×
25
      ? '/marketplace'
26
      : undefined
27
  })
28

29
export function initStore(history: History) {
UNCOV
30
  const anyWindow = window as any
×
31

UNCOV
32
  const isDev = config.is(Env.DEVELOPMENT)
×
33

34
  const composeEnhancers =
UNCOV
35
    isDev && anyWindow.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
×
36
      ? anyWindow.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
37
          stateSanitizer: (state: RootState) => {
38
            const { tile, proximity, ...sanitized } = { ...state }
×
UNCOV
39
            return sanitized
×
40
          }
41
        })
42
      : compose
43

UNCOV
44
  const rootReducer = storageReducerWrapper(createRootReducer(history))
×
45

46
  const sagasMiddleware = createSagasMiddleware()
×
47
  const loggerMiddleware = createLogger({
×
48
    collapsed: () => true,
×
UNCOV
49
    predicate: (_: any, action) => isDev || action.type.includes('Failure')
×
50
  })
51
  const transactionMiddleware = createTransactionMiddleware()
×
UNCOV
52
  const { storageMiddleware, loadStorageMiddleware } = createStorageMiddleware({
×
53
    storageKey: 'marketplace-v2', // this is the key used to save the state in localStorage (required)
54
    paths: [
55
      ['ui', 'archivedBidIds'],
56
      ['ui', 'preview', 'isTryingOn']
57
    ], // array of paths from state to be persisted (optional)
58
    actions: [CLEAR_TRANSACTIONS, ARCHIVE_BID, UNARCHIVE_BID, SET_IS_TRYING_ON], // array of actions types that will trigger a SAVE (optional)
59
    migrations: {} // migration object that will migrate your localstorage (optional)
60
  })
UNCOV
61
  const analyticsMiddleware = createAnalyticsMiddleware(
×
62
    config.get('SEGMENT_API_KEY')!
63
  )
64

UNCOV
65
  const middleware = applyMiddleware(
×
66
    sagasMiddleware,
67
    routerMiddleware(history),
68
    loggerMiddleware,
69
    transactionMiddleware,
70
    storageMiddleware,
71
    analyticsMiddleware
72
  )
73
  const enhancer = composeEnhancers(middleware)
×
UNCOV
74
  const store = createStore(
×
75
    (rootReducer as unknown) as ReturnType<typeof createRootReducer>,
76
    enhancer
77
  )
78
  const getIdentity = () => {
×
UNCOV
79
    return (
×
80
      (getCurrentIdentity(store.getState()) as AuthIdentity | null) ?? undefined
×
81
    )
82
  }
83
  sagasMiddleware.run(rootSaga, getIdentity)
×
UNCOV
84
  loadStorageMiddleware(store)
×
85

86
  if (isDev) {
×
87
    const _window = window as any
×
UNCOV
88
    _window.getState = store.getState
×
89
  }
90

91
  // fetch tiles
UNCOV
92
  store.dispatch(fetchTilesRequest())
×
93

UNCOV
94
  return store
×
95
}
96

97
export function initTestStore(preloadedState = {}) {
×
98
  const testHistory = createMemoryHistory({ initialEntries: ['/marketplace'] })
172✔
99
  const rootReducer = storageReducerWrapper(createRootReducer(testHistory))
172✔
100
  const sagasMiddleware = createSagasMiddleware()
172✔
101
  const transactionMiddleware = createTransactionMiddleware()
172✔
102
  const { storageMiddleware, loadStorageMiddleware } = createStorageMiddleware({
172✔
103
    storageKey: 'marketplace-v2', // this is the key used to save the state in localStorage (required)
104
    paths: [
105
      ['ui', 'archivedBidIds'],
106
      ['ui', 'preview', 'isTryingOn']
107
    ], // array of paths from state to be persisted (optional)
108
    actions: [CLEAR_TRANSACTIONS, ARCHIVE_BID, UNARCHIVE_BID, SET_IS_TRYING_ON], // array of actions types that will trigger a SAVE (optional)
109
    migrations: {} // migration object that will migrate your localstorage (optional)
110
  })
111

112
  const middleware = applyMiddleware(
172✔
113
    sagasMiddleware,
114
    routerMiddleware(testHistory),
115
    transactionMiddleware,
116
    storageMiddleware
117
  )
118
  const enhancer = compose(middleware)
172✔
119
  const store = createStore(rootReducer, preloadedState, enhancer)
172✔
120
  sagasMiddleware.run(rootSaga, () => undefined)
172✔
121
  loadStorageMiddleware(store)
172✔
122
  store.dispatch(fetchTilesRequest())
172✔
123

124
  return store
172✔
125
}
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