16 changed files with 293 additions and 36 deletions
@ -0,0 +1,52 @@ |
|||
import { callApis } from '../api' |
|||
// ------------------------------------
|
|||
// Constants
|
|||
// ------------------------------------
|
|||
export const GET_BALANCE = 'GET_BALANCE' |
|||
export const RECEIVE_BALANCE = 'RECEIVE_BALANCE' |
|||
|
|||
// ------------------------------------
|
|||
// Actions
|
|||
// ------------------------------------
|
|||
export function getBalance() { |
|||
return { |
|||
type: GET_BALANCE |
|||
} |
|||
} |
|||
|
|||
export function receiveBalance(data) { |
|||
return { |
|||
type: RECEIVE_BALANCE, |
|||
walletBalance: data[0].data.balance, |
|||
channelBalance: data[1].data.balance |
|||
} |
|||
} |
|||
|
|||
export const fetchBalance = () => async (dispatch) => { |
|||
dispatch(getBalance()) |
|||
const balance = await callApis(['wallet_balance', 'channel_balance']) |
|||
dispatch(receiveBalance(balance)) |
|||
} |
|||
|
|||
// ------------------------------------
|
|||
// Action Handlers
|
|||
// ------------------------------------
|
|||
const ACTION_HANDLERS = { |
|||
[GET_BALANCE]: (state) => ({ ...state, balanceLoading: true }), |
|||
[RECEIVE_BALANCE]: (state, { walletBalance, channelBalance }) => ({ ...state, balanceLoading: false, walletBalance, channelBalance }) |
|||
} |
|||
|
|||
// ------------------------------------
|
|||
// Reducer
|
|||
// ------------------------------------
|
|||
const initialState = { |
|||
balanceLoading: false, |
|||
walletBalance: null, |
|||
channelBalance: null |
|||
} |
|||
|
|||
export default function balanceReducer(state = initialState, action) { |
|||
const handler = ACTION_HANDLERS[action.type] |
|||
|
|||
return handler ? handler(state, action) : state |
|||
} |
@ -0,0 +1,50 @@ |
|||
import { callApi } from '../api' |
|||
// ------------------------------------
|
|||
// Constants
|
|||
// ------------------------------------
|
|||
export const GET_INFO = 'GET_INFO' |
|||
export const RECEIVE_INFO = 'RECEIVE_INFO' |
|||
|
|||
// ------------------------------------
|
|||
// Actions
|
|||
// ------------------------------------
|
|||
export function getInfo() { |
|||
return { |
|||
type: GET_INFO |
|||
} |
|||
} |
|||
|
|||
export function receiveInfo(data) { |
|||
return { |
|||
type: RECEIVE_INFO, |
|||
data |
|||
} |
|||
} |
|||
|
|||
export const fetchInfo = () => async (dispatch) => { |
|||
dispatch(getInfo()) |
|||
const info = await callApi('info') |
|||
dispatch(receiveInfo(info.data)) |
|||
} |
|||
|
|||
// ------------------------------------
|
|||
// Action Handlers
|
|||
// ------------------------------------
|
|||
const ACTION_HANDLERS = { |
|||
[GET_INFO]: (state) => ({ ...state, infoLoading: true }), |
|||
[RECEIVE_INFO]: (state, { data }) => ({ ...state, infoLoading: false, data }) |
|||
} |
|||
|
|||
// ------------------------------------
|
|||
// Reducer
|
|||
// ------------------------------------
|
|||
const initialState = { |
|||
infoLoading: false, |
|||
data: {} |
|||
} |
|||
|
|||
export default function infoReducer(state = initialState, action) { |
|||
const handler = ACTION_HANDLERS[action.type] |
|||
|
|||
return handler ? handler(state, action) : state |
|||
} |
@ -0,0 +1,54 @@ |
|||
import { requestTicker } from '../api' |
|||
// ------------------------------------
|
|||
// Constants
|
|||
// ------------------------------------
|
|||
export const GET_TICKER = 'GET_TICKER' |
|||
export const RECIEVE_TICKER = 'RECIEVE_TICKER' |
|||
|
|||
// ------------------------------------
|
|||
// Actions
|
|||
// ------------------------------------
|
|||
export function getTicker() { |
|||
return { |
|||
type: GET_TICKER |
|||
} |
|||
} |
|||
|
|||
export function recieveTicker(ticker) { |
|||
return { |
|||
type: RECIEVE_TICKER, |
|||
ticker |
|||
} |
|||
} |
|||
|
|||
export const fetchTicker = () => async (dispatch) => { |
|||
dispatch(getTicker()) |
|||
const ticker = await requestTicker() |
|||
dispatch(recieveTicker(ticker)) |
|||
|
|||
return ticker |
|||
} |
|||
|
|||
// ------------------------------------
|
|||
// Action Handlers
|
|||
// ------------------------------------
|
|||
const ACTION_HANDLERS = { |
|||
[GET_TICKER]: (state) => ({ ...state, tickerLoading: true }), |
|||
[RECIEVE_TICKER]: (state, { ticker }) => ({...state, btcTicker: ticker[0] }) |
|||
} |
|||
|
|||
// ------------------------------------
|
|||
// Reducer
|
|||
// ------------------------------------
|
|||
const initialState = { |
|||
tickerLoading: false, |
|||
current: 'btc', |
|||
crypto: 'btc', |
|||
btcTicker: null |
|||
} |
|||
|
|||
export default function tickerReducer(state = initialState, action) { |
|||
const handler = ACTION_HANDLERS[action.type] |
|||
|
|||
return handler ? handler(state, action) : state |
|||
} |
@ -1,8 +1,18 @@ |
|||
import { connect } from 'react-redux' |
|||
import App from '../components/App' |
|||
import { fetchTicker } from '../../../reducers/ticker' |
|||
import { fetchBalance } from '../../../reducers/balance' |
|||
import { fetchInfo } from '../../../reducers/info' |
|||
|
|||
const mapDispatchToProps = {} |
|||
const mapDispatchToProps = { |
|||
fetchTicker, |
|||
fetchBalance, |
|||
fetchInfo |
|||
} |
|||
|
|||
const mapStateToProps = (state) => ({}) |
|||
const mapStateToProps = (state) => ({ |
|||
ticker: state.ticker, |
|||
balance: state.balance |
|||
}) |
|||
|
|||
export default connect(mapStateToProps, mapDispatchToProps)(App) |
Loading…
Reference in new issue