created actions/claims, removed file_actions reducer and selector and moved corresponding methods to claims

This commit is contained in:
Akinwale Ariwodola 2017-07-30 16:14:30 +01:00
parent b7058b5f2e
commit 25b510daba
7 changed files with 71 additions and 90 deletions

View file

@ -1,9 +1,6 @@
import * as types from "constants/action_types";
import lbry from "lbry";
import {
selectClaimSupport,
selectClaimSupportAmount,
} from "selectors/file_actions";
import { selectClaimSupport, selectClaimSupportAmount } from "selectors/claims";
import { selectBalance } from "selectors/wallet";
import { doOpenModal } from "actions/app";

View file

@ -21,8 +21,8 @@ import {
doClaimNewSupport,
doSetClaimSupportAmount,
doSetClaimSupportClaim,
} from "actions/file_actions";
import { selectClaimSupportAmount } from "selectors/file_actions";
} from "actions/claims";
import { selectClaimSupportAmount } from "selectors/claims";
const makeSelect = () => {
const selectClaim = makeSelectClaimForUri();

View file

@ -2,7 +2,14 @@ import * as types from "constants/action_types";
import lbryuri from "lbryuri";
const reducers = {};
const defaultState = {};
const buildClaimSupport = () => ({
name: undefined,
amount: undefined,
claim_id: undefined,
});
const defaultState = {
claimSupport: buildClaimSupport(),
};
reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) {
const { uri, certificate, claim } = action.data;
@ -190,6 +197,56 @@ reducers[types.CREATE_CHANNEL_COMPLETED] = function(state, action) {
});
};
reducers[types.SET_CLAIM_SUPPORT_CLAIM] = function(state, action) {
const oldClaimSupport = state.claimSupport;
const newClaimSupport = Object.assign({}, oldClaimSupport, {
claim_id: action.data.claim_id,
name: action.data.name,
});
return Object.assign({}, state, {
claimSupport: newClaimSupport,
});
};
reducers[types.SET_CLAIM_SUPPORT_AMOUNT] = function(state, action) {
const oldClaimSupport = state.claimSupport;
const newClaimSupport = Object.assign({}, oldClaimSupport, {
amount: parseFloat(action.data.amount),
});
return Object.assign({}, state, {
claimSupport: newClaimSupport,
});
};
reducers[types.CLAIM_SUPPORT_STARTED] = function(state, action) {
const newClaimSupport = Object.assign({}, state.claimSupport, {
sending: true,
});
return Object.assign({}, state, {
claimSupport: newClaimSupport,
});
};
reducers[types.CLAIM_SUPPORT_COMPLETED] = function(state, action) {
return Object.assign({}, state, {
draftTransaction: buildClaimSupport(),
});
};
reducers[types.CLAIM_SUPPORT_FAILED] = function(state, action) {
const newClaimSupport = Object.assign({}, state.claimSupport, {
sending: false,
error: action.data.error,
});
return Object.assign({}, state, {
claimSupport: newClaimSupport,
});
};
export default function reducer(state = defaultState, action) {
const handler = reducers[action.type];
if (handler) return handler(state, action);

View file

@ -1,68 +0,0 @@
import * as types from "constants/action_types";
const reducers = {};
const buildClaimSupport = () => ({
name: undefined,
amount: undefined,
claim_id: undefined,
});
const defaultState = {
claimSupport: buildClaimSupport(),
};
reducers[types.SET_CLAIM_SUPPORT_CLAIM] = function(state, action) {
const oldClaimSupport = state.claimSupport;
const newClaimSupport = Object.assign({}, oldClaimSupport, {
claim_id: action.data.claim_id,
name: action.data.name,
});
return Object.assign({}, state, {
claimSupport: newClaimSupport,
});
};
reducers[types.SET_CLAIM_SUPPORT_AMOUNT] = function(state, action) {
const oldClaimSupport = state.claimSupport;
const newClaimSupport = Object.assign({}, oldClaimSupport, {
amount: parseFloat(action.data.amount),
});
return Object.assign({}, state, {
claimSupport: newClaimSupport,
});
};
reducers[types.CLAIM_SUPPORT_STARTED] = function(state, action) {
const newClaimSupport = Object.assign({}, state.claimSupport, {
sending: true,
});
return Object.assign({}, state, {
claimSupport: newClaimSupport,
});
};
reducers[types.CLAIM_SUPPORT_COMPLETED] = function(state, action) {
return Object.assign({}, state, {
draftTransaction: buildClaimSupport(),
});
};
reducers[types.CLAIM_SUPPORT_FAILED] = function(state, action) {
const newClaimSupport = Object.assign({}, state.claimSupport, {
sending: false,
error: action.data.error,
});
return Object.assign({}, state, {
claimSupport: newClaimSupport,
});
};
export default function reducer(state = defaultState, action) {
const handler = reducers[action.type];
if (handler) return handler(state, action);
return state;
}

View file

@ -215,3 +215,13 @@ export const selectMyChannelClaims = createSelector(
return claims;
}
);
export const selectClaimSupport = createSelector(
_selectState,
state => state.claimSupport || {}
);
export const selectClaimSupportAmount = createSelector(
selectClaimSupport,
claimSupport => claimSupport.amount
);

View file

@ -1,13 +0,0 @@
import { createSelector } from "reselect";
export const _selectState = state => state.fileActions || {};
export const selectClaimSupport = createSelector(
_selectState,
state => state.claimSupport || {}
);
export const selectClaimSupportAmount = createSelector(
selectClaimSupport,
claimSupport => claimSupport.amount
);

View file

@ -10,7 +10,6 @@ import searchReducer from "reducers/search";
import settingsReducer from "reducers/settings";
import userReducer from "reducers/user";
import walletReducer from "reducers/wallet";
import fileActionsReducer from "reducers/file_actions";
import { persistStore, autoRehydrate } from "redux-persist";
import createCompressor from "redux-persist-transform-compress";
import createFilter from "redux-persist-transform-filter";
@ -66,7 +65,6 @@ const reducers = redux.combineReducers({
settings: settingsReducer,
wallet: walletReducer,
user: userReducer,
fileActions: fileActionsReducer,
});
const bulkThunk = createBulkThunkMiddleware();