Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced price actions/reducers with new actions architecture #595

Merged
merged 1 commit into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions __tests__/components/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@ const initialState = {
api: {
APP: {
batch: true,
mapping: ['NETWORK', 'SETTINGS']
mapping: ['NETWORK', 'PRICES', 'SETTINGS']
},
NETWORK: {
batch: false,
state: LOADED,
data: MAIN_NETWORK_ID,
loadedCount: 1
},
PRICES: {
batch: false,
state: LOADED,
data: {
NEO: 40.5,
GAS: 19.8
},
loadedCount: 1
},
SETTINGS: {
batch: false,
state: LOADED,
Expand All @@ -34,10 +43,6 @@ const initialState = {
transactions: []
},
modal: {
},
price: {
NEO: 40.5,
GAS: 19.8
}
}
const setup = (state, shallowRender = true) => {
Expand Down
61 changes: 19 additions & 42 deletions __tests__/components/WalletInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ const initialState = {
data: {
currency: DEFAULT_CURRENCY_CODE
}
},
PRICES: {
batch: false,
state: LOADED,
data: {
NEO: 25.48,
GAS: 18.1
}
}
},
account: {
Expand All @@ -72,10 +80,6 @@ const initialState = {
GAS: '1000.0001601',
tokenBalances: []
},
price: {
NEO: 25.48,
GAS: 18.1
},
claim: {
claimAmount: 0.5
}
Expand Down Expand Up @@ -107,6 +111,7 @@ describe('WalletInfo', () => {
expect(wrapper).toMatchSnapshot()
done()
})

test('correctly renders data from state', done => {
const { wrapper } = setup(initialState, false)

Expand All @@ -128,6 +133,7 @@ describe('WalletInfo', () => {
expect(gasField.text()).toEqual('1,000.0002')
done()
})

test('refreshBalance is getting called on click', async () => {
const { wrapper, store } = setup(initialState, false)

Expand All @@ -138,54 +144,24 @@ describe('WalletInfo', () => {
.then()
.then()
jest.runAllTimers()
const actions = store.getActions()
expect(actions.length).toEqual(7)

expect(actions[0]).toEqual({
type: LOADING_TRANSACTIONS,
payload: {
isLoadingTransactions: true
}
})
expect(actions[2]).toEqual({
type: LOADING_TRANSACTIONS,
payload: {
isLoadingTransactions: false
}
})
expect(actions[3]).toEqual({
type: SET_TRANSACTION_HISTORY,
payload: {
transactions: []
}
})
expect(actions[4]).toEqual({
const action = store.getActions().find((action) => action.type === SET_BALANCE)

expect(action).toEqual({
type: SET_BALANCE,
payload: {
NEO: '1',
GAS: '1'
}
})
// TODO fix this to capture the notifications as well
// expect(actions[6]).toEqual({
// type: HIDE_NOTIFICATIONS,
// payload: {
// dismissible: true,
// position: DEFAULT_POSITION
// }
// })
// expect(actions[7]).toEqual({
// type: SHOW_NOTIFICATION,
// payload: expect.objectContaining({
// message: 'Received latest blockchain information.',
// level: NOTIFICATION_LEVELS.SUCCESS
// })
// })
})

test('correctly renders data from state with non-default currency', done => {
const testState = merge(initialState, {
api: { SETTINGS: { data: { currency: 'eur' } } },
price: { NEO: 1.11, GAS: 0.55 }
api: {
SETTINGS: { data: { currency: 'eur' } },
PRICES: { data: { NEO: 1.11, GAS: 0.55 } }
}
})
const { wrapper } = setup(testState, false)

Expand All @@ -203,6 +179,7 @@ describe('WalletInfo', () => {

done()
})

test('network error is shown with connectivity error', async () => {
neonjs.api.neonDB.getBalance = jest.fn(() => {
return new Promise((resolve, reject) => {
Expand Down
4 changes: 1 addition & 3 deletions __tests__/components/__snapshots__/WalletInfo.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`WalletInfo renders without crashing 1`] = `
<Connect(withData(mapProps(Connect(withData(Connect(withActions(WalletInfo)))))))
<Connect(withData(Connect(withData(mapProps(Connect(withData(Connect(withActions(WalletInfo)))))))))
GAS="1000.0001601"
NEO="100001"
address="ANqUrhv99rwCiFTL6N1An9NH5UVkPYxTuw"
gasPrice={18.1}
loadWalletData={[Function]}
neoPrice={25.48}
networks={
Array [
Object {
Expand Down
71 changes: 0 additions & 71 deletions __tests__/modules/price.test.js

This file was deleted.

1 change: 0 additions & 1 deletion __tests__/store/reducers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ describe('root reducer', () => {
addressBook: expect.any(Object),
generateWallet: expect.any(Object),
wallet: expect.any(Object),
price: expect.any(Object),
transactions: expect.any(Object),
dashboard: expect.any(Object),
notifications: expect.any(Object),
Expand Down
2 changes: 2 additions & 0 deletions app/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import createBatchActions from '../util/api/createBatchActions'

import blockHeightActions from './blockHeightActions'
import pricesActions from './pricesActions'
import settingsActions from './settingsActions'

export const ID = 'APP'

export default createBatchActions(ID, {
blockHeight: blockHeightActions,
prices: pricesActions,
settings: settingsActions
})
16 changes: 16 additions & 0 deletions app/actions/pricesActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @flow
import { api } from 'neon-js'

import createRequestActions from '../util/api/createRequestActions'
import { ASSETS, DEFAULT_CURRENCY_CODE } from '../core/constants'

type Props = {
symbols?: Array<string>,
currency?: string
}

export const ID = 'PRICES'

export default createRequestActions(ID, ({ symbols = [ASSETS.NEO, ASSETS.GAS], currency = DEFAULT_CURRENCY_CODE }: Props = {}) => (state: Object) => {
return api.cmc.getPrices(symbols, currency)
})
11 changes: 8 additions & 3 deletions app/containers/App/Header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ import { connect, type MapStateToProps } from 'react-redux'
import { bindActionCreators } from 'redux'
import { compose } from 'recompose'

import withData from '../../../hocs/api/withData'
import withCurrencyData from '../../../hocs/withCurrencyData'
import pricesActions from '../../../actions/pricesActions'
import { logout, getAddress, getLoggedIn } from '../../../modules/account'
import { getNEOPrice, getGASPrice } from '../../../modules/price'

import Header from './Header'

const mapStateToProps: MapStateToProps<*, *, *> = (state: Object) => ({
address: getAddress(state),
neoPrice: getNEOPrice(state),
gasPrice: getGASPrice(state),
isLoggedIn: getLoggedIn(state)
})

const mapPricesDataToProps = ({ NEO, GAS }) => ({
neoPrice: NEO,
gasPrice: GAS
})

const actionCreators = {
logout
}
Expand All @@ -24,5 +28,6 @@ const mapDispatchToProps = dispatch => bindActionCreators(actionCreators, dispat

export default compose(
connect(mapStateToProps, mapDispatchToProps),
withData(pricesActions, mapPricesDataToProps),
withCurrencyData('currencyCode')
)(Header)
11 changes: 8 additions & 3 deletions app/containers/WalletInfo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { connect, type MapStateToProps } from 'react-redux'
import { bindActionCreators } from 'redux'
import { compose } from 'recompose'

import pricesActions from '../../actions/pricesActions'
import withData from '../../hocs/api/withData'
import withActions from '../../hocs/api/withActions'
import withNetworkData from '../../hocs/withNetworkData'
import withCurrencyData from '../../hocs/withCurrencyData'
Expand All @@ -11,7 +13,6 @@ import { getNetworks } from '../../core/networks'
import { showErrorNotification, showSuccessNotification } from '../../modules/notifications'
import { getAddress } from '../../modules/account'
import { loadWalletData, getNEO, getGAS, getTokenBalances } from '../../modules/wallet'
import { getNEOPrice, getGASPrice } from '../../modules/price'
import { showModal } from '../../modules/modal'
import { participateInSale, oldParticipateInSale } from '../../modules/sale'

Expand All @@ -21,12 +22,15 @@ const mapStateToProps: MapStateToProps<*, *, *> = (state: Object) => ({
NEO: getNEO(state),
GAS: getGAS(state),
address: getAddress(state),
neoPrice: getNEOPrice(state),
gasPrice: getGASPrice(state),
tokenBalances: getTokenBalances(state),
networks: getNetworks()
})

const mapPricesDataToProps = ({ NEO, GAS }) => ({
neoPrice: NEO,
gasPrice: GAS
})

const actionCreators = {
loadWalletData,
showErrorNotification,
Expand All @@ -44,6 +48,7 @@ const mapActionsToProps = (actions) => ({

export default compose(
connect(mapStateToProps, mapDispatchToProps),
withData(pricesActions, mapPricesDataToProps),
withNetworkData(),
withCurrencyData('currencyCode'),
withActions(updateSettingsActions, mapActionsToProps)
Expand Down
5 changes: 5 additions & 0 deletions app/core/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { get } from 'lodash'

import blockHeightActions from '../actions/blockHeightActions'
import pricesActions from '../actions/pricesActions'
import { ID as NETWORK_ID } from '../actions/networkActions'
import { ID as SETTINGS_ID } from '../actions/settingsActions'
import { getNetworks } from '../core/networks'
Expand Down Expand Up @@ -44,3 +45,7 @@ export const getTokensForNetwork = (state: Object) => {
export const syncBlockHeight = (state: Object) => {
return blockHeightActions.request({ networkId: getNetworkId(state) })
}

export const getMarketPrices = (state: Object) => {
return pricesActions.request({ currency: getCurrency(state) })
}
2 changes: 0 additions & 2 deletions app/modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import claim from './claim'
import dashboard from './dashboard'
import notifications from './notifications'
import modal from './modal'
import price from './price'
import addressBook from './addressBook'
import sale from './sale'

Expand All @@ -23,7 +22,6 @@ export default combineReducers({
claim,
notifications,
modal,
price,
addressBook,
sale
})
Loading