Swap: Redux actions; Redux Reducers
This commit is contained in:
parent
9144d2c666
commit
0304bc8a67
|
@ -0,0 +1,42 @@
|
|||
// @flow
|
||||
export const SWAP_ORIGIN_KIND = 'SWAP_ORIGIN_KIND';
|
||||
export const SWAP_DESTINATION_KIND = 'SWAP_DESTINATION_KIND';
|
||||
export const SWAP_ORIGIN_AMOUNT = 'SWAP_ORIGIN_AMOUNT';
|
||||
export const SWAP_DESTINATION_AMOUNT = 'SWAP_DESTINATION_AMOUNT';
|
||||
export const SWAP_UPDATE_BITY_RATES = 'SWAP_UPDATE_BITY_RATES';
|
||||
|
||||
|
||||
export const SWAP_ORIGIN_KIND_TO = (value: any) => {
|
||||
return {
|
||||
type: SWAP_ORIGIN_KIND,
|
||||
value
|
||||
};
|
||||
};
|
||||
|
||||
export const SWAP_DESTINATION_KIND_TO = (value: any) => {
|
||||
return {
|
||||
type: SWAP_DESTINATION_KIND,
|
||||
value
|
||||
}
|
||||
}
|
||||
|
||||
export const SWAP_ORIGIN_AMOUNT_TO = (value: any) => {
|
||||
return {
|
||||
type: SWAP_ORIGIN_AMOUNT,
|
||||
value
|
||||
};
|
||||
};
|
||||
|
||||
export const SWAP_DESTINATION_AMOUNT_TO = (value: any) => {
|
||||
return {
|
||||
type: SWAP_DESTINATION_AMOUNT,
|
||||
value
|
||||
}
|
||||
}
|
||||
|
||||
export const SWAP_UPDATE_BITY_RATES_TO = (value: any) => {
|
||||
return {
|
||||
type: SWAP_UPDATE_BITY_RATES,
|
||||
value
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
import * as generateWallet from './generateWallet'
|
||||
import * as config from './config'
|
||||
import * as swap from './swap'
|
||||
|
||||
import { reducer as formReducer } from 'redux-form'
|
||||
import {combineReducers} from 'redux';
|
||||
import {routerReducer} from 'react-router-redux'
|
||||
|
@ -7,6 +9,7 @@ import {routerReducer} from 'react-router-redux'
|
|||
export default combineReducers({
|
||||
...generateWallet,
|
||||
...config,
|
||||
...swap,
|
||||
form: formReducer,
|
||||
routing: routerReducer
|
||||
})
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
import {
|
||||
SWAP_DESTINATION_AMOUNT,
|
||||
SWAP_DESTINATION_KIND,
|
||||
SWAP_ORIGIN_AMOUNT,
|
||||
SWAP_ORIGIN_KIND,
|
||||
SWAP_UPDATE_BITY_RATES
|
||||
} from 'actions/swap';
|
||||
|
||||
import {without} from 'lodash';
|
||||
const ALL_CRYPTO_KIND_OPTIONS = ['BTC', 'ETH', 'REP'];
|
||||
|
||||
const initialState = {
|
||||
originAmount: 0,
|
||||
destinationAmount: 0,
|
||||
originKind: 'BTC',
|
||||
destinationKind: 'ETH',
|
||||
destinationKindOptions: without(ALL_CRYPTO_KIND_OPTIONS, 'BTC'),
|
||||
originKindOptions: without(ALL_CRYPTO_KIND_OPTIONS, 'REP'),
|
||||
bityRates: {}
|
||||
};
|
||||
|
||||
|
||||
export function swap(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case SWAP_ORIGIN_KIND: {
|
||||
return {
|
||||
...state,
|
||||
originKind: action.value,
|
||||
destinationKindOptions: without(ALL_CRYPTO_KIND_OPTIONS, action.value),
|
||||
destinationKind: without(ALL_CRYPTO_KIND_OPTIONS, action.value)[0]
|
||||
};
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue