import * as swap from "../actions/start.action" ; import { BtcCoinModel } from "../models/coins/btc-coin.model" ; import { Coin } from "../models/coins/coin.model" ; import { EthCoinModel } from "../models/coins/eth-coin.model" ; import { SwapProcess } from "../models/swap-process.model" ; import { RepCoinModel } from "../models/coins/rep-coin.model" ; import { BatCoinModel } from "../models/coins/bat-coin.model" ; export interface State { swapProcess : SwapProcess ; link : string ; } export const initialState = { swapProcess : { depositCoin : new RepCoinModel ( ) , receiveCoin : new BatCoinModel ( ) , activeStep : 1 , } as SwapProcess , link : undefined , } ; export function reducer ( state = initialState , action ) { switch ( action . type ) { case swap . SWAP_DEPOSIT_RECEIVE_COINS : { const temp = state . swapProcess . depositCoin ; return { ... state , swapProcess : { ... state . swapProcess , depositCoin : state . swapProcess . receiveCoin . update ( temp ) , receiveCoin : temp , } , } ; } case swap . SET_DEPOSIT_COIN : { return { ... state , swapProcess : { ... state . swapProcess , depositCoin : action . payload , } , } ; } case swap . SET_RECEIVE_COIN : { return { ... state , swapProcess : { ... state . swapProcess , receiveCoin : action . payload , } , } ; } case swap . START_SWAP : { return { ... state , swapProcess : { ... state . swapProcess , depositCoin : action . payload . depositCoin , receiveCoin : action . payload . receiveCoin , activeStep : 2 , } , } ; } case swap . SET_ACTIVE_STEP : { return { ... state , swapProcess : { ... state . swapProcess , activeStep : action . payload , } , } ; } case swap . SET_DEPOSIT_AMOUNT : { const newState = { ... state , swapProcess : { ... state . swapProcess , depositCoin : state . swapProcess . depositCoin . update ( { amount : action . payload } as Coin ) , } , } ; return newState ; } case swap . SET_RECEIVE_AMOUNT : { const newState = { ... state , swapProcess : { ... state . swapProcess , receiveCoin : state . swapProcess . receiveCoin . update ( { amount : action . payload } as Coin ) , } , } ; return newState ; } default : { return state ; } } } export const getSwapProcess = ( state ) => state . swapProcess ; export const getDepositCoin = ( state ) => state . swapProcess . depositCoin ; export const getReceiveCoin = ( state ) => state . swapProcess . receiveCoin ; export const getLink = ( state ) => state . link ; export const getActiveStep = ( state ) => state . swapProcess . activeStep ;