2017-06-06 17:19:12 -04:00
|
|
|
import * as types from "constants/action_types";
|
|
|
|
import lbryuri from "lbryuri";
|
2017-04-28 22:14:44 +07:00
|
|
|
|
2017-06-05 21:21:55 -07:00
|
|
|
const reducers = {};
|
|
|
|
const defaultState = {};
|
2017-04-28 22:14:44 +07:00
|
|
|
|
|
|
|
reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) {
|
2017-06-06 17:19:12 -04:00
|
|
|
const { uri, certificate, claim } = action.data;
|
2017-04-28 22:14:44 +07:00
|
|
|
|
2017-06-04 18:53:26 +07:00
|
|
|
const byUri = Object.assign({}, state.claimsByUri);
|
|
|
|
const byId = Object.assign({}, state.byId);
|
2017-05-12 18:50:51 -04:00
|
|
|
|
2017-06-04 18:53:26 +07:00
|
|
|
if (claim) {
|
|
|
|
byId[claim.claim_id] = claim;
|
|
|
|
byUri[uri] = claim.claim_id;
|
2017-06-06 11:44:23 +07:00
|
|
|
} else if (claim === undefined && certificate !== undefined) {
|
|
|
|
byId[certificate.claim_id] = certificate;
|
|
|
|
byUri[uri] = certificate.claim_id;
|
2017-06-05 15:48:06 +07:00
|
|
|
} else {
|
|
|
|
byUri[uri] = null;
|
2017-05-12 18:50:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-06-04 18:53:26 +07:00
|
|
|
byId,
|
2017-06-11 00:17:37 +07:00
|
|
|
claimsByUri: byUri,
|
2017-06-06 17:19:12 -04:00
|
|
|
});
|
2017-06-11 00:17:37 +07:00
|
|
|
};
|
2017-05-12 18:50:51 -04:00
|
|
|
|
2017-05-18 13:58:28 -04:00
|
|
|
reducers[types.RESOLVE_URI_CANCELED] = function(state, action) {
|
2017-06-06 17:19:12 -04:00
|
|
|
const uri = action.data.uri;
|
|
|
|
const newClaims = Object.assign({}, state.claimsByUri);
|
|
|
|
delete newClaims[uri];
|
2017-05-18 13:58:28 -04:00
|
|
|
return Object.assign({}, state, {
|
2017-06-06 17:19:12 -04:00
|
|
|
claimsByUri: newClaims,
|
|
|
|
});
|
2017-06-05 21:21:55 -07:00
|
|
|
};
|
2017-05-18 19:14:26 -04:00
|
|
|
|
2017-05-28 17:01:11 +04:00
|
|
|
reducers[types.FETCH_CLAIM_LIST_MINE_STARTED] = function(state, action) {
|
2017-05-18 19:14:26 -04:00
|
|
|
return Object.assign({}, state, {
|
2017-06-06 17:19:12 -04:00
|
|
|
isClaimListMinePending: true,
|
|
|
|
});
|
2017-06-05 21:21:55 -07:00
|
|
|
};
|
2017-05-18 19:14:26 -04:00
|
|
|
|
2017-05-28 17:01:11 +04:00
|
|
|
reducers[types.FETCH_CLAIM_LIST_MINE_COMPLETED] = function(state, action) {
|
2017-06-11 00:17:37 +07:00
|
|
|
const { claims } = action.data;
|
2017-06-06 17:19:12 -04:00
|
|
|
const myClaims = new Set(state.myClaims);
|
|
|
|
const byUri = Object.assign({}, state.claimsByUri);
|
2017-06-04 18:53:26 +07:00
|
|
|
const byId = Object.assign({}, state.byId);
|
2017-05-28 17:01:11 +04:00
|
|
|
|
|
|
|
claims.forEach(claim => {
|
2017-06-04 18:53:26 +07:00
|
|
|
myClaims.add(claim.claim_id);
|
|
|
|
byId[claim.claim_id] = claim;
|
2017-06-11 00:17:37 +07:00
|
|
|
});
|
2017-05-28 17:01:11 +04:00
|
|
|
|
2017-05-18 19:14:26 -04:00
|
|
|
return Object.assign({}, state, {
|
|
|
|
isClaimListMinePending: false,
|
2017-05-28 17:01:11 +04:00
|
|
|
myClaims: myClaims,
|
2017-06-04 18:53:26 +07:00
|
|
|
byId,
|
2017-06-06 17:19:12 -04:00
|
|
|
});
|
2017-06-11 00:17:37 +07:00
|
|
|
};
|
2017-05-18 19:14:26 -04:00
|
|
|
|
2017-05-21 10:42:34 -04:00
|
|
|
// reducers[types.FETCH_CHANNEL_CLAIMS_STARTED] = function(state, action) {
|
|
|
|
// const {
|
|
|
|
// uri,
|
|
|
|
// } = action.data
|
|
|
|
//
|
|
|
|
// const newClaims = Object.assign({}, state.claimsByChannel)
|
|
|
|
//
|
|
|
|
// if (claims !== undefined) {
|
|
|
|
// newClaims[uri] = claims
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return Object.assign({}, state, {
|
|
|
|
// claimsByChannel: newClaims
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
|
2017-05-12 18:50:51 -04:00
|
|
|
reducers[types.FETCH_CHANNEL_CLAIMS_COMPLETED] = function(state, action) {
|
2017-06-06 17:19:12 -04:00
|
|
|
const { uri, claims } = action.data;
|
2017-05-12 18:50:51 -04:00
|
|
|
|
2017-06-06 17:19:12 -04:00
|
|
|
const newClaims = Object.assign({}, state.claimsByChannel);
|
2017-05-12 18:50:51 -04:00
|
|
|
|
|
|
|
if (claims !== undefined) {
|
2017-06-06 17:19:12 -04:00
|
|
|
newClaims[uri] = claims;
|
2017-05-12 18:50:51 -04:00
|
|
|
}
|
|
|
|
|
2017-04-28 22:14:44 +07:00
|
|
|
return Object.assign({}, state, {
|
2017-06-06 17:19:12 -04:00
|
|
|
claimsByChannel: newClaims,
|
|
|
|
});
|
2017-06-05 21:21:55 -07:00
|
|
|
};
|
2017-04-28 22:14:44 +07:00
|
|
|
|
|
|
|
export default function reducer(state = defaultState, action) {
|
|
|
|
const handler = reducers[action.type];
|
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|