2017-06-26 22:27:55 +00:00
|
|
|
// @flow
|
|
|
|
import type { EnsAction, CacheEnsAddressAction } from 'actions/ens';
|
|
|
|
|
|
|
|
export type State = { [string]: string };
|
|
|
|
|
2017-07-27 17:05:09 +00:00
|
|
|
export const INITIAL_STATE: State = {};
|
2017-06-26 22:27:55 +00:00
|
|
|
|
|
|
|
function cacheEnsAddress(state: State, action: CacheEnsAddressAction): State {
|
2017-07-02 05:49:06 +00:00
|
|
|
const { ensName, address } = action.payload;
|
|
|
|
return { ...state, [ensName]: address };
|
2017-06-26 22:27:55 +00:00
|
|
|
}
|
|
|
|
|
2017-07-27 17:05:09 +00:00
|
|
|
export function ens(state: State = INITIAL_STATE, action: EnsAction): State {
|
2017-07-02 05:49:06 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case 'ENS_CACHE':
|
|
|
|
return cacheEnsAddress(state, action);
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2017-06-26 22:27:55 +00:00
|
|
|
}
|