Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The NGRX reducers
import { GET_ACCOUNTS_SUCCESS, SELECT_ACCOUNT, AccountsActions } from './eth.actions';
export interface State {
selected: string,
accounts: string[]
}
const initialState: State = {
selected: null,
accounts: []
}
export const reducers = (state = initialState, action: AccountsActions): State => {
switch (action.type) {
case (GET_ACCOUNTS_SUCCESS): {
return {...state, accounts: action.payload };
};
case (SELECT_ACCOUNT): {
return {...state, selected: action.payload };
};
default: {
return state;
}
}
}
/**
* Ethereum Global State
*/
export interface EthState {
eth: State
}
export const ethReducer: ActionReducerMap<EthState> = {
eth: reducers
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment