Skip to content

Commit

Permalink
feat(Exchange): typed exchange component actions and reducers
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLeoB committed Jan 18, 2020
1 parent 902c51f commit e5670e5
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 134 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as AT from './actionTypes'
import { ExchangeActionTypes } from './types'

export const setStep = step => ({
export const setStep = (step): ExchangeActionTypes => ({
type: AT.SET_STEP,
payload: { step }
})
Expand Down Expand Up @@ -36,18 +37,18 @@ export const swapBaseAndCounter = () => ({
export const updateLimits = () => ({
type: AT.UPDATE_LIMITS
})
export const fetchLimitsLoading = () => ({
export const fetchLimitsLoading = (): ExchangeActionTypes => ({
type: AT.FETCH_LIMITS_LOADING
})
export const fetchLimitsSuccess = limits => ({
export const fetchLimitsSuccess = (limits): ExchangeActionTypes => ({
type: AT.FETCH_LIMITS_SUCCESS,
payload: { limits }
})
export const fetchLimitsError = error => ({
export const fetchLimitsError = (error): ExchangeActionTypes => ({
type: AT.FETCH_LIMITS_ERROR,
payload: { error }
})
export const setMinMax = (min, max) => ({
export const setMinMax = (min, max): ExchangeActionTypes => ({
type: AT.SET_MIN_MAX,
payload: { min, max }
})
Expand All @@ -57,35 +58,21 @@ export const useMin = () => ({
export const useMax = () => ({
type: AT.USE_MAX
})
export const fetchTargetFees = () => ({
type: AT.FETCH_TARGET_FEES
})
export const fetchTargetFeesLoading = () => ({
type: AT.FETCH_TARGET_FEES_LOADING
})
export const fetchTargetFeesSuccess = fee => ({
type: AT.FETCH_TARGET_FEES_SUCCESS,
payload: { fee }
})
export const fetchTargetFeesError = error => ({
type: AT.FETCH_TARGET_FEES_ERROR,
payload: { error }
})
export const setSourceFee = fee => ({
type: AT.SET_SOURCE_FEE,
payload: { fee }
})
export const setShowError = showError => ({
export const setShowError = (showError): ExchangeActionTypes => ({
type: AT.SET_SHOW_ERROR,
payload: { showError }
})
export const recheckLatestTx = () => ({
type: AT.RECHECK_LATEST_TX
})
export const setTxError = error => ({
export const setTxError = (error): ExchangeActionTypes => ({
type: AT.SET_TX_ERROR,
payload: { error }
})
export const showConfirmation = () => ({
export const showConfirmation = (): ExchangeActionTypes => ({
type: AT.SHOW_CONFIRMATION
})

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import * as AT from 'data/components/exchange/actionTypes'
import { assoc, compose } from 'ramda'
import { ExchangeActionTypes, ExchangeState } from './types'
import Remote from 'blockchain-wallet-v4/src/remote/remote'

const INITIAL_STATE: ExchangeState = {
limits: Remote.NotAsked,
min: null,
max: null,
// @PHIL how to solve for default state for all these, 15-28
sourceFee: {
isSourceErc20: false,
mempoolFees: {
limits: {
max: 0,
min: 0
},
priority: 0,
regular: 0
},
source: 0,
sourceFiat: '',
target: 0
},
showError: false,
txError: null
}

export function exchangeReducer (
state = INITIAL_STATE,
action: ExchangeActionTypes
): ExchangeState {
switch (action.type) {
case AT.FETCH_LIMITS_LOADING: {
return {
...state,
limits: Remote.Loading
}
}
case AT.FETCH_LIMITS_SUCCESS: {
return {
...state,
limits: Remote.Success(action.payload.limits)
}
}
case AT.FETCH_LIMITS_ERROR: {
return {
...state,
limits: Remote.Failure(action.payload.error)
}
}
case AT.SET_MIN_MAX: {
return {
...state,
min: action.payload.min,
max: action.payload.max
}
}
case AT.SET_SOURCE_FEE: {
return {
...state,
sourceFee: action.payload.fee
}
}
case AT.SET_SHOW_ERROR: {
return {
...state,
showError: action.payload.showError
}
}
case AT.SET_TX_ERROR: {
return {
...state,
txError: action.payload.error
}
}
default:
return state
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,17 @@ import { String } from 'index'
// @PHIL limts are repetitive, should this be explicit for every one?

export type LimitsType = {
annual: AnnualType
balanceMax: BalanceMaxType
daily: DailyType
maxFiatLimit: MaxFiatLimitType
maxOrder: MaxOrderType
minOrder: MinOrderType
weekly: WeeklyType
annual: LimitDurationType,
balanceMax: BalanceMaxType,
daily: LimitDurationType,
maxFiatLimit: MaxFiatLimitType,
maxOrder: OrderType,
maxPossibleOrder: OrderType,
minOrder: OrderType,
weekly: LimitDurationType
}

export type MinOrderType = {
amount: string
fiat: boolean
symbol: string
}

export type MaxOrderType = {
amount: string
fiat: boolean
symbol: string
}

export type MaxPossibleOrderType = {
export type OrderType = {
amount: string
fiat: boolean
symbol: string
Expand All @@ -40,19 +29,7 @@ export type AmountType = {
used: string
}

export type DailyType = {
amount: AmountType
fiat: boolean
symbol: string
}

export type WeeklyType = {
amount: AmountType
fiat: boolean
symbol: string
}

export type AnnualType = {
export type LimitDurationType = {
amount: AmountType
fiat: boolean
symbol: string
Expand Down Expand Up @@ -80,9 +57,9 @@ export type SourceFeeType = {
priority: number
regular: number
}
source: string
source: number | string
sourceFiat: string
target: string
target: number | string
}

// State
Expand All @@ -91,8 +68,6 @@ export interface ExchangeState {
max: null | AmountType
min: null | AmountType
showError: boolean
// @PHIL not sure about this one
// targetFee: RemoteData<string, array>
sourceFee: SourceFeeType
txError: string | null
}
Expand All @@ -102,42 +77,24 @@ export interface ExchangeState {

interface FetchLimitsError {
payload: {
e: string
error: string
}
type: typeof AT.EXCHANGE.FETCH_LIMITS_ERROR
type: typeof AT.FETCH_LIMITS_ERROR
}

interface FetchLimitsLoading {
type: AT.EXCHANGE.FETCH_LIMITS_LOADING
type: typeof AT.FETCH_LIMITS_LOADING
}

interface FetchLimitsSuccess {
paylod: {
limits: Currencies<LimitsType>
}
type: typeof AT.EXCHANGE.FETCH_LIMITS_SUCCESS
}

interface FetchTargetFeesError {
payload: {
e: string
}
type: typeof AT.FETCH_TARGET_FEES_ERROR
}

interface FetchTargetFeesLoading {
type: typeof AT.FETCH_TARGET_FEES_LOADING
}
// @PHIL see above in state as well, target fee is an empty array in the wallet
interface FetchTargetFeesSuccess {
payload: {
fee: string
limits: Currencies<LimitsType>
}
type: typeof AT.FETCH_TARGET_FEES_SUCCESS
type: typeof AT.FETCH_LIMITS_SUCCESS
}

interface SetMinMax {
paylaod: {
payload: {
max: AmountType
min: AmountType
}
Expand All @@ -147,7 +104,7 @@ interface SetShowError {
payload: {
showError: boolean
}
type: typeof AT.EXCHANGE.SET_SHOW_ERROR
type: typeof AT.SET_SHOW_ERROR
}

interface SetSourceFee {
Expand All @@ -167,7 +124,7 @@ interface SetStep {

interface SetTxError {
payload: {
e: string
error: string
}
type: typeof AT.SET_TX_ERROR
}
Expand All @@ -176,13 +133,10 @@ interface ShowConfirmation {
type: typeof AT.SHOW_CONFIRMATION
}

export type ExchangeActionType =
export type ExchangeActionTypes =
| FetchLimitsError
| FetchLimitsLoading
| FetchLimitsSuccess
| FetchTargetFeesError
| FetchTargetFeesLoading
| FetchTargetFeesSuccess
| SetMinMax
| SetShowError
| SetSourceFee
Expand Down

0 comments on commit e5670e5

Please sign in to comment.