From 0022860e7f26ce5259d333612da63c17eeb2c334 Mon Sep 17 00:00:00 2001 From: Jonathan Zernik Date: Mon, 1 Feb 2021 02:39:00 -0800 Subject: [PATCH] Refactor navigation functions (#776) * Refactor navigation functions out of offer detail component * Remove old commentes * Fix go to lightning node from offer detail * Refactor more navigation functions * Refactor goto function out of create contact profile * Refactor goto out of create peer dialog * Refactor goto out of create signing dialog * Refactor goto out of delete squeak dialog * Refactor goto out of import signing profile dialog * Refactor goto out of lightning peer list dialog * Refactor goto out of make squeak dialog * Refactor goto out of open channel dialog * Refactor goto out of pending open channel component * Refactor goto out of pending received payment component * Refactor goto out of send bitcoin dialog * Refactor goto out of sent offer component * Refactor goto out of sent payment component * Refactor goto out of squeak detail component * Refactor goto out of profile detail component * Refactor goto out of squeak thread item component * Refactor goto out of payments page * Refactor goto out of peers page * Refactor goto out of profile page * Refactor goto out of squeak page * Refactor goto out of squeak address page * Refactor goto out of timeline page * Refactor reload out of buy dialog * Refactor reload out of delete peer dialog * Refactor reload out of delete profile dialog * Refactor reload out of delete squeak dialog * Refactor reload out of header * Refactor reload out of squeak detail component * Refactor goto out of timeline avatar component * Refactor reload out of upload image dialog * Refactor reload out of channel page * Refactor reload out of lightning node page * Refactor goto out of profiles page --- .../BuyOfferDetailItem/BuyOfferDetailItem.js | 78 +++---------- .../BuyOfferDialog/BuyOfferDialog.js | 109 ------------------ .../components/BuyOfferDialog/package.json | 6 - .../src/components/BuyOfferDialog/styles.js | 43 ------- .../BuySqueakDialog/BuySqueakDialog.js | 17 ++- .../src/components/ChannelItem/ChannelItem.js | 9 +- .../CreateContactProfileDialog.js | 9 +- .../CreatePeerDialog/CreatePeerDialog.js | 10 +- .../CreateSigningProfileDialog.js | 9 +- .../DeletePeerDialog/DeletePeerDialog.js | 9 +- .../DeleteProfileDialog.js | 9 +- .../DeleteSqueakDialog/DeleteSqueakDialog.js | 13 +-- frontend/src/components/Header/Header.js | 9 +- .../ImportSigningProfileDialog.js | 9 +- .../LightningPeerListItem.js | 12 +- .../MakeSqueakDialog/MakeSqueakDialog.js | 9 +- .../OpenChannelDialog/OpenChannelDialog.js | 4 - .../PendingOpenChannelItem.js | 11 +- .../ReceivedPayment/ReceivedPayment.js | 13 +-- .../SendBitcoinDialog/SendBitcoinDialog.js | 11 +- .../src/components/SentOffer/SentOffer.js | 13 +-- .../src/components/SentPayment/SentPayment.js | 36 ++---- .../SqueakDetailItem/SqueakDetailItem.js | 18 ++- .../SqueakProfileDetailItem.js | 8 +- .../SqueakThreadItem/SqueakThreadItem.js | 19 ++- .../SqueakUserAvatar/SqueakUserAvatar.js | 9 +- .../UpdateProfileImageDialog.js | 9 +- frontend/src/navigation/navigation.js | 46 ++++++++ frontend/src/pages/channel/Channel.js | 5 - .../src/pages/lightningnode/LightningNode.js | 14 +-- frontend/src/pages/payments/Payments.js | 17 +-- frontend/src/pages/peers/Peers.js | 9 +- frontend/src/pages/profile/Profile.js | 11 +- frontend/src/pages/profiles/Profiles.js | 10 +- frontend/src/pages/squeak/Squeak.js | 9 +- .../src/pages/squeakaddress/SqueakAddress.js | 16 +-- frontend/src/pages/timeline/Timeline.js | 9 +- 37 files changed, 215 insertions(+), 442 deletions(-) delete mode 100644 frontend/src/components/BuyOfferDialog/BuyOfferDialog.js delete mode 100644 frontend/src/components/BuyOfferDialog/package.json delete mode 100644 frontend/src/components/BuyOfferDialog/styles.js create mode 100644 frontend/src/navigation/navigation.js diff --git a/frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js b/frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js index 8a8091ab..4c4c8d83 100644 --- a/frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js +++ b/frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js @@ -16,9 +16,6 @@ import classnames from "classnames"; import LockIcon from '@material-ui/icons/Lock'; -// components -import BuyOfferDialog from "../../components/BuyOfferDialog"; - // styles import useStyles from "./styles"; @@ -26,26 +23,21 @@ import Widget from "../../components/Widget"; import moment from 'moment'; +import { + goToPeerPage, + goToLightningNodePage, +} from "../../navigation/navigation" + export default function BuyOfferDetailItem({ offer, - handleOfferClick, ...props }) { var classes = useStyles(); const history = useHistory(); const [payOfferDialogOpen, setPayOfferDialogOpen] = useState(false); - const preventDefault = (event) => event.preventDefault(); - const onOfferClick = (event) => { - event.preventDefault(); - console.log("Handling offer click..."); - if (handleOfferClick) { - handleOfferClick(); - } - } - const onPeerClick = (event) => { event.preventDefault(); const peerId = getPeerId(); @@ -53,7 +45,17 @@ export default function BuyOfferDetailItem({ return; } console.log("Handling peer click for peerId: " + peerId); - goToPeerPage(peerId); + goToPeerPage(history, peerId); + } + + const onLightningNodeClick = (event) => { + event.preventDefault(); + goToLightningNodePage( + history, + offer.getNodePubkey(), + offer.getNodeHost(), + offer.getNodePort(), + ) } const getPeerId = () => { @@ -64,20 +66,7 @@ export default function BuyOfferDetailItem({ return peer.getPeerId(); } - const goToPeerPage = (peerId) => { - history.push("/app/peer/" + peerId); - }; - const goToLightningNodePage = (pubkey, host, port) => { - console.log("Go to lightning node for pubkey: " + pubkey); - if (pubkey && host && port) { - history.push("/app/lightningnode/" + pubkey + "/" + host + "/" + port); - } else if (pubkey && host) { - history.push("/app/lightningnode/" + pubkey + "/" + host); - } else { - history.push("/app/lightningnode/" + pubkey); - } - }; const handleClickPayOffer = () => { console.log("Handle click pay offer."); @@ -160,13 +149,7 @@ export default function BuyOfferDetailItem({ Lightning Node: { - goToLightningNodePage( - offer.getNodePubkey(), - offer.getNodeHost(), - offer.getNodePort(), - ) - }}> + >Lightning Node: {lightningPubkey + "@" + lightningAddress} @@ -174,38 +157,12 @@ export default function BuyOfferDetailItem({ ) } - function PayOfferButton() { - return ( - <> - - - ) - } - - function PayOfferDialogContent() { - return ( - <> - - - ) - } - return ( <> - {PayOfferDialogContent()} ) } diff --git a/frontend/src/components/BuyOfferDialog/BuyOfferDialog.js b/frontend/src/components/BuyOfferDialog/BuyOfferDialog.js deleted file mode 100644 index d57e6cfc..00000000 --- a/frontend/src/components/BuyOfferDialog/BuyOfferDialog.js +++ /dev/null @@ -1,109 +0,0 @@ -import React, {useState, useEffect} from 'react'; -import { - Paper, - IconButton, - Menu, - MenuItem, - Typography, - Grid, - Box, - Link, - Dialog, - DialogTitle, - DialogContent, - DialogContentText, - TextField, - DialogActions, - Button, - FormControl, - InputLabel, - Select, -} from "@material-ui/core"; -import { MoreVert as MoreIcon } from "@material-ui/icons"; -import {useHistory} from "react-router-dom"; -import classnames from "classnames"; - -// styles -import useStyles from "./styles"; - -import Widget from "../../components/Widget"; -import SqueakThreadItem from "../../components/SqueakThreadItem"; - - -import { - payOfferRequest, -} from "../../squeakclient/requests" - - -export default function BuyOfferDialog({ - open, - offer, - handleClose, - ...props -}) { - var classes = useStyles(); - const history = useHistory(); - - const handleResponse = (response) => { - goToSqueakPage(offer.getSqueakHash()); - }; - - const handleErr = (err) => { - alert('Payment failure: ' + err); - }; - - const pay = (offerId) => { - payOfferRequest(offerId, handleResponse, handleErr); - }; - - const goToSqueakPage = (squeakHash) => { - history.push("/app/squeak/" + squeakHash); - }; - - function handleSubmit(event) { - event.preventDefault(); - console.log( 'Offer ID:', offer.getOfferId()); - pay(offer.getOfferId()); - handleClose(); - } - - function CancelButton() { - return ( - - ) - } - - function PayOfferButton() { - return ( - - ) - } - - return ( - - Buy Offer -
- - Are you sure you want to pay {offer.getPriceMsat() / 1000} satoshis for this offer? - - - {CancelButton()} - {PayOfferButton()} - -
-
- ) -} diff --git a/frontend/src/components/BuyOfferDialog/package.json b/frontend/src/components/BuyOfferDialog/package.json deleted file mode 100644 index 7c81f856..00000000 --- a/frontend/src/components/BuyOfferDialog/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "BuyOfferDialog", - "version": "0.0.0", - "private": true, - "main": "BuyOfferDialog.js" -} diff --git a/frontend/src/components/BuyOfferDialog/styles.js b/frontend/src/components/BuyOfferDialog/styles.js deleted file mode 100644 index f2d64da1..00000000 --- a/frontend/src/components/BuyOfferDialog/styles.js +++ /dev/null @@ -1,43 +0,0 @@ -import { makeStyles } from "@material-ui/styles"; - -export default makeStyles(theme => ({ - widgetWrapper: { - display: "flex", - minHeight: "100%", - }, - widgetHeader: { - padding: theme.spacing(3), - paddingBottom: theme.spacing(1), - display: "flex", - justifyContent: "space-between", - alignItems: "center", - }, - widgetRoot: { - boxShadow: theme.customShadows.widget, - }, - widgetBody: { - paddingBottom: theme.spacing(3), - paddingRight: theme.spacing(3), - paddingLeft: theme.spacing(3), - }, - noPadding: { - padding: 0, - }, - paper: { - display: "flex", - flexDirection: "column", - flexGrow: 1, - overflow: "hidden", - }, - moreButton: { - margin: -theme.spacing(1), - padding: 0, - width: 40, - height: 40, - color: theme.palette.text.hint, - "&:hover": { - backgroundColor: theme.palette.primary.main, - color: "rgba(255, 255, 255, 0.35)", - }, - }, -})); diff --git a/frontend/src/components/BuySqueakDialog/BuySqueakDialog.js b/frontend/src/components/BuySqueakDialog/BuySqueakDialog.js index fc1671f1..5ea37855 100644 --- a/frontend/src/components/BuySqueakDialog/BuySqueakDialog.js +++ b/frontend/src/components/BuySqueakDialog/BuySqueakDialog.js @@ -43,6 +43,9 @@ import { import { payOfferRequest, } from "../../squeakclient/requests" +import { + reloadRoute, +} from "../../navigation/navigation" export default function BuySqueakDialog({ @@ -55,11 +58,11 @@ export default function BuySqueakDialog({ var classes = useStyles(); const history = useHistory(); - var [selectedOfferId, setSelectedOfferId] = useState(-1); + var [selectedOfferId, setSelectedOfferId] = useState(""); const [offers, setOffers] = useState([]); const resetFields = () => { - setSelectedOfferId(-1); + setSelectedOfferId(""); }; const handleChange = (event) => { @@ -84,8 +87,6 @@ export default function BuySqueakDialog({ }; const handlePayResponse = (response) => { - // goToSqueakPage(offer.getSqueakHash()); - // reloadRoute(); handlePaymentComplete(); }; @@ -104,14 +105,10 @@ export default function BuySqueakDialog({ syncSqueakRequest(hash, (response) => { console.log("response:"); console.log(response); - reloadRoute(); + reloadRoute(history); }); } - const reloadRoute = () => { - history.go(0); - }; - const getSelectedOffer = () => { var offer; for (offer of offers) { @@ -137,7 +134,7 @@ export default function BuySqueakDialog({ function handleSubmit(event) { event.preventDefault(); console.log( 'selectedOfferId:', selectedOfferId); - if (selectedOfferId == -1) { + if (selectedOfferId == "") { alert('Offer must be selected.'); return; } diff --git a/frontend/src/components/ChannelItem/ChannelItem.js b/frontend/src/components/ChannelItem/ChannelItem.js index cee780d2..554941bc 100644 --- a/frontend/src/components/ChannelItem/ChannelItem.js +++ b/frontend/src/components/ChannelItem/ChannelItem.js @@ -10,6 +10,9 @@ import useStyles from "../../pages/wallet/styles"; import moment from 'moment'; import ChannelBalanceBar from "./ChannelBalanceBar"; +import { + goToChannelPage, +} from "../../navigation/navigation" export default function ChannelItem({ channel, @@ -43,16 +46,12 @@ export default function ChannelItem({ return pieces[1]; } - const goToChannelPage = (txId, outputIndex) => { - history.push("/app/channel/" + txId + "/" + outputIndex); - }; - const onChannelClick = (event) => { event.preventDefault(); console.log("Handling channel click..."); var txId = getTxId(channel); var outputIndex = getOutputIndex(channel); - goToChannelPage(txId, outputIndex); + goToChannelPage(history, txId, outputIndex); } function ChannelDetailItem(label, value) { diff --git a/frontend/src/components/CreateContactProfileDialog/CreateContactProfileDialog.js b/frontend/src/components/CreateContactProfileDialog/CreateContactProfileDialog.js index 2e741206..e94e3ee9 100644 --- a/frontend/src/components/CreateContactProfileDialog/CreateContactProfileDialog.js +++ b/frontend/src/components/CreateContactProfileDialog/CreateContactProfileDialog.js @@ -15,6 +15,9 @@ import useStyles from "./styles"; import { createContactProfileRequest, } from "../../squeakclient/requests" +import { + goToProfilePage, +} from "../../navigation/navigation" export default function CreateContactProfileDialog({ @@ -43,7 +46,7 @@ export default function CreateContactProfileDialog({ }; const handleResponse = (response) => { - goToProfilePage(response.getProfileId()); + goToProfilePage(history, response.getProfileId()); }; const handleErr = (err) => { @@ -54,10 +57,6 @@ export default function CreateContactProfileDialog({ createContactProfileRequest(profileName, squeakAddress, handleResponse, handleErr); }; - const goToProfilePage = (profileId) => { - history.push("/app/profile/" + profileId); - }; - function handleSubmit(event) { event.preventDefault(); console.log( 'profileName:', profileName); diff --git a/frontend/src/components/CreatePeerDialog/CreatePeerDialog.js b/frontend/src/components/CreatePeerDialog/CreatePeerDialog.js index d2c6f350..f9a7910d 100644 --- a/frontend/src/components/CreatePeerDialog/CreatePeerDialog.js +++ b/frontend/src/components/CreatePeerDialog/CreatePeerDialog.js @@ -17,6 +17,10 @@ import {makeStyles} from '@material-ui/core/styles'; import { createPeerRequest, } from "../../squeakclient/requests" +import { + goToPeerPage, +} from "../../navigation/navigation" + const useStyles = makeStyles((theme) => ({ form: { @@ -81,14 +85,10 @@ export default function CreatePeerDialog({ const createPeer = (peerName, host, port) => { createPeerRequest(peerName, host, port, (response) => { - goToPeerPage(response.getPeerId()); + goToPeerPage(history, response.getPeerId()); }); }; - const goToPeerPage = (peerId) => { - history.push("/app/peer/" + peerId); - }; - function handleSubmit(event) { event.preventDefault(); console.log( 'peerName:', peerName); diff --git a/frontend/src/components/CreateSigningProfileDialog/CreateSigningProfileDialog.js b/frontend/src/components/CreateSigningProfileDialog/CreateSigningProfileDialog.js index 0c502148..5b305428 100644 --- a/frontend/src/components/CreateSigningProfileDialog/CreateSigningProfileDialog.js +++ b/frontend/src/components/CreateSigningProfileDialog/CreateSigningProfileDialog.js @@ -32,6 +32,9 @@ import SqueakThreadItem from "../../components/SqueakThreadItem"; import { createSigningProfileRequest, } from "../../squeakclient/requests" +import { + goToProfilePage, +} from "../../navigation/navigation" export default function CreateSigningProfileDialog({ @@ -53,7 +56,7 @@ export default function CreateSigningProfileDialog({ }; const handleResponse = (response) => { - goToProfilePage(response.getProfileId()); + goToProfilePage(history, response.getProfileId()); }; const handleErr = (err) => { @@ -64,10 +67,6 @@ export default function CreateSigningProfileDialog({ createSigningProfileRequest(profileName, handleResponse, handleErr); }; - const goToProfilePage = (profileId) => { - history.push("/app/profile/" + profileId); - }; - function handleSubmit(event) { event.preventDefault(); console.log( 'profileName:', profileName); diff --git a/frontend/src/components/DeletePeerDialog/DeletePeerDialog.js b/frontend/src/components/DeletePeerDialog/DeletePeerDialog.js index d1d51701..64b0c629 100644 --- a/frontend/src/components/DeletePeerDialog/DeletePeerDialog.js +++ b/frontend/src/components/DeletePeerDialog/DeletePeerDialog.js @@ -31,6 +31,9 @@ import Widget from "../../components/Widget"; import { deletePeerRequest, } from "../../squeakclient/requests" +import { + reloadRoute, +} from "../../navigation/navigation" export default function DeletePeerDialog({ @@ -44,14 +47,10 @@ export default function DeletePeerDialog({ const deletePeer = (peerId) => { deletePeerRequest(peerId, (response) => { - reloadRoute(); + reloadRoute(history); }); }; - const reloadRoute = () => { - history.go(0); - }; - function handleSubmit(event) { event.preventDefault(); console.log( 'peer:', peer); diff --git a/frontend/src/components/DeleteProfileDialog/DeleteProfileDialog.js b/frontend/src/components/DeleteProfileDialog/DeleteProfileDialog.js index aeee8c81..4e2edaef 100644 --- a/frontend/src/components/DeleteProfileDialog/DeleteProfileDialog.js +++ b/frontend/src/components/DeleteProfileDialog/DeleteProfileDialog.js @@ -31,6 +31,9 @@ import Widget from "../../components/Widget"; import { deleteProfileRequest, } from "../../squeakclient/requests" +import { + reloadRoute, +} from "../../navigation/navigation" export default function DeleteProfileDialog({ @@ -44,14 +47,10 @@ export default function DeleteProfileDialog({ const deleteProfile = (profileId) => { deleteProfileRequest(profileId, (response) => { - reloadRoute(); + reloadRoute(history); }); }; - const reloadRoute = () => { - history.go(0); - }; - function handleSubmit(event) { event.preventDefault(); console.log( 'profile:', profile); diff --git a/frontend/src/components/DeleteSqueakDialog/DeleteSqueakDialog.js b/frontend/src/components/DeleteSqueakDialog/DeleteSqueakDialog.js index 4fef7b2f..1b86e14c 100644 --- a/frontend/src/components/DeleteSqueakDialog/DeleteSqueakDialog.js +++ b/frontend/src/components/DeleteSqueakDialog/DeleteSqueakDialog.js @@ -32,6 +32,9 @@ import SqueakThreadItem from "../../components/SqueakThreadItem"; import { deleteSqueakRequest, } from "../../squeakclient/requests" +import { + reloadRoute, +} from "../../navigation/navigation" export default function DeleteSqueakDialog({ @@ -45,18 +48,10 @@ export default function DeleteSqueakDialog({ const deleteSqueak = (squeakHash) => { deleteSqueakRequest(squeakHash, (response) => { - reloadRoute(); + reloadRoute(history); }); }; - const goToSqueakPage = (squeakHash) => { - history.push("/app/squeak/" + squeakHash); - }; - - const reloadRoute = () => { - history.go(0); - }; - function handleSubmit(event) { event.preventDefault(); console.log( 'squeakToDelete:', squeakToDelete); diff --git a/frontend/src/components/Header/Header.js b/frontend/src/components/Header/Header.js index 8f081055..9621acdd 100644 --- a/frontend/src/components/Header/Header.js +++ b/frontend/src/components/Header/Header.js @@ -41,6 +41,9 @@ import { logoutRequest, getUserRequest, } from "../../squeakclient/requests" +import { + reloadRoute, +} from "../../navigation/navigation" const notifications = []; @@ -61,10 +64,6 @@ export default function Header(props) { var [isSearchOpen, setSearchOpen] = useState(false); var [username, setUsername] = useState("bob smith"); - const reloadRoute = () => { - history.go(0); - }; - const getUser = () => { getUserRequest(setUsername); }; @@ -194,7 +193,7 @@ export default function Header(props) { color="primary" onClick={() => logoutRequest( () => { - reloadRoute(); + reloadRoute(history); } )} > diff --git a/frontend/src/components/ImportSigningProfileDialog/ImportSigningProfileDialog.js b/frontend/src/components/ImportSigningProfileDialog/ImportSigningProfileDialog.js index 9a7bf5ee..0d153ddd 100644 --- a/frontend/src/components/ImportSigningProfileDialog/ImportSigningProfileDialog.js +++ b/frontend/src/components/ImportSigningProfileDialog/ImportSigningProfileDialog.js @@ -32,6 +32,9 @@ import SqueakThreadItem from "../../components/SqueakThreadItem"; import { importSigningProfileRequest, } from "../../squeakclient/requests" +import { + goToProfilePage, +} from "../../navigation/navigation" export default function ImportSigningProfileDialog({ @@ -58,17 +61,13 @@ export default function ImportSigningProfileDialog({ }; const handleResponse = (response) => { - goToProfilePage(response.getProfileId()); + goToProfilePage(history, response.getProfileId()); }; const handleErr = (err) => { alert('Error creating contact profile: ' + err); }; - const goToProfilePage = (profileId) => { - history.push("/app/profile/" + profileId); - }; - function handleSubmit(event) { event.preventDefault(); console.log( 'profileName:', profileName); diff --git a/frontend/src/components/LightningPeerListItem/LightningPeerListItem.js b/frontend/src/components/LightningPeerListItem/LightningPeerListItem.js index 10d18a90..92bc0105 100644 --- a/frontend/src/components/LightningPeerListItem/LightningPeerListItem.js +++ b/frontend/src/components/LightningPeerListItem/LightningPeerListItem.js @@ -10,6 +10,10 @@ import RecordVoiceOverIcon from '@material-ui/icons/RecordVoiceOver'; import useStyles from "../../pages/wallet/styles"; +import { + goToLightningNodePage, +} from "../../navigation/navigation" + export default function LightningPeerListItem({ peer, @@ -24,15 +28,11 @@ export default function LightningPeerListItem({ const onPeerClick = (event) => { event.preventDefault(); console.log("Handling peer click..."); - goToLightningNodePage(); - } - - const goToLightningNodePage = () => { const pubkey = peer.getPubKey(); const host = getPeerHost(); const port = getPeerPort(); - history.push("/app/lightningnode/" + pubkey + "/" + host + "/" + port); - }; + goToLightningNodePage(history, pubkey, host, port); + } const getPeerHost = () => { const address = peer.getAddress(); diff --git a/frontend/src/components/MakeSqueakDialog/MakeSqueakDialog.js b/frontend/src/components/MakeSqueakDialog/MakeSqueakDialog.js index 8a03395b..607a8767 100644 --- a/frontend/src/components/MakeSqueakDialog/MakeSqueakDialog.js +++ b/frontend/src/components/MakeSqueakDialog/MakeSqueakDialog.js @@ -34,6 +34,9 @@ import { makeSqueakRequest, getSigningProfilesRequest, } from "../../squeakclient/requests" +import { + goToSqueakPage, +} from "../../navigation/navigation" export default function MakeSqueakDialog({ @@ -63,7 +66,7 @@ export default function MakeSqueakDialog({ }; const handleResponse = (response) => { - goToSqueakPage(response.getSqueakHash()); + goToSqueakPage(history, response.getSqueakHash()); }; const handleErr = (err) => { @@ -81,10 +84,6 @@ export default function MakeSqueakDialog({ loadSigningProfiles() }, []); - const goToSqueakPage = (squeakHash) => { - history.push("/app/squeak/" + squeakHash); - }; - function handleSubmit(event) { event.preventDefault(); console.log( 'profileId:', profileId); diff --git a/frontend/src/components/OpenChannelDialog/OpenChannelDialog.js b/frontend/src/components/OpenChannelDialog/OpenChannelDialog.js index 1ef9cb3c..d19b7cc3 100644 --- a/frontend/src/components/OpenChannelDialog/OpenChannelDialog.js +++ b/frontend/src/components/OpenChannelDialog/OpenChannelDialog.js @@ -72,10 +72,6 @@ export default function OpenChannelDialog({ lndOpenChannelSyncRequest(pubkey, amount, satperbyte, handleResponse, handleErr); }; - // const goToProfilePage = (profileId) => { - // history.push("/app/profile/" + profileId); - // }; - function handleSubmit(event) { event.preventDefault(); console.log( 'pubkey:', pubkey); diff --git a/frontend/src/components/PendingOpenChannelItem/PendingOpenChannelItem.js b/frontend/src/components/PendingOpenChannelItem/PendingOpenChannelItem.js index 30e631c5..2bf5734e 100644 --- a/frontend/src/components/PendingOpenChannelItem/PendingOpenChannelItem.js +++ b/frontend/src/components/PendingOpenChannelItem/PendingOpenChannelItem.js @@ -9,6 +9,11 @@ import moment from 'moment'; import Card from "@material-ui/core/Card"; import ChannelBalanceBar from "../ChannelItem/ChannelBalanceBar"; +import { + goToChannelPage, +} from "../../navigation/navigation" + + export default function PendingOpenChannelItem({ pendingOpenChannel, ...props @@ -48,10 +53,6 @@ export default function PendingOpenChannelItem({ return pieces[1]; } - const goToChannelPage = (txId, outputIndex) => { - history.push("/app/channel/" + txId + "/" + outputIndex); - }; - const onChannelClick = (event) => { event.preventDefault(); console.log("Handling channel click..."); @@ -103,4 +104,4 @@ export default function PendingOpenChannelItem({
) -} \ No newline at end of file +} diff --git a/frontend/src/components/ReceivedPayment/ReceivedPayment.js b/frontend/src/components/ReceivedPayment/ReceivedPayment.js index 299bb336..0e6375a3 100644 --- a/frontend/src/components/ReceivedPayment/ReceivedPayment.js +++ b/frontend/src/components/ReceivedPayment/ReceivedPayment.js @@ -20,6 +20,11 @@ import Widget from "../../components/Widget"; import moment from 'moment'; +import { + goToSqueakPage, +} from "../../navigation/navigation" + + export default function ReceivedPayment({ receivedPayment, ...props @@ -28,17 +33,11 @@ export default function ReceivedPayment({ const history = useHistory(); - const goToSqueakPage = (hash) => { - history.push("/app/squeak/" + hash); - }; - const onSqueakClick = (event) => { event.preventDefault(); var hash = receivedPayment.getSqueakHash(); console.log("Handling squeak click for hash: " + hash); - if (goToSqueakPage) { - goToSqueakPage(hash); - } + goToSqueakPage(history, hash); } console.log("receivedPayment:"); diff --git a/frontend/src/components/SendBitcoinDialog/SendBitcoinDialog.js b/frontend/src/components/SendBitcoinDialog/SendBitcoinDialog.js index ead17454..00e2bbfc 100644 --- a/frontend/src/components/SendBitcoinDialog/SendBitcoinDialog.js +++ b/frontend/src/components/SendBitcoinDialog/SendBitcoinDialog.js @@ -34,7 +34,9 @@ import SqueakThreadItem from "../../components/SqueakThreadItem"; import { lndSendCoins, } from "../../squeakclient/requests" - +import { + reloadRoute, +} from "../../navigation/navigation" export default function SendBitcoinDialog({ @@ -76,14 +78,11 @@ export default function SendBitcoinDialog({ const sendBitcoin = (address, amount, satperbyte, sendall) => { lndSendCoins(address, amount, satperbyte, sendall, (response) => { // setAddress(response.getAddress()); - goToWalletPage(); + // goToWalletPage(history); + reloadRoute(); }); }; - const goToWalletPage = () => { - history.push("/app/wallet/"); - }; - function handleSubmit(event) { event.preventDefault(); console.log( 'address:', address); diff --git a/frontend/src/components/SentOffer/SentOffer.js b/frontend/src/components/SentOffer/SentOffer.js index 252a0117..7206a690 100644 --- a/frontend/src/components/SentOffer/SentOffer.js +++ b/frontend/src/components/SentOffer/SentOffer.js @@ -20,6 +20,11 @@ import Widget from "../../components/Widget"; import moment from 'moment'; +import { + goToSqueakPage, +} from "../../navigation/navigation" + + export default function SentOffer({ receivedPayment, ...props @@ -30,17 +35,11 @@ export default function SentOffer({ const paymentTimeMs = receivedPayment.setPaymentTimeMs(); - const goToSqueakPage = (hash) => { - history.push("/app/squeak/" + hash); - }; - const onSqueakClick = (event) => { event.preventDefault(); var hash = receivedPayment.getSqueakHash(); console.log("Handling squeak click for hash: " + hash); - if (goToSqueakPage) { - goToSqueakPage(hash); - } + goToSqueakPage(history, hash); } console.log("receivedPayment:"); diff --git a/frontend/src/components/SentPayment/SentPayment.js b/frontend/src/components/SentPayment/SentPayment.js index 857ea742..8760de39 100644 --- a/frontend/src/components/SentPayment/SentPayment.js +++ b/frontend/src/components/SentPayment/SentPayment.js @@ -23,6 +23,13 @@ import Widget from "../../components/Widget"; import moment from 'moment'; +import { + goToSqueakPage, + goToPeerPage, + goToLightningNodePage, +} from "../../navigation/navigation" + + export default function SentPayment({ sentPayment, ...props @@ -31,32 +38,11 @@ export default function SentPayment({ const history = useHistory(); - const goToSqueakPage = (hash) => { - history.push("/app/squeak/" + hash); - }; - - const goToPeerPage = (id) => { - history.push("/app/Peer/" + id); - }; - - const goToLightningNodePage = (pubkey, host, port) => { - console.log("Go to lightning node for pubkey: " + pubkey); - if (pubkey && host && port) { - history.push("/app/lightningnode/" + pubkey + "/" + host + "/" + port); - } else if (pubkey && host) { - history.push("/app/lightningnode/" + pubkey + "/" + host); - } else { - history.push("/app/lightningnode/" + pubkey); - } - }; - const onSqueakClick = (event) => { event.preventDefault(); var hash = sentPayment.getSqueakHash(); console.log("Handling squeak click for hash: " + hash); - if (goToSqueakPage) { - goToSqueakPage(hash); - } + goToSqueakPage(history, hash); } const onPeerClick = (event) => { @@ -66,16 +52,14 @@ export default function SentPayment({ return; } console.log("Handling peer click for peerId: " + peerId); - goToPeerPage(peerId); + goToPeerPage(history, peerId); } const onLightningNodeClick = (event) => { event.preventDefault(); var nodePubkey = sentPayment.getNodePubkey(); console.log("Handling lightning node click for nodePubkey: " + nodePubkey); - if (goToLightningNodePage) { - goToLightningNodePage(nodePubkey); - } + goToLightningNodePage(history, nodePubkey); } const getPeerId = () => { diff --git a/frontend/src/components/SqueakDetailItem/SqueakDetailItem.js b/frontend/src/components/SqueakDetailItem/SqueakDetailItem.js index f01fc04b..1065e65a 100644 --- a/frontend/src/components/SqueakDetailItem/SqueakDetailItem.js +++ b/frontend/src/components/SqueakDetailItem/SqueakDetailItem.js @@ -41,6 +41,12 @@ import { import moment from 'moment'; +import { + goToSqueakAddressPage, + reloadRoute, +} from "../../navigation/navigation" + + export default function SqueakDetailItem({ hash, squeak, @@ -55,14 +61,6 @@ export default function SqueakDetailItem({ const history = useHistory(); - const goToSqueakAddressPage = () => { - history.push("/app/squeakaddress/" + squeak.getAuthorAddress()); - }; - - const reloadRoute = () => { - history.go(0); - }; - const blockDetailUrl = () => { // return "https://blockstream.info/testnet/block/" + squeak.getBlockHash(); return getBlockDetailUrl(squeak.getBlockHash(), network); @@ -75,7 +73,7 @@ export default function SqueakDetailItem({ if (!squeak) { return; } - goToSqueakAddressPage(squeak.getAuthorAddress()); + goToSqueakAddressPage(history, squeak.getAuthorAddress()); } const onReplyClick = (event) => { @@ -121,7 +119,7 @@ export default function SqueakDetailItem({ event.preventDefault(); console.log("Handling download click..."); syncSqueakRequest(hash, (response) => { - reloadRoute(); + reloadRoute(history); }); } diff --git a/frontend/src/components/SqueakProfileDetailItem/SqueakProfileDetailItem.js b/frontend/src/components/SqueakProfileDetailItem/SqueakProfileDetailItem.js index d7dcadc9..869f3a18 100644 --- a/frontend/src/components/SqueakProfileDetailItem/SqueakProfileDetailItem.js +++ b/frontend/src/components/SqueakProfileDetailItem/SqueakProfileDetailItem.js @@ -45,6 +45,7 @@ import { getProfileImageSrcString, } from "../../squeakimages/images" + import moment from 'moment'; export default function SqueakProfileDetailItem({ @@ -70,17 +71,14 @@ export default function SqueakProfileDetailItem({ const history = useHistory(); - const goToSqueakAddressPage = () => { - history.push("/app/squeakaddress/" + squeakProfile.getAddress()); - }; - const onViewSqueaksClick = () => { console.log("Handling view squeaks click..."); handleClose(); if (!squeakProfile) { return; } - goToSqueakAddressPage(); + //goToSqueakAddressPage(history, squeakProfile.getAddress()); + handleViewSqueaksClick(); } const onConfigureClick = () => { diff --git a/frontend/src/components/SqueakThreadItem/SqueakThreadItem.js b/frontend/src/components/SqueakThreadItem/SqueakThreadItem.js index 9cd6b3db..603f2fce 100644 --- a/frontend/src/components/SqueakThreadItem/SqueakThreadItem.js +++ b/frontend/src/components/SqueakThreadItem/SqueakThreadItem.js @@ -27,6 +27,11 @@ import { import moment from 'moment'; +import { + goToSqueakPage, + goToSqueakAddressPage, +} from "../../navigation/navigation" + export default function SqueakThreadItem({ hash, squeak, @@ -42,14 +47,6 @@ export default function SqueakThreadItem({ return getBlockDetailUrl(squeak.getBlockHash(), network); }; - const goToSqueakPage = (hash) => { - history.push("/app/squeak/" + hash); - }; - - const goToSqueakAddressPage = () => { - history.push("/app/squeakaddress/" + squeak.getAuthorAddress()); - }; - const onAddressClick = (event) => { event.preventDefault(); event.stopPropagation(); @@ -57,15 +54,13 @@ export default function SqueakThreadItem({ if (!squeak) { return; } - goToSqueakAddressPage(squeak.getAuthorAddress()); + goToSqueakAddressPage(history, squeak.getAuthorAddress()); } const onSqueakClick = (event) => { event.preventDefault(); console.log("Handling squeak click for hash: " + hash); - if (goToSqueakPage) { - goToSqueakPage(hash); - } + goToSqueakPage(history, hash); } function SqueakUnlockedContent() { diff --git a/frontend/src/components/SqueakUserAvatar/SqueakUserAvatar.js b/frontend/src/components/SqueakUserAvatar/SqueakUserAvatar.js index c5e3210f..6f39cac4 100644 --- a/frontend/src/components/SqueakUserAvatar/SqueakUserAvatar.js +++ b/frontend/src/components/SqueakUserAvatar/SqueakUserAvatar.js @@ -11,6 +11,9 @@ import {useHistory} from "react-router-dom"; import { getProfileImageSrcString, } from "../../squeakimages/images" +import { + goToSqueakAddressPage, +} from "../../navigation/navigation" export default function SqueakUserAvatar({ @@ -19,13 +22,9 @@ export default function SqueakUserAvatar({ }) { const history = useHistory(); - const goToSqueakAddressPage = (squeakAddress) => { - history.push("/app/squeakaddress/" + squeakAddress); - }; - const handleAvatarClick = () => { if (squeakProfile) { - goToSqueakAddressPage(squeakProfile.getAddress()); + goToSqueakAddressPage(history, squeakProfile.getAddress()); } }; diff --git a/frontend/src/components/UpdateProfileImageDialog/UpdateProfileImageDialog.js b/frontend/src/components/UpdateProfileImageDialog/UpdateProfileImageDialog.js index dbf97acf..bf5971a9 100644 --- a/frontend/src/components/UpdateProfileImageDialog/UpdateProfileImageDialog.js +++ b/frontend/src/components/UpdateProfileImageDialog/UpdateProfileImageDialog.js @@ -32,6 +32,9 @@ import SqueakThreadItem from "../../components/SqueakThreadItem"; import { setSqueakProfileImageRequest, } from "../../squeakclient/requests" +import { + reloadRoute, +} from "../../navigation/navigation" export default function UpdateProfileImageDialog({ @@ -51,13 +54,9 @@ export default function UpdateProfileImageDialog({ setImageBase64(null); }; - const reloadRoute = () => { - history.go(0); - }; - const handleResponse = (response) => { // TODO: reload profile only. - reloadRoute(); + reloadRoute(history); }; const handleErr = (err) => { diff --git a/frontend/src/navigation/navigation.js b/frontend/src/navigation/navigation.js new file mode 100644 index 00000000..25b96d28 --- /dev/null +++ b/frontend/src/navigation/navigation.js @@ -0,0 +1,46 @@ +export const reloadRoute = (history) => { + history.go(0); +}; + +export const goToPeerPage = (history, peerId) => { + history.push("/app/peer/" + peerId); +}; + +export const goToLightningNodePage = (history, pubkey, host, port) => { + console.log("Go to lightning node for pubkey: " + pubkey); + if (pubkey && host && port) { + history.push("/app/lightningnode/" + pubkey + "/" + host + "/" + port); + } else if (pubkey && host) { + history.push("/app/lightningnode/" + pubkey + "/" + host); + } else { + history.push("/app/lightningnode/" + pubkey); + } +}; + +export const goToSqueakPage = (history, squeakHash) => { + history.push("/app/squeak/" + squeakHash); +}; + +export const goToSqueakAddressPage = (history, squeakAddress) => { + history.push("/app/squeakaddress/" + squeakAddress); +}; + +export const goToChannelPage = (history, txId, outputIndex) => { + history.push("/app/channel/" + txId + "/" + outputIndex); +}; + +export const goToProfilePage = (history, profileId) => { + history.push("/app/profile/" + profileId); +}; + +export const goToWalletPage = (history) => { + history.push("/app/wallet/"); +}; + +export const goToSentPaymentsPage = (history) => { + history.push("/app/sentpayments/"); +}; + +export const goToReceivedPaymentsPage = (history) => { + history.push("/app/receivedpayments/"); +}; diff --git a/frontend/src/pages/channel/Channel.js b/frontend/src/pages/channel/Channel.js index 375a9b1b..ee019a38 100644 --- a/frontend/src/pages/channel/Channel.js +++ b/frontend/src/pages/channel/Channel.js @@ -97,11 +97,6 @@ export default function LightningNodePage() { setCloseChannelDialogOpen(true); }; - - const reloadRoute = () => { - history.go(0); - }; - useEffect(()=>{ listPeers() },[]); diff --git a/frontend/src/pages/lightningnode/LightningNode.js b/frontend/src/pages/lightningnode/LightningNode.js index 7f8a7e35..a1fb2c67 100644 --- a/frontend/src/pages/lightningnode/LightningNode.js +++ b/frontend/src/pages/lightningnode/LightningNode.js @@ -45,6 +45,10 @@ import { lndConnectPeerRequest, lndDisconnectPeerRequest, } from "../../squeakclient/requests" +import { + reloadRoute, +} from "../../navigation/navigation" + export default function LightningNodePage() { var classes = useStyles(); @@ -124,19 +128,15 @@ export default function LightningNodePage() { }; const connectPeer = (pubkey, host) => { lndConnectPeerRequest(pubkey, host, () => { - reloadRoute(); + reloadRoute(history); }); }; const disconnectPeer = (pubkey) => { lndDisconnectPeerRequest(pubkey, () => { - reloadRoute(); + reloadRoute(history); }); }; - const reloadRoute = () => { - history.go(0); - }; - useEffect(()=>{ listPeers() },[]); @@ -277,7 +277,7 @@ export default function LightningNodePage() { {HasChannelToPeer()} - {!hasChannelToPeer && + {!hasChannelToPeer() && OpenChannelButton() } diff --git a/frontend/src/pages/payments/Payments.js b/frontend/src/pages/payments/Payments.js index ca2759de..ce9be58b 100644 --- a/frontend/src/pages/payments/Payments.js +++ b/frontend/src/pages/payments/Payments.js @@ -23,7 +23,6 @@ import Table from "../dashboard/components/Table/Table"; import SentPayment from "../../components/SentPayment"; import ReceivedPayment from "../../components/ReceivedPayment"; - // data import mock from "../dashboard/mock"; @@ -32,6 +31,10 @@ import { getReceivedPaymentsRequest, getPaymentSummaryRequest } from "../../squeakclient/requests" +import { + goToSentPaymentsPage, + goToReceivedPaymentsPage, +} from "../../navigation/navigation" const useStyles = makeStyles((theme) => ({ root: { @@ -53,14 +56,6 @@ export default function Payments() { }); }; - const goToSentPaymentsPage = () => { - history.push("/app/sentpayments/"); - }; - - const goToReceivedPaymentsPage = () => { - history.push("/app/receivedpayments/"); - }; - useEffect(() => { loadPaymentSummary(); }, []); @@ -138,7 +133,7 @@ export default function Payments() { @@ -155,7 +150,7 @@ export default function Payments() { diff --git a/frontend/src/pages/peers/Peers.js b/frontend/src/pages/peers/Peers.js index 7d364d62..385ca52b 100644 --- a/frontend/src/pages/peers/Peers.js +++ b/frontend/src/pages/peers/Peers.js @@ -27,6 +27,9 @@ import mock from "../dashboard/mock"; import { getPeersRequest, } from "../../squeakclient/requests" +import { + goToPeerPage, +} from "../../navigation/navigation" const useStyles = makeStyles((theme) => ({ @@ -54,10 +57,6 @@ export default function Peers() { getPeersRequest(setPeers); }; - const goToPeerPage = (id) => { - history.push("/app/Peer/" + id); - }; - const handleClickOpenCreatePeerDialog = () => { setCreatePeerDialogOpen(true); }; @@ -126,7 +125,7 @@ export default function Peers() { onRowClick: rowData => { var id = rowData[0]; console.log("clicked on id" + id); - goToPeerPage(id); + goToPeerPage(history, id); }, }}/> diff --git a/frontend/src/pages/profile/Profile.js b/frontend/src/pages/profile/Profile.js index 93ccb8fd..b0156f4a 100644 --- a/frontend/src/pages/profile/Profile.js +++ b/frontend/src/pages/profile/Profile.js @@ -50,7 +50,9 @@ import { import { getProfileImageSrcString, } from "../../squeakimages/images" - +import { + goToSqueakAddressPage, +} from "../../navigation/navigation" export default function ProfilePage() { @@ -77,11 +79,6 @@ export default function ProfilePage() { getSqueakProfileRequest(id, setSqueakProfile); }; - const goToSqueakAddressPage = (squeakAddress) => { - history.push("/app/squeakaddress/" + squeakAddress); - }; - - useEffect(()=>{ getSqueakProfile(id) },[id]); @@ -123,7 +120,7 @@ export default function ProfilePage() { }; const handleViewSqueaks = () => { - goToSqueakAddressPage(squeakProfile.getAddress()); + goToSqueakAddressPage(history, squeakProfile.getAddress()); }; function ProfileContent() { diff --git a/frontend/src/pages/profiles/Profiles.js b/frontend/src/pages/profiles/Profiles.js index 9a9e642e..5391486f 100644 --- a/frontend/src/pages/profiles/Profiles.js +++ b/frontend/src/pages/profiles/Profiles.js @@ -30,6 +30,9 @@ import { getSigningProfilesRequest, getContactProfilesRequest, } from "../../squeakclient/requests" +import { + goToProfilePage, +} from "../../navigation/navigation" const useStyles = makeStyles((theme) => ({ @@ -68,10 +71,6 @@ export default function Profiles() { getContactProfilesRequest(setContactProfiles); }; - const goToProfilePage = (profileId) => { - history.push("/app/profile/" + profileId); - }; - const handleClickOpenCreateSigningProfileDialog = () => { setCreateSigningProfileDialogOpen(true); }; @@ -255,8 +254,7 @@ export default function Profiles() { onRowClick: rowData => { var id = rowData[0]; var address = rowData[2]; - //goToSqueakAddressPage(address); - goToProfilePage(id); + goToProfilePage(history, id); } }}/> diff --git a/frontend/src/pages/squeak/Squeak.js b/frontend/src/pages/squeak/Squeak.js index 5b1deec4..ebd41d3d 100644 --- a/frontend/src/pages/squeak/Squeak.js +++ b/frontend/src/pages/squeak/Squeak.js @@ -42,6 +42,9 @@ import { getReplySqueakDisplaysRequest, getNetworkRequest, } from "../../squeakclient/requests" +import { + goToSqueakAddressPage, +} from "../../navigation/navigation" function Alert(props) { @@ -77,10 +80,6 @@ export default function SqueakPage() { getNetworkRequest(setNetwork); }; - const goToSqueakAddressPage = (squeakAddress) => { - history.push("/app/squeakaddress/" + squeakAddress); - }; - const unknownAncestorHash = () => { if (!ancestorSqueaks) { return null; @@ -163,7 +162,7 @@ export default function SqueakPage() { const handleAvatarClick = () => { console.log("Avatar clicked..."); if (squeak) { - goToSqueakAddressPage(squeak.getAuthorAddress()); + goToSqueakAddressPage(history, squeak.getAuthorAddress()); } }; return ( diff --git a/frontend/src/pages/squeakaddress/SqueakAddress.js b/frontend/src/pages/squeakaddress/SqueakAddress.js index caefc029..a12cc93e 100644 --- a/frontend/src/pages/squeakaddress/SqueakAddress.js +++ b/frontend/src/pages/squeakaddress/SqueakAddress.js @@ -32,6 +32,10 @@ import { getAddressSqueakDisplaysRequest, getNetworkRequest, } from "../../squeakclient/requests" +import { + goToSqueakAddressPage, + goToProfilePage, +} from "../../navigation/navigation" export default function SqueakAddressPage() { @@ -53,14 +57,6 @@ export default function SqueakAddressPage() { getNetworkRequest(setNetwork); }; - const goToProfilePage = (profileId) => { - history.push("/app/profile/" + profileId); - }; - - const goToSqueakAddressPage = (squeakAddress) => { - history.push("/app/squeakaddress/" + squeakAddress); - }; - const handleClickOpenCreateContactProfileDialog = () => { setCreateContactProfileDialogOpen(true); }; @@ -95,7 +91,7 @@ export default function SqueakAddressPage() {
Profile:
) @@ -112,7 +108,7 @@ export default function SqueakAddressPage() { function TimelineUserAvatar(squeak) { const handleAvatarClick = () => { console.log("Avatar clicked..."); - goToSqueakAddressPage(squeak.getAuthorAddress()); + goToSqueakAddressPage(history, squeak.getAuthorAddress()); }; return ( { - history.push("/app/squeakaddress/" + squeakAddress); - }; - const handleClickOpen = () => { setOpen(true); }; @@ -107,7 +106,7 @@ export default function TimelinePage() { function TimelineUserAvatar(squeak) { const handleAvatarClick = () => { console.log("Avatar clicked..."); - goToSqueakAddressPage(squeak.getAuthorAddress()); + goToSqueakAddressPage(history, squeak.getAuthorAddress()); }; return (