2018-12-28 15:24:46 -08:00
|
|
|
import type, { AddressCollection } from './types';
|
|
|
|
import { ActionTypes } from './actions';
|
|
|
|
import { dedupeArray, removeItem } from '../util';
|
|
|
|
|
|
|
|
export interface StoreState {
|
2019-01-21 09:51:49 -08:00
|
|
|
startingBlockHeight: number | null;
|
2018-12-28 15:24:46 -08:00
|
|
|
watchAddresses: { [contributionId: number]: AddressCollection };
|
|
|
|
watchDisclosures: { [contributionId: number]: string };
|
|
|
|
}
|
|
|
|
|
|
|
|
const INITIAL_STATE: StoreState = {
|
2019-01-21 09:51:49 -08:00
|
|
|
startingBlockHeight: null,
|
2018-12-28 15:24:46 -08:00
|
|
|
watchAddresses: {},
|
|
|
|
watchDisclosures: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
export function reducer(state: StoreState = INITIAL_STATE, action: ActionTypes): StoreState {
|
|
|
|
switch(action.type) {
|
2019-01-21 09:51:49 -08:00
|
|
|
case type.SET_STARTING_BLOCK_HEIGHT:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
startingBlockHeight: action.payload,
|
|
|
|
};
|
|
|
|
|
2018-12-28 15:24:46 -08:00
|
|
|
case type.GENERATE_ADDRESSES:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
watchAddresses: {
|
|
|
|
...state.watchAddresses,
|
|
|
|
[action.payload.contributionId]: action.payload.addresses,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
case type.ADD_PAYMENT_DISCLOSURE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
watchDisclosures: {
|
|
|
|
...state.watchDisclosures,
|
|
|
|
[action.payload.contributionId]: action.payload.disclosure,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
case type.CONFIRM_PAYMENT_DISCLOSURE: {
|
|
|
|
const watchDisclosures = { ...state.watchDisclosures };
|
|
|
|
delete watchDisclosures[action.payload.contributionId];
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
watchDisclosures,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|