This repository has been archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added the balances section - Added more information to Ticker - SCSS changes for the ticker - Made some information in Ticker to be optional. - Added some tests (but only some) - Changed the way utils.js was done - Removed 'api' folder and moved its logic to utils.js - Better API error handling - And probably more that I don't remember now 😛
- Loading branch information
1 parent
eb36ee7
commit dc776f7
Showing
25 changed files
with
463 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import axios from 'axios' | ||
import { | ||
BALANCES_GET, | ||
BALANCES_GET_SUCCESS, | ||
BALANCES_GET_ERROR, | ||
} from '../constants/actionTypes' | ||
import { uri, parseResponse } from '../utils' | ||
|
||
export const balancesGet = () => ({ | ||
type: BALANCES_GET, | ||
}) | ||
|
||
export const balancesGetSuccess = (balances) => ({ | ||
type: BALANCES_GET_SUCCESS, | ||
balances, | ||
}) | ||
|
||
export const balancesGetError = (error) => ({ | ||
typep: BALANCES_GET_ERROR, | ||
error, | ||
}) | ||
|
||
export const get = () => (dispatch) => { | ||
dispatch(balancesGet()) | ||
|
||
return axios.get(uri('balances')) | ||
.then(parseResponse) | ||
.then((balances) => dispatch(balancesGetSuccess(balances))) | ||
.catch((error) => dispatch(balancesGetError(error))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import configureMockStore from 'redux-mock-store' | ||
import axiosCore from 'axios' | ||
import MockAdapter from 'axios-mock-adapter' | ||
import thunk from 'redux-thunk' | ||
|
||
import { | ||
BALANCES_GET, | ||
BALANCES_GET_SUCCESS, | ||
} from '../constants/actionTypes' | ||
import * as actions from './balances' | ||
|
||
const axios = new MockAdapter(axiosCore) | ||
|
||
const middlewares = [thunk] | ||
const mockStore = configureMockStore(middlewares) | ||
|
||
const defaultState = { | ||
all: {}, | ||
ids: [], | ||
error: false, | ||
} | ||
|
||
const balances = [ | ||
{ | ||
Currency: 'ADA', | ||
Balance: 0, | ||
Available: 0, | ||
Pending: 0, | ||
CryptoAddress: null, | ||
}, | ||
{ | ||
Currency: 'BAT', | ||
Balance: 200, | ||
Available: 0, | ||
Pending: 0, | ||
CryptoAddress: null, | ||
}, | ||
] | ||
|
||
describe('actions::balances', () => { | ||
it('get() fires BALANCES_GET && BALANCES_GET_SUCCESS', () => { | ||
axios.onGet(/balances$/).reply(200, balances) | ||
const expectedActions = [ | ||
{ | ||
type: BALANCES_GET, | ||
}, | ||
{ | ||
type: BALANCES_GET_SUCCESS, | ||
balances, | ||
}, | ||
] | ||
|
||
const store = mockStore({ balances: defaultState }) | ||
|
||
return store.dispatch(actions.get()).then(() => | ||
expect(store.getActions()).toEqual(expectedActions) | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,39 @@ | ||
import axios from 'axios' | ||
import { | ||
MARKETS_GET, | ||
MARKETS_GET_SUCCESS, | ||
MARKETS_GET_ERROR, | ||
MARKETS_FILTER, | ||
MARKETS_GET, | ||
MARKETS_GET_SUCCESS, | ||
MARKETS_GET_ERROR, | ||
MARKETS_FILTER, | ||
} from '../constants/actionTypes' | ||
import { uri, parseResponse } from '../utils' | ||
|
||
import { | ||
get as getMarkets, | ||
} from '../api/markets' | ||
const marketsGet = () => ({ | ||
type: MARKETS_GET, | ||
}) | ||
|
||
const marketsGetSuccess = (markets) => ({ | ||
type: MARKETS_GET_SUCCESS, | ||
markets, | ||
}) | ||
|
||
const marketsGetError = (error) => ({ | ||
type: MARKETS_GET_ERROR, | ||
error, | ||
}) | ||
|
||
const marketsFilter = (keyword) => ({ | ||
type: MARKETS_FILTER, | ||
keyword, | ||
}) | ||
|
||
export const get = () => (dispatch) => { | ||
dispatch({ type: MARKETS_GET }) | ||
dispatch(marketsGet()) | ||
|
||
return getMarkets() | ||
.then((data) => dispatch({ type: MARKETS_GET_SUCCESS, data })) | ||
.catch((error) => dispatch({ type: MARKETS_GET_ERROR, error })) | ||
return axios.get(uri('markets')) | ||
.then(parseResponse) | ||
.then((markets) => dispatch(marketsGetSuccess(markets))) | ||
.catch((error) => dispatch(marketsGetError(error))) | ||
} | ||
|
||
export const filter = (keyword) => (dispatch) => | ||
dispatch({ type: MARKETS_FILTER, keyword }) | ||
dispatch(marketsFilter(keyword)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import configureMockStore from 'redux-mock-store' | ||
import axiosCore from 'axios' | ||
import MockAdapter from 'axios-mock-adapter' | ||
import thunk from 'redux-thunk' | ||
|
||
import { | ||
MARKETS_GET, | ||
MARKETS_GET_SUCCESS, | ||
} from '../constants/actionTypes' | ||
import * as actions from './markets' | ||
|
||
const axios = new MockAdapter(axiosCore) | ||
|
||
const middlewares = [thunk] | ||
const mockStore = configureMockStore(middlewares) | ||
|
||
const defaultState = { | ||
all: {}, | ||
ids: [], | ||
visible: {}, | ||
error: false, | ||
} | ||
|
||
const markets = [ | ||
{ | ||
name: 'StartCoin', | ||
base: 'BTC', | ||
key: 'BTC-START', | ||
ticker: 'START', | ||
logo: 'https://bittrexblobstorage.blob.core.windows.net/public/2b596cad-231b-4252-8b50-0a5895a8a6b4.png', | ||
id: '5a26e508597a4609068baee2', | ||
active: true, | ||
}, | ||
{ | ||
name: 'Monero', | ||
base: 'BTC', | ||
key: 'BTC-XMR', | ||
ticker: 'XMR', | ||
logo: 'https://bittrexblobstorage.blob.core.windows.net/public/efcda24e-c6c3-4029-982c-15af2915fb08.png', | ||
id: '5a26e508597a4609068baee0', | ||
active: true, | ||
}, | ||
] | ||
|
||
describe('actions::markets', () => { | ||
it('get() fires MARKETS_GET && MARKETS_GET_SUCCESS', () => { | ||
axios.onGet(/markets$/).reply(200, markets) | ||
const expectedActions = [ | ||
{ | ||
type: MARKETS_GET, | ||
}, | ||
{ | ||
type: MARKETS_GET_SUCCESS, | ||
markets, | ||
}, | ||
] | ||
|
||
const store = mockStore({ markets: defaultState }) | ||
|
||
return store.dispatch(actions.get()).then(() => | ||
expect(store.getActions()).toEqual(expectedActions) | ||
) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
import _ from 'lodash' | ||
|
||
import { get as getBalances } from '../../actions/balances' | ||
import { get as getMarkets } from '../../actions/markets' | ||
import Ticker from '../Ticker' | ||
|
||
export default class Balances extends Component { | ||
static propTypes = { | ||
dispatch: PropTypes.func.isRequired, | ||
markets: PropTypes.object.isRequired, | ||
balances: PropTypes.object.isRequired, | ||
} | ||
|
||
componentWillMount() { | ||
this.props.dispatch(getMarkets()) | ||
this.props.dispatch(getBalances()) | ||
} | ||
|
||
render() { | ||
const { markets, balances } = this.props | ||
if (!markets.ids.length || !balances.ids.length) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div className='balances-index'> | ||
{ | ||
_.map(balances.all, (balance) => { | ||
const market = markets.all[balance.Currency] | ||
if (!market) { | ||
console.error('Currency not found:', balance) | ||
return null | ||
} | ||
if (!balance.Balance) { | ||
return null | ||
} | ||
return ( | ||
<Ticker | ||
logo={markets.all[balance.Currency].logo} | ||
key={balance.Currency} | ||
amount={`${balance.Balance} ${balance.Currency}`} | ||
/> | ||
) | ||
}) | ||
} | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.