Tom Kirkpatrick
6 years ago
21 changed files with 318 additions and 171 deletions
@ -0,0 +1,41 @@ |
|||
import { connect } from 'react-redux' |
|||
import { Pay } from 'components/Pay' |
|||
import { tickerSelectors, setCurrency, setFiatTicker } from 'reducers/ticker' |
|||
import { queryFees, queryRoutes } from 'reducers/pay' |
|||
import { infoSelectors } from 'reducers/info' |
|||
import { sendCoins } from 'reducers/transaction' |
|||
import { payInvoice } from 'reducers/payment' |
|||
|
|||
const mapStateToProps = state => ({ |
|||
chain: state.info.chain, |
|||
network: infoSelectors.testnetSelector(state) ? 'testnet' : 'mainnet', |
|||
cryptoName: tickerSelectors.cryptoName(state), |
|||
channelBalance: state.balance.channelBalance, |
|||
currentTicker: tickerSelectors.currentTicker(state), |
|||
cryptoCurrency: state.ticker.currency, |
|||
cryptoCurrencyTicker: tickerSelectors.currencyName(state), |
|||
cryptoCurrencies: state.ticker.currencyFilters, |
|||
fiatCurrencies: state.ticker.fiatTickers, |
|||
fiatCurrency: state.ticker.fiatTicker, |
|||
initialPayReq: state.pay.payReq, |
|||
isQueryingFees: state.pay.isQueryingFees, |
|||
isQueryingRoutes: state.pay.isQueryingRoutes, |
|||
nodes: state.network.nodes, |
|||
onchainFees: state.pay.onchainFees, |
|||
routes: state.pay.routes, |
|||
walletBalance: state.balance.walletBalance |
|||
}) |
|||
|
|||
const mapDispatchToProps = { |
|||
payInvoice, |
|||
setCryptoCurrency: setCurrency, |
|||
setFiatCurrency: setFiatTicker, |
|||
sendCoins, |
|||
queryFees, |
|||
queryRoutes |
|||
} |
|||
|
|||
export default connect( |
|||
mapStateToProps, |
|||
mapDispatchToProps |
|||
)(Pay) |
@ -0,0 +1,131 @@ |
|||
import { ipcRenderer } from 'electron' |
|||
import get from 'lodash.get' |
|||
import { requestFees } from 'lib/utils/api' |
|||
import { setFormType } from './form' |
|||
|
|||
// ------------------------------------
|
|||
// Constants
|
|||
// ------------------------------------
|
|||
export const QUERY_FEES = 'QUERY_FEES' |
|||
export const QUERY_FEES_SUCCESS = 'QUERY_FEES_SUCCESS' |
|||
export const QUERY_FEES_FAILURE = 'QUERY_FEES_FAILURE' |
|||
|
|||
export const QUERY_ROUTES = 'QUERY_ROUTES' |
|||
export const QUERY_ROUTES_SUCCESS = 'QUERY_ROUTES_SUCCESS' |
|||
export const QUERY_ROUTES_FAILURE = 'QUERY_ROUTES_FAILURE' |
|||
|
|||
export const SET_PAY_REQ = 'SET_PAY_REQ' |
|||
|
|||
// ------------------------------------
|
|||
// Actions
|
|||
// ------------------------------------
|
|||
export const queryFees = () => async dispatch => { |
|||
dispatch({ type: QUERY_FEES }) |
|||
try { |
|||
const onchainFees = await requestFees() |
|||
dispatch({ type: QUERY_FEES_SUCCESS, onchainFees }) |
|||
} catch (e) { |
|||
const error = get(e, 'response.statusText', e) |
|||
dispatch({ type: QUERY_FEES_FAILURE, error }) |
|||
} |
|||
} |
|||
|
|||
export const queryRoutes = (pubKey, amount) => dispatch => { |
|||
dispatch({ type: QUERY_ROUTES, pubKey }) |
|||
ipcRenderer.send('lnd', { msg: 'queryRoutes', data: { pubkey: pubKey, amount } }) |
|||
} |
|||
|
|||
export const queryRoutesSuccess = (event, { routes }) => dispatch => |
|||
dispatch({ type: QUERY_ROUTES_SUCCESS, routes }) |
|||
|
|||
export const queryRoutesFailure = () => dispatch => { |
|||
dispatch({ type: QUERY_ROUTES_FAILURE }) |
|||
} |
|||
|
|||
export function setPayReq(payReq) { |
|||
return { |
|||
type: SET_PAY_REQ, |
|||
payReq |
|||
} |
|||
} |
|||
|
|||
export const lightningPaymentUri = (event, { payReq }) => dispatch => { |
|||
dispatch(setPayReq(payReq)) |
|||
dispatch(setFormType('PAY_FORM')) |
|||
dispatch(setPayReq(null)) |
|||
} |
|||
|
|||
// ------------------------------------
|
|||
// Action Handlers
|
|||
// ------------------------------------
|
|||
const ACTION_HANDLERS = { |
|||
[QUERY_FEES]: state => ({ |
|||
...state, |
|||
isQueryingFees: true, |
|||
onchainFees: {}, |
|||
queryFeesError: null |
|||
}), |
|||
[QUERY_FEES_SUCCESS]: (state, { onchainFees }) => ({ |
|||
...state, |
|||
isQueryingFees: false, |
|||
onchainFees, |
|||
queryFeesError: null |
|||
}), |
|||
[QUERY_FEES_FAILURE]: (state, { error }) => ({ |
|||
...state, |
|||
isQueryingFees: false, |
|||
onchainFees: {}, |
|||
queryFeesError: error |
|||
}), |
|||
[QUERY_ROUTES]: (state, { pubKey }) => ({ |
|||
...state, |
|||
isQueryingRoutes: true, |
|||
pubKey, |
|||
queryRoutesError: null, |
|||
routes: [] |
|||
}), |
|||
[QUERY_ROUTES_SUCCESS]: (state, { routes }) => ({ |
|||
...state, |
|||
isQueryingRoutes: false, |
|||
queryRoutesError: null, |
|||
routes |
|||
}), |
|||
[QUERY_ROUTES_FAILURE]: (state, { error }) => ({ |
|||
...state, |
|||
isQueryingRoutes: false, |
|||
pubKey: null, |
|||
queryRoutesError: error, |
|||
routes: [] |
|||
}), |
|||
[SET_PAY_REQ]: (state, { payReq }) => ({ |
|||
...state, |
|||
payReq |
|||
}) |
|||
} |
|||
|
|||
// ------------------------------------
|
|||
// Initial State
|
|||
// ------------------------------------
|
|||
const initialState = { |
|||
isQueryingRoutes: false, |
|||
isQueryingFees: false, |
|||
onchainFees: { |
|||
fastestFee: null, |
|||
halfHourFee: null, |
|||
hourFee: null |
|||
}, |
|||
payReq: null, |
|||
pubKey: null, |
|||
queryFeesError: null, |
|||
queryRoutesError: null, |
|||
routes: [] |
|||
} |
|||
|
|||
// ------------------------------------
|
|||
// Reducer
|
|||
// ------------------------------------
|
|||
export default function activityReducer(state = initialState, action) { |
|||
const handler = ACTION_HANDLERS[action.type] |
|||
|
|||
return handler ? handler(state, action) : state |
|||
} |
@ -1,87 +0,0 @@ |
|||
import React from 'react' |
|||
import { configure } from 'enzyme' |
|||
import Adapter from 'enzyme-adapter-react-16' |
|||
import 'jest-styled-components' |
|||
import { ThemeProvider } from 'styled-components' |
|||
import Pay from 'components/Form/Pay' |
|||
import { dark } from 'themes' |
|||
import { mountWithIntl } from '../../__helpers__/intl-enzyme-test-helper' |
|||
|
|||
configure({ adapter: new Adapter() }) |
|||
|
|||
const defaultProps = { |
|||
payform: { |
|||
amount: 0, |
|||
payInput: '', |
|||
invoice: {}, |
|||
showErrors: {} |
|||
}, |
|||
currency: '', |
|||
crypto: '', |
|||
nodes: [], |
|||
ticker: { |
|||
currency: 'btc', |
|||
fiatTicker: 'USD' |
|||
}, |
|||
|
|||
isOnchain: false, |
|||
isLn: true, |
|||
currentAmount: 0, |
|||
usdAmount: 0, |
|||
inputCaption: '', |
|||
showPayLoadingScreen: true, |
|||
payFormIsValid: {}, |
|||
currencyFilters: [], |
|||
currencyName: '', |
|||
|
|||
setPayAmount: () => {}, |
|||
setPayInput: () => {}, |
|||
fetchInvoice: () => {}, |
|||
setCurrency: () => {}, |
|||
|
|||
onPayAmountBlur: () => {}, |
|||
|
|||
onPayInputBlur: () => {}, |
|||
|
|||
onPaySubmit: () => {} |
|||
} |
|||
|
|||
describe('Form', () => { |
|||
describe('should show the form without an input', () => { |
|||
const el = mountWithIntl( |
|||
<ThemeProvider theme={dark}> |
|||
<Pay {...defaultProps} /> |
|||
</ThemeProvider> |
|||
) |
|||
|
|||
it('should contain Pay', () => { |
|||
expect(el.find('input#paymentRequest').props.value).toBe(undefined) |
|||
}) |
|||
}) |
|||
|
|||
describe('should show lightning with a lightning input', () => { |
|||
const props = { ...defaultProps, isLn: true } |
|||
const el = mountWithIntl( |
|||
<ThemeProvider theme={dark}> |
|||
<Pay {...props} /> |
|||
</ThemeProvider> |
|||
) |
|||
|
|||
it('should contain Pay', () => { |
|||
expect(el.find('input#paymentRequest').props.value).toBe(undefined) |
|||
}) |
|||
}) |
|||
|
|||
describe('should show on-chain with an on-chain input', () => { |
|||
const props = { ...defaultProps, isOnchain: true } |
|||
const el = mountWithIntl( |
|||
<ThemeProvider theme={dark}> |
|||
<Pay {...props} /> |
|||
</ThemeProvider> |
|||
) |
|||
|
|||
it('should contain Pay', () => { |
|||
expect(el.find('input#paymentRequest').props.value).toBe(undefined) |
|||
}) |
|||
}) |
|||
}) |
Loading…
Reference in new issue