2017-04-28 17:14:44 +02:00
|
|
|
import {
|
|
|
|
createSelector,
|
|
|
|
} from 'reselect'
|
2017-04-29 11:50:29 +02:00
|
|
|
import lbryuri from 'lbryuri'
|
2017-04-28 17:14:44 +02:00
|
|
|
import {
|
|
|
|
selectCurrentUri,
|
|
|
|
} from 'selectors/app'
|
|
|
|
|
|
|
|
export const _selectState = state => state.claims || {}
|
|
|
|
|
|
|
|
export const selectClaimsByUri = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.byUri || {}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectCurrentUriClaim = createSelector(
|
|
|
|
selectCurrentUri,
|
|
|
|
selectClaimsByUri,
|
2017-05-10 05:06:48 +02:00
|
|
|
(uri, byUri) => byUri[uri]
|
2017-04-28 17:14:44 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
export const selectCurrentUriClaimOutpoint = createSelector(
|
|
|
|
selectCurrentUriClaim,
|
2017-05-10 05:06:48 +02:00
|
|
|
(claim) => {
|
|
|
|
return claim ? `${claim.txid}:${claim.nout}` : null
|
|
|
|
}
|
2017-04-28 17:14:44 +02:00
|
|
|
)
|
2017-04-29 11:50:29 +02:00
|
|
|
|
|
|
|
const selectClaimForUri = (state, props) => {
|
|
|
|
const uri = lbryuri.normalize(props.uri)
|
|
|
|
return selectClaimsByUri(state)[uri]
|
|
|
|
}
|
|
|
|
|
|
|
|
export const makeSelectClaimForUri = () => {
|
|
|
|
return createSelector(
|
|
|
|
selectClaimForUri,
|
|
|
|
(claim) => claim
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const selectMetadataForUri = (state, props) => {
|
|
|
|
const claim = selectClaimForUri(state, props)
|
|
|
|
const metadata = claim && claim.value && claim.value.stream && claim.value.stream.metadata
|
|
|
|
|
|
|
|
return metadata ? metadata : undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
export const makeSelectMetadataForUri = () => {
|
|
|
|
return createSelector(
|
|
|
|
selectMetadataForUri,
|
|
|
|
(metadata) => metadata
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const selectSourceForUri = (state, props) => {
|
|
|
|
const claim = selectClaimForUri(state, props)
|
|
|
|
const source = claim && claim.value && claim.value.stream && claim.value.stream.source
|
|
|
|
|
|
|
|
return source ? source : undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
export const makeSelectSourceForUri = () => {
|
|
|
|
return createSelector(
|
|
|
|
selectSourceForUri,
|
|
|
|
(source) => source
|
|
|
|
)
|
|
|
|
}
|
2017-05-01 08:26:09 +02:00
|
|
|
|
|
|
|
export const selectMyClaims = createSelector(
|
|
|
|
_selectState,
|
|
|
|
(state) => state.mine || {}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectMyClaimsById = createSelector(
|
|
|
|
selectMyClaims,
|
|
|
|
(mine) => mine.byId || {}
|
|
|
|
)
|
|
|
|
|
|
|
|
export const selectMyClaimsOutpoints = createSelector(
|
|
|
|
selectMyClaimsById,
|
|
|
|
(byId) => {
|
|
|
|
const outpoints = []
|
|
|
|
Object.keys(byId).forEach(key => {
|
|
|
|
const claim = byId[key]
|
|
|
|
const outpoint = `${claim.txid}:${claim.nout}`
|
|
|
|
outpoints.push(outpoint)
|
|
|
|
})
|
|
|
|
|
|
|
|
return outpoints
|
|
|
|
}
|
|
|
|
)
|