-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into #633-load-open-orders
Conflicts: src/modules/market/selectors/market.js src/selectors.js
- Loading branch information
Showing
43 changed files
with
664 additions
and
771 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
export const UPDATE_MARKETS_DATA = 'UPDATE_MARKETS_DATA'; | ||
export const UPDATE_MARKET_DATA = 'UPDATE_MARKET_DATA'; | ||
|
||
export function updateMarketsData(marketsData) { | ||
return { type: UPDATE_MARKETS_DATA, marketsData }; | ||
} | ||
|
||
export function updateMarketData(marketData) { | ||
return { type: UPDATE_MARKET_DATA, marketData }; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,62 @@ | ||
import { UPDATE_MARKETS_DATA, UPDATE_MARKET_DATA } from '../../markets/actions/update-markets-data'; | ||
import { UPDATE_MARKETS_DATA } from '../../markets/actions/update-markets-data'; | ||
|
||
import { CATEGORICAL } from '../../markets/constants/market-types'; | ||
import { CATEGORICAL_OUTCOMES_SEPARATOR } from '../../markets/constants/market-outcomes'; | ||
|
||
export default function (marketsData = {}, action) { | ||
switch (action.type) { | ||
case UPDATE_MARKETS_DATA: | ||
return { | ||
...marketsData, | ||
...action.marketsData | ||
}; | ||
|
||
case UPDATE_MARKET_DATA: | ||
return { | ||
...marketsData, | ||
[action.marketData.id]: { | ||
...marketsData[action.marketData.id], | ||
...action.marketData | ||
} | ||
...processMarketsData(action.marketsData, marketsData) | ||
}; | ||
|
||
default: | ||
return marketsData; | ||
} | ||
} | ||
|
||
function processMarketsData(newMarketsData, existingMarketsData) { | ||
|
||
// it's important to loop through the original marketIDs so that unloaded markets can still be marked as isLoadedMarketInfo and avoid infinite recursion later on | ||
return Object.keys(newMarketsData).reduce((p, marketID) => { | ||
const marketData = { | ||
...existingMarketsData[marketID], | ||
...newMarketsData[marketID] | ||
}; | ||
|
||
// clean description | ||
if (marketData.type === CATEGORICAL) { | ||
marketData.description = marketData.description.split(CATEGORICAL_OUTCOMES_SEPARATOR).slice(0, -1).join(); | ||
} | ||
|
||
// delete outcomes | ||
delete marketData.outcomes; | ||
|
||
// parse out event, currently we only support single event markets, no combinatorial | ||
parseEvent(marketData); | ||
|
||
// mark whether details have been loaded | ||
marketData.isLoadedMarketInfo = !!marketData.type; | ||
|
||
// save market (without outcomes) | ||
p[marketID] = marketData; | ||
|
||
return p; | ||
}, {}); | ||
|
||
function parseEvent(marketData) { | ||
if (!marketData.events || marketData.events.length !== 1) { | ||
delete marketData.events; | ||
return; | ||
} | ||
|
||
const event = marketData.events[0]; | ||
marketData.eventID = event.id; | ||
marketData.minValue = event.minValue; | ||
marketData.maxValue = event.maxValue; | ||
marketData.numOutcomes = event.numOutcomes; | ||
marketData.reportedOutcome = event.outcome; | ||
delete marketData.events; | ||
} | ||
} |
Oops, something went wrong.