Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LN] Add support for watchtowers (#2638)
This adds a watchtowers tab to delivery wtclient functions: - list towers - add tower - remove tower Co-authored-by: Matheus Degiovani <opensource@matheusd.com>
- Loading branch information
Showing
20 changed files
with
3,315 additions
and
18 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
104 changes: 104 additions & 0 deletions
104
app/components/views/LNPage/WatchtowersTab/WatchtowersTab.jsx
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,104 @@ | ||
import { useWatchtowersTab } from "./hooks"; | ||
import { FormattedMessage as T } from "react-intl"; | ||
import { useState } from "react"; | ||
import styles from "./WatchtowersTab.module.css"; | ||
import { TextInput } from "inputs"; | ||
import { Subtitle, Tooltip } from "shared"; | ||
import { KeyBlueButton } from "buttons"; | ||
import { CopyableText } from "pi-ui"; | ||
|
||
const AddWatchtower = ({ | ||
addWatchtower, | ||
listWatchtowers | ||
}) => { | ||
const [pubkey, setPubkey] = useState(""); | ||
const [addr, setAddr] = useState(""); | ||
|
||
return ( | ||
<div className={styles.addWatchtower}> | ||
<div className={styles.addWatchtowerContent}> | ||
<div className={styles.addWatchtowerNest}> | ||
<div className={styles.addWatchtowerNestPrefix}> | ||
<T id="ln.watchtowersTab.Pubkey" m="Tower ID:" /> | ||
</div> | ||
<TextInput | ||
value={pubkey} | ||
onChange={(e) => setPubkey(e.target.value.trim())} | ||
/> | ||
</div> | ||
<div className={styles.addWatchtowerNest}> | ||
<div className={styles.addWatchtowerNestPrefix}> | ||
<T id="ln.watchtowersTab.address" m="Address:" /> | ||
</div> | ||
<TextInput | ||
value={addr} | ||
onChange={(e) => setAddr(e.target.value.trim())} | ||
/> | ||
</div> | ||
</div> | ||
<KeyBlueButton | ||
className={styles.addWatchtowerButton} | ||
onClick={() => addWatchtower(pubkey, addr).then(() => | ||
listWatchtowers()) | ||
}> | ||
<T id="ln.watchtowersTab.addBtn" m="Add" /> | ||
</KeyBlueButton> | ||
|
||
</div> | ||
); | ||
}; | ||
|
||
const WatchtowersTab = () => { | ||
const { | ||
addWatchtower, | ||
removeWatchtower, | ||
listWatchtowers, | ||
towersList | ||
} = useWatchtowersTab(); | ||
|
||
return ( | ||
<> | ||
<Subtitle title={<T id="ln.watchtowersTab.addWatchtowerHeader" m="Add Watchtower" />} /> | ||
<AddWatchtower | ||
addWatchtower={addWatchtower} | ||
listWatchtowers={listWatchtowers} | ||
towersList={towersList} | ||
/> | ||
{towersList.length > 0 ? ( | ||
<Subtitle title={<T id="ln.watchtowersTab.listWatchtowers" m="Watchtowers connected" />} /> | ||
) : null } | ||
|
||
{towersList.map((tower) => | ||
<div | ||
className={` | ||
${styles.tower} ${tower.activeSessionCandidate ? styles.statusTrue : styles.statusFalse} | ||
`} | ||
key={tower.pubkey} | ||
> | ||
<Tooltip | ||
className={styles.removeTowerBtn} | ||
text={ | ||
<T id="ln.watchtowersTab.removeTowerBtn" m="Remove tower" /> | ||
}><a | ||
className={styles.removeIcon} | ||
onClick={() => { | ||
removeWatchtower(tower.pubkeyHex); | ||
listWatchtowers(); | ||
}} | ||
href="#"> | ||
× | ||
</a></Tooltip> | ||
<p>Sessions: {tower.numSessions}</p> | ||
<CopyableText id="copyable" className={styles.copyableText}>{tower.pubkeyHex}</CopyableText> | ||
<div className={styles.addrsWrapper}> | ||
{tower.addressesList.map((addrs) => ( | ||
<p key={`ips-${addrs}`}>{addrs}</p> | ||
))}</div> | ||
</div> | ||
)} | ||
|
||
</> | ||
); | ||
}; | ||
|
||
export default WatchtowersTab; |
81 changes: 81 additions & 0 deletions
81
app/components/views/LNPage/WatchtowersTab/WatchtowersTab.module.css
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,81 @@ | ||
.addWatchtowerContent { | ||
background-color: var(--background-back-color); | ||
padding-top: 20px; | ||
padding-left: 30px; | ||
width: 784px; | ||
box-sizing: border-box; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.addWatchtowerNest { | ||
display: flex; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.addWatchtowerNest input { | ||
width: 550px; | ||
} | ||
|
||
.addWatchtowerNestPrefix { | ||
margin-right: 20px; | ||
min-width: 125px; | ||
margin-left: 0; | ||
font-size: 19px; | ||
line-height: 24px; | ||
text-transform: capitalize; | ||
text-align: right; | ||
} | ||
|
||
.addWatchtowerButton { | ||
position: relative; | ||
margin: 20px 0 0 730px; | ||
} | ||
|
||
.tower { | ||
margin-top: 1em; | ||
background-color: var(--background-back-color); | ||
padding: 2em; | ||
display: grid; | ||
grid-template-columns: 1fr 5fr 0fr; | ||
width: 750px; | ||
min-height: 40px; | ||
} | ||
|
||
.tower.statusFalse { | ||
border-left: 10px solid var(--vote-no-color); | ||
} | ||
|
||
.tower.statusTrue { | ||
border-left: 10px solid var(--accent-color); | ||
} | ||
|
||
.addrsWrapper { | ||
margin-right: 2em; | ||
} | ||
|
||
.removeTowerBtn { position: absolute; } | ||
|
||
.removeIcon, | ||
.removeIcon:link, | ||
.removeIcon:visited { | ||
position: absolute; | ||
font-size: var(--font-size-xxlarge); | ||
bottom: 0.1rem; | ||
left: 75.5rem; | ||
color: var(--modal-close-color); | ||
transition: all 0.3s; | ||
} | ||
|
||
.removeIcon:hover, | ||
.removeIcon:link:hover, | ||
.removeIcon:visited:hover { | ||
color: var(--color-primary); | ||
} | ||
|
||
.tower div { align-items: unset; } | ||
.copyableText span { | ||
font-size: 14px; | ||
background: none; | ||
padding: 0; | ||
} |
15 changes: 15 additions & 0 deletions
15
app/components/views/LNPage/WatchtowersTab/WatchtowersTabHeader.jsx
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,15 @@ | ||
import { DescriptionHeader } from "layout"; | ||
import { FormattedMessage as T } from "react-intl"; | ||
|
||
const WatchtowersTabHeader = () => ( | ||
<DescriptionHeader | ||
description={ | ||
<T | ||
id="ln.description.watchtowers" | ||
m="Manage connection to watchtowers." | ||
/> | ||
} | ||
/> | ||
); | ||
|
||
export default WatchtowersTabHeader; |
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,26 @@ | ||
import * as sel from "selectors"; | ||
import { useEffect } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import * as lna from "actions/LNActions"; | ||
|
||
export function useWatchtowersTab() { | ||
const dispatch = useDispatch(); | ||
const addWatchtower = (wtPubKey, addr) => | ||
dispatch(lna.addWatchtower(wtPubKey, addr)); | ||
const removeWatchtower = wtPubKey => | ||
dispatch(lna.removeWatchtower(wtPubKey)); | ||
const listWatchtowers = () => | ||
dispatch(lna.listWatchtowers()); | ||
const towersList = useSelector(sel.lnTowersList); | ||
|
||
useEffect(() => { | ||
dispatch(lna.listWatchtowers()); | ||
}, [dispatch]); | ||
|
||
return { | ||
addWatchtower, | ||
removeWatchtower, | ||
listWatchtowers, | ||
towersList | ||
}; | ||
} |
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.