Browse Source

feature(refresh channels): ability to refresh channels

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
6e2dde1dfe
  1. 6
      app/app.global.scss
  2. 136
      app/components/Channels/Channels.js
  3. 24
      app/components/Channels/Channels.scss
  4. 10
      app/keyframes.scss
  5. 2
      app/routes/wallet/components/Wallet.js

6
app/app.global.scss

@ -67,3 +67,9 @@ body {
stroke: darken($main, 10%); stroke: darken($main, 10%);
} }
} }
@keyframes spin {
100% {
transform: rotate(360deg);
}
}

136
app/components/Channels/Channels.js

@ -1,6 +1,7 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { TiPlus } from 'react-icons/lib/ti' import { TiPlus } from 'react-icons/lib/ti'
import { FaRepeat } from 'react-icons/lib/fa'
import ChannelModal from './ChannelModal' import ChannelModal from './ChannelModal'
import ChannelForm from './ChannelForm' import ChannelForm from './ChannelForm'
import Channel from './Channel' import Channel from './Channel'
@ -9,6 +10,7 @@ import ClosedPendingChannel from './ClosedPendingChannel'
import styles from './Channels.scss' import styles from './Channels.scss'
const Channels = ({ const Channels = ({
fetchChannels,
ticker, ticker,
peers, peers,
channelsLoading, channelsLoading,
@ -22,67 +24,93 @@ const Channels = ({
closeChannel, closeChannel,
currentTicker, currentTicker,
explorerLinkBase explorerLinkBase
}) => ( }) => {
<div className={styles.channels}> const refreshClicked = (event) => {
<ChannelModal // store event in icon so we dont get an error when react clears it
isOpen={channelModalOpen} let icon = event.currentTarget
resetChannel={setChannel}
channel={modalChannel} // fetch channels
explorerLinkBase={explorerLinkBase} fetchChannels()
closeChannel={closeChannel}
/> // clear animation after the second so we can reuse it
<ChannelForm form={channelForm} setForm={setChannelForm} ticker={ticker} peers={peers} openChannel={openChannel} currentTicker={currentTicker} /> setTimeout(() => icon.style.animation = '', 1000)
<div className={styles.header}>
<h3>Channels</h3> // spin icon for 1 sec
<div icon.style.animation = 'spin 1000ms linear 1'
className={`${styles.openChannel} hint--top`} }
data-hint='Open a channel'
onClick={() => setChannelForm({ isOpen: true })} return (
> <div className={styles.channels}>
<TiPlus /> <ChannelModal
isOpen={channelModalOpen}
resetChannel={setChannel}
channel={modalChannel}
explorerLinkBase={explorerLinkBase}
closeChannel={closeChannel}
/>
<ChannelForm form={channelForm} setForm={setChannelForm} ticker={ticker} peers={peers} openChannel={openChannel} currentTicker={currentTicker} />
<div className={styles.header}>
<h3>Channels</h3>
<span
className={`${styles.refresh} hint--top`}
data-hint='Refresh your channels list'
>
<FaRepeat
style={{ verticalAlign: 'baseline' }}
onClick={refreshClicked}
/>
</span>
<div
className={`${styles.openChannel} hint--top`}
data-hint='Open a channel'
onClick={() => setChannelForm({ isOpen: true })}
>
<TiPlus />
</div>
</div> </div>
</div> <ul>
<ul> {
{ !channelsLoading ?
!channelsLoading ? allChannels.map((channel, index) => {
allChannels.map((channel, index) => { if (Object.prototype.hasOwnProperty.call(channel, 'blocks_till_open')) {
if (Object.prototype.hasOwnProperty.call(channel, 'blocks_till_open')) { return (
<OpenPendingChannel
key={index}
channel={channel}
ticker={ticker}
currentTicker={currentTicker}
explorerLinkBase={explorerLinkBase}
/>
)
} else if (Object.prototype.hasOwnProperty.call(channel, 'closing_txid')) {
return (
<ClosedPendingChannel
key={index}
channel={channel}
ticker={ticker}
currentTicker={currentTicker}
explorerLinkBase={explorerLinkBase}
/>
)
}
return ( return (
<OpenPendingChannel <Channel
key={index} key={channel.chan_id}
channel={channel}
ticker={ticker} ticker={ticker}
currentTicker={currentTicker}
explorerLinkBase={explorerLinkBase}
/>
)
} else if (Object.prototype.hasOwnProperty.call(channel, 'closing_txid')) {
return (
<ClosedPendingChannel
key={index}
channel={channel} channel={channel}
ticker={ticker} setChannel={setChannel}
currentTicker={currentTicker} currentTicker={currentTicker}
explorerLinkBase={explorerLinkBase}
/> />
) )
} })
return ( :
<Channel 'Loading...'
key={channel.chan_id} }
ticker={ticker} </ul>
channel={channel} </div>
setChannel={setChannel} )
currentTicker={currentTicker} }
/>
)
})
:
'Loading...'
}
</ul>
</div>
)
Channels.propTypes = { Channels.propTypes = {
ticker: PropTypes.object.isRequired, ticker: PropTypes.object.isRequired,

24
app/components/Channels/Channels.scss

@ -1,5 +1,15 @@
@import '../../variables.scss'; @import '../../variables.scss';
@keyframes spin {
from {
transform: rotate(0deg)
}
to {
transform: rotate(360deg);
}
}
.channels { .channels {
width: 75%; width: 75%;
margin: 50px auto; margin: 50px auto;
@ -15,6 +25,20 @@
text-align: left; text-align: left;
} }
.refresh {
cursor: pointer;
margin-left: 5px;
font-size: 12px;
vertical-align: top;
color: $darkestgrey;
line-height: 14px;
transition: color 0.25s;
&:hover {
color: $main;
}
}
.openChannel { .openChannel {
float: right; float: right;
cursor: pointer; cursor: pointer;

10
app/keyframes.scss

@ -31,3 +31,13 @@
75% { color: $gold; } 75% { color: $gold; }
100% { color: $white; } 100% { color: $white; }
} }
@keyframes spin {
from {
transform:rotate(0deg)
}
to {
transform:rotate(360deg);
}
}

2
app/routes/wallet/components/Wallet.js

@ -21,6 +21,7 @@ class Wallet extends Component {
ticker, ticker,
peers: { peersLoading, peers, peer, peerForm }, peers: { peersLoading, peers, peer, peerForm },
channels: { channelsLoading, channels, channel, channelForm, pendingChannels }, channels: { channelsLoading, channels, channel, channelForm, pendingChannels },
fetchChannels,
setPeer, setPeer,
setChannel, setChannel,
peerModalOpen, peerModalOpen,
@ -64,6 +65,7 @@ class Wallet extends Component {
disconnect={disconnectRequest} disconnect={disconnectRequest}
/> />
<Channels <Channels
fetchChannels={fetchChannels}
ticker={ticker} ticker={ticker}
peers={peers} peers={peers}
channelsLoading={channelsLoading} channelsLoading={channelsLoading}

Loading…
Cancel
Save