2017-04-28 17:14:44 +02:00
|
|
|
import * as types from 'constants/action_types'
|
2017-04-29 11:50:29 +02:00
|
|
|
import lbryuri from 'lbryuri'
|
2017-04-28 17:14:44 +02:00
|
|
|
|
|
|
|
const reducers = {}
|
|
|
|
const defaultState = {
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) {
|
|
|
|
const {
|
|
|
|
uri,
|
2017-05-13 00:50:51 +02:00
|
|
|
certificate,
|
2017-04-28 17:14:44 +02:00
|
|
|
claim,
|
|
|
|
} = action.data
|
|
|
|
|
2017-05-13 00:50:51 +02:00
|
|
|
const newClaims = Object.assign({}, state.claimsByUri)
|
|
|
|
const newChannelClaims = Object.assign({}, state.channelClaimsByUri)
|
|
|
|
|
|
|
|
if (claim !== undefined) {
|
|
|
|
newClaims[uri] = claim
|
|
|
|
}
|
|
|
|
|
|
|
|
//This needs a sanity boost...
|
|
|
|
if (certificate !== undefined) {
|
|
|
|
newChannelClaims[uri] = certificate
|
|
|
|
if (claim === undefined) {
|
|
|
|
newClaims[uri] = certificate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
claimsByUri: newClaims,
|
|
|
|
channelClaimsByUri: newChannelClaims
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.FETCH_CHANNEL_CLAIMS_COMPLETED] = function(state, action) {
|
|
|
|
const {
|
|
|
|
uri,
|
|
|
|
claims
|
|
|
|
} = action.data
|
|
|
|
|
|
|
|
const newClaims = Object.assign({}, state.claimsByChannel)
|
|
|
|
|
|
|
|
if (claims !== undefined) {
|
|
|
|
newClaims[uri] = claims
|
|
|
|
}
|
|
|
|
|
2017-04-28 17:14:44 +02:00
|
|
|
return Object.assign({}, state, {
|
2017-05-13 00:50:51 +02:00
|
|
|
claimsByChannel: newClaims
|
2017-04-28 17:14:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-05-01 08:26:09 +02:00
|
|
|
reducers[types.FETCH_MY_CLAIMS_COMPLETED] = function(state, action) {
|
|
|
|
const {
|
|
|
|
claims,
|
|
|
|
} = action.data
|
|
|
|
const newMine = Object.assign({}, state.mine)
|
|
|
|
const newById = Object.assign({}, newMine.byId)
|
|
|
|
|
|
|
|
claims.forEach(claim => {
|
|
|
|
newById[claim.claim_id] = claim
|
|
|
|
})
|
|
|
|
newMine.byId = newById
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
mine: newMine,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-28 17:14:44 +02:00
|
|
|
export default function reducer(state = defaultState, action) {
|
|
|
|
const handler = reducers[action.type];
|
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|