2017-06-11 20:00:28 -05:00
|
|
|
import {
|
|
|
|
SWAP_DESTINATION_AMOUNT,
|
|
|
|
SWAP_DESTINATION_KIND,
|
|
|
|
SWAP_ORIGIN_AMOUNT,
|
|
|
|
SWAP_ORIGIN_KIND,
|
|
|
|
SWAP_UPDATE_BITY_RATES
|
|
|
|
} from 'actions/swap';
|
|
|
|
|
2017-06-18 23:53:32 -05:00
|
|
|
export const ALL_CRYPTO_KIND_OPTIONS = ['BTC', 'ETH', 'REP'];
|
|
|
|
|
2017-06-11 20:00:28 -05:00
|
|
|
|
|
|
|
const initialState = {
|
|
|
|
originAmount: 0,
|
|
|
|
destinationAmount: 0,
|
|
|
|
originKind: 'BTC',
|
|
|
|
destinationKind: 'ETH',
|
2017-06-18 23:53:32 -05:00
|
|
|
destinationKindOptions: ALL_CRYPTO_KIND_OPTIONS.filter(element => element !== 'BTC'),
|
|
|
|
originKindOptions: ALL_CRYPTO_KIND_OPTIONS.filter(element => element !== 'REP'),
|
2017-06-11 20:00:28 -05:00
|
|
|
bityRates: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export function swap(state = initialState, action) {
|
|
|
|
switch (action.type) {
|
|
|
|
case SWAP_ORIGIN_KIND: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
originKind: action.value,
|
2017-06-18 23:53:32 -05:00
|
|
|
destinationKind: action.value === state.destinationKind ? ALL_CRYPTO_KIND_OPTIONS.filter(element => element !== action.value)[0] : state.destinationKind,
|
|
|
|
destinationKindOptions: ALL_CRYPTO_KIND_OPTIONS.filter(element => element !== action.value)
|
2017-06-11 20:00:28 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
case SWAP_DESTINATION_KIND: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
destinationKind: action.value
|
|
|
|
};
|
|
|
|
}
|
|
|
|
case SWAP_ORIGIN_AMOUNT:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
originAmount: action.value
|
|
|
|
};
|
|
|
|
case SWAP_DESTINATION_AMOUNT:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
destinationAmount: action.value
|
|
|
|
};
|
|
|
|
case SWAP_UPDATE_BITY_RATES:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
bityRates: {
|
|
|
|
...state.bityRates,
|
|
|
|
...action.value
|
|
|
|
}
|
|
|
|
};
|
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|