mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-10 02:55:41 +00:00
1aad9d1c21
* Convert Swap to consistent style * Generate wallet reducer cleanup. * Confirm empty action in swap reducer * Union types. Fix gen wallet collision * Fix not using all actions in reducer. Added reducer state for is fetching from bity. Added todo to make that a loader. * Readme instructions. * Remove common action constants. * Bring all actions and reducers inline with readme instructions. * Readme fixes * address comments
40 lines
921 B
JavaScript
40 lines
921 B
JavaScript
// @flow
|
|
import type {
|
|
CustomTokenAction,
|
|
AddCustomTokenAction,
|
|
RemoveCustomTokenAction
|
|
} from 'actions/customTokens';
|
|
import type { Token } from 'config/data';
|
|
|
|
export type State = Token[];
|
|
|
|
export const INITIAL_STATE: State = [];
|
|
|
|
function addCustomToken(state: State, action: AddCustomTokenAction): State {
|
|
if (state.find(token => token.symbol === action.payload.symbol)) {
|
|
return state;
|
|
}
|
|
return [...state, action.payload];
|
|
}
|
|
|
|
function removeCustomToken(
|
|
state: State,
|
|
action: RemoveCustomTokenAction
|
|
): State {
|
|
return state.filter(token => token.symbol !== action.payload);
|
|
}
|
|
|
|
export function customTokens(
|
|
state: State = INITIAL_STATE,
|
|
action: CustomTokenAction
|
|
): State {
|
|
switch (action.type) {
|
|
case 'CUSTOM_TOKEN_ADD':
|
|
return addCustomToken(state, action);
|
|
case 'CUSTOM_TOKEN_REMOVE':
|
|
return removeCustomToken(state, action);
|
|
default:
|
|
return state;
|
|
}
|
|
}
|