From 2fc1619454722abc8e746b70319388314c44638b Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Mon, 7 Aug 2017 10:23:17 -0500 Subject: [PATCH] features(logo, peers): update Zap logo and allow connecting and disconnecting of peers --- app/main.dev.js | 5 + app/reducers/peers.js | 87 ++++++++++++++++-- app/routes/wallet/components/Wallet.js | 9 +- .../components/components/Peers/Peers.js | 13 +-- .../Peers/components/PeerForm/PeerForm.js | 31 +++++-- .../Peers/components/PeerModal/PeerModal.js | 13 ++- .../wallet/containers/WalletContainer.js | 6 +- resources/zap.png | Bin 4217 -> 0 bytes resources/zap_2.png | Bin 0 -> 2277 bytes 9 files changed, 138 insertions(+), 26 deletions(-) delete mode 100644 resources/zap.png create mode 100644 resources/zap_2.png diff --git a/app/main.dev.js b/app/main.dev.js index 122ef61f..dfe63df2 100644 --- a/app/main.dev.js +++ b/app/main.dev.js @@ -25,6 +25,9 @@ if (process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true') const path = require('path'); const p = path.join(__dirname, '..', 'app', 'node_modules'); require('module').globalPaths.push(p); + + // set icon + app.dock.setIcon(`${path.join(__dirname, '..', 'resources')}/zap_2.png`) } const installExtensions = async () => { @@ -64,6 +67,8 @@ app.on('ready', async () => { frame: false }); + mainWindow.maximize(); + mainWindow.loadURL(`file://${__dirname}/app.html`); // @TODO: Use 'ready-to-show' event diff --git a/app/reducers/peers.js b/app/reducers/peers.js index d3a716bd..7528b11d 100644 --- a/app/reducers/peers.js +++ b/app/reducers/peers.js @@ -3,6 +3,14 @@ import { callApi } from '../api' // ------------------------------------ // Constants // ------------------------------------ +export const CONNECT_PEER = 'CONNECT_PEER' +export const CONNECT_SUCCESS = 'CONNECT_SUCCESS' +export const CONNECT_FAILURE = 'CONNECT_FAILURE' + +export const DISCONNECT_PEER = 'DISCONNECT_PEER' +export const DISCONNECT_SUCCESS = 'DISCONNECT_SUCCESS' +export const DISCONNECT_FAILURE = 'DISCONNECT_FAILURE' + export const SET_PEER_FORM = 'SET_PEER_FORM' export const SET_PEER = 'SET_PEER' @@ -13,10 +21,48 @@ export const RECEIVE_PEERS = 'RECEIVE_PEERS' // ------------------------------------ // Actions // ------------------------------------ -export function setPeerForm(isOpen) { +export function connectPeer() { + return { + type: CONNECT_PEER + } +} + +export function connectSuccess(peer) { + return { + type: CONNECT_SUCCESS, + peer + } +} + +export function connectFailure() { + return { + type: CONNECT_FAILURE + } +} + +export function disconnectPeer() { + return { + type: DISCONNECT_PEER + } +} + +export function disconnectSuccess(pubkey) { + return { + type: DISCONNECT_SUCCESS, + pubkey + } +} + +export function disconnectFailure() { + return { + type: DISCONNECT_FAILURE + } +} + +export function setPeerForm(form) { return { type: SET_PEER_FORM, - isOpen + form } } @@ -46,11 +92,36 @@ export const fetchPeers = () => async (dispatch) => { dispatch(receivePeers(peers.data)) } +export const connectRequest = ({ pubkey, host }) => async (dispatch) => { + dispatch(connectPeer()) + const success = await callApi('connect', 'post', { pubkey, host }) + success.data ? dispatch(connectSuccess({ pub_key: pubkey, address: host, peer_id: success.data.peer_id })) : dispatch(connectFailure()) + + return success +} + +export const disconnectRequest = ({ pubkey }) => async (dispatch) => { + dispatch(disconnectPeer()) + const success = await callApi('disconnect', 'post', { pubkey }) + console.log('success: ', success) + success ? dispatch(disconnectSuccess(pubkey)) : dispatch(disconnectFailure()) + + return success +} + // ------------------------------------ // Action Handlers // ------------------------------------ const ACTION_HANDLERS = { - [SET_PEER_FORM]: (state, { isOpen }) => ({ ...state, peerForm: { ...state.form, isOpen } }), + [DISCONNECT_PEER]: (state) => ({ ...state, disconnecting: true }), + [DISCONNECT_SUCCESS]: (state, { pubkey }) => ({ ...state, disconnecting: false, peers: state.peers.filter(peer => peer.pub_key !== pubkey) }), + [DISCONNECT_FAILURE]: (state) => ({ ...state, disconnecting: false }), + + [CONNECT_PEER]: (state) => ({ ...state, connecting: true }), + [CONNECT_SUCCESS]: (state, { peer }) => ({ ...state, connecting: false, peers: [...state.peers, peer] }), + [CONNECT_FAILURE]: (state) => ({ ...state, connecting: false }), + + [SET_PEER_FORM]: (state, { form }) => ({ ...state, peerForm: Object.assign({}, state.peerForm, form) }), [SET_PEER]: (state, { peer }) => ({ ...state, peer }), @@ -77,13 +148,15 @@ const initialState = { peer: null, peerForm: { isOpen: false, - pub_key: '', - address: '' - } + pubkey: '', + host: '' + }, + connecting: false, + disconnecting: false } export default function peersReducer(state = initialState, action) { const handler = ACTION_HANDLERS[action.type] return handler ? handler(state, action) : state -} \ No newline at end of file +} diff --git a/app/routes/wallet/components/Wallet.js b/app/routes/wallet/components/Wallet.js index f054d643..0fcc9436 100644 --- a/app/routes/wallet/components/Wallet.js +++ b/app/routes/wallet/components/Wallet.js @@ -25,10 +25,11 @@ class Wallet extends Component { peerModalOpen, channelModalOpen, setPeerForm, - setChannelForm + setChannelForm, + connectRequest, + disconnectRequest } = this.props - console.log('setPeerForm: ', setPeerForm) - console.log('setChannelForm: ', setChannelForm) + return (
@@ -44,6 +45,8 @@ class Wallet extends Component { peerModalOpen={peerModalOpen} peerForm={peerForm} setPeerForm={setPeerForm} + connect={connectRequest} + disconnect={disconnectRequest} /> - - + +

Peers

setPeerForm(true)} + onClick={() => setPeerForm({ isOpen: true })} >
@@ -46,5 +48,4 @@ class Peers extends Component { } } - -export default Peers \ No newline at end of file +export default Peers diff --git a/app/routes/wallet/components/components/Peers/components/PeerForm/PeerForm.js b/app/routes/wallet/components/components/Peers/components/PeerForm/PeerForm.js index 77750e8d..5befb8f2 100644 --- a/app/routes/wallet/components/components/Peers/components/PeerForm/PeerForm.js +++ b/app/routes/wallet/components/components/Peers/components/PeerForm/PeerForm.js @@ -4,8 +4,23 @@ import ReactModal from 'react-modal' import styles from './PeerForm.scss' class PeerForm extends Component { + constructor(props, context) { + super(props, context) + this.state = { + pubkey: '02ef6248210e27b0f0df4d11d876e63f56e04bcb0054d0d8b6ba6a1a3e90dc56e1', + host: 'lnd-testnet-2.mably.com' + } + } + render() { - const customStyles = { + const submit = () => { + const { pubkey, host } = this.state + this.props.connect({ pubkey, host }).then(success => { + if (success.data) { setForm({ isOpen: false }) } + }) + } + + const customStyles = { overlay: { cursor: 'pointer', overflowY: 'auto' @@ -21,7 +36,8 @@ class PeerForm extends Component { } } - const { form, setForm } = this.props + const { form, setForm, connect } = this.props + const { pubkey, host } = this.state return (
setForm(false)} + onRequestClose={() => setForm({ isOpen: false })} parentSelector={() => document.body} style={customStyles} > @@ -42,6 +58,8 @@ class PeerForm extends Component { type='text' size='' placeholder='Public key' + value={form.pubkey} + onChange={(event) => setForm({ pubkey: event.target.value })} />
@@ -50,11 +68,13 @@ class PeerForm extends Component { type='text' size='' placeholder='Host address' + value={form.host} + onChange={(event) => setForm({ host: event.target.value })} />
-
+
Submit
@@ -65,5 +85,4 @@ class PeerForm extends Component { } } - -export default PeerForm \ No newline at end of file +export default PeerForm diff --git a/app/routes/wallet/components/components/Peers/components/PeerModal/PeerModal.js b/app/routes/wallet/components/components/Peers/components/PeerModal/PeerModal.js index 79aa1ada..4e2a4d23 100644 --- a/app/routes/wallet/components/components/Peers/components/PeerModal/PeerModal.js +++ b/app/routes/wallet/components/components/Peers/components/PeerModal/PeerModal.js @@ -5,6 +5,13 @@ import styles from './PeerModal.scss' class PeerModal extends Component { render() { + const disconnectClicked = () => { + const { peer, disconnect } = this.props + + disconnect({ pubkey: peer.pub_key }) + .then(success => success ? resetPeer(null) : null) + } + const customStyles = { overlay: { cursor: 'pointer', @@ -21,8 +28,8 @@ class PeerModal extends Component { } } - const { isOpen, resetPeer, peer } = this.props - console.log('peer: ', peer) + const { isOpen, resetPeer, peer, disconnect } = this.props + return ( {peer.bytes_sent}
-
+
Disconnect peer
diff --git a/app/routes/wallet/containers/WalletContainer.js b/app/routes/wallet/containers/WalletContainer.js index 508ce872..0680f52b 100644 --- a/app/routes/wallet/containers/WalletContainer.js +++ b/app/routes/wallet/containers/WalletContainer.js @@ -4,7 +4,9 @@ import { fetchPeers, setPeer, peersSelectors, - setPeerForm + setPeerForm, + connectRequest, + disconnectRequest } from '../../../reducers/peers' import { fetchChannels, @@ -19,6 +21,8 @@ const mapDispatchToProps = { fetchPeers, setPeer, + connectRequest, + disconnectRequest, fetchChannels, setChannel, diff --git a/resources/zap.png b/resources/zap.png deleted file mode 100644 index aa1a5953a0c8c5276a383bbda3969f9739910f4e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4217 zcmb_f3vf(V7(VCRbMM`~o83*sBT`zAAQ2*wA|WavA`yuQQlUYU3iW7m6L;4ZXXd}>KmY&zk9+Sq z|2gNYq{Lx*$yY)M>EmLflcDdRkVb&#+yx6BLZ|&GHgzsSI&XzATEEc;A-yL=8HOZyPR(_A*(BAFQQXT zAUw3|V#II`INT-5byJU(R{irL&R@tTs&Bxjk^KT#WZ!_LFXZ55jD`*DJ~AdEP>vZ8 z`1Q;9`9HSA4vvrL=_OFQLEyQg{fC<8+2yagPmBtVPl)OjX!qN=3N#Y;1qii-@@d)G zNVWsi`c9qN_kk5L9m!Z!^iU6O%7}bZSy_2o4eu!91w0GpmoLbA0WsSbNQ((-E%M|& zfhS8%MZey1G-%ET2X@XhXvOhbt$tQT)z$F|d1(19MjhD{6x6X>bA0o$AfP28k9$rS z5i(lQ*%IJ%d^!YgATqzExq;(&K%ee`dWrTaHD8%+Hk*}FYik$Eub90hexj!+E_dF|x zJBv#$syS6;#V5*swCl#khJ<6OE(^vB?J|2$DPM@OoXZ#&LyRq?5cvO8pyZq#;Miv* z_e;}h`D;6hO2$L*R7agF-gLO+XM;pLs$ss}ajF_(R%-;}PX(U6&R{M!F!`z)*r?+M zG7I}qP4_&RLD#s*o`J$VsA3p(q5{XYL{N|g3s?UP3Iql%e-TM|5U_{U^v-09r$vn> zjGcF;hqu2CTe$}nMJfY>I^XqHO`t7$m|G)xesKg zSnyQdl;bIppn%lC7l1t-6LinZq7;?KO<@R4U4KqVEPd1bxK?%8+QzQu5P1!FFWZ=) z$5vT}?HVCUcx&x_dHDxxitB7TCl8UQ28`relxl=BB3n^|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