From e29f5f174c473f035256d7ba55d9bdf32154c1df Mon Sep 17 00:00:00 2001 From: Jonathan Zernik Date: Sun, 18 Oct 2020 17:41:45 -0400 Subject: [PATCH] Add pay offer dialog (#301) * Add pay offer dialog to offer component * Show offer info in buyoffer dialog * Remove old amount state from pay offer dialog * Fix import pay offer request in pay offer dialog * Go to squeak page after pay offer * Fix text of pay offer button --- .../BuyOfferDetailItem/BuyOfferDetailItem.js | 49 ++++++++- .../BuyOfferDialog/BuyOfferDialog.js | 104 +++++------------- 2 files changed, 78 insertions(+), 75 deletions(-) diff --git a/frontend/squeak-node-frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js b/frontend/squeak-node-frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js index 4955f9f4..ff088e1e 100644 --- a/frontend/squeak-node-frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js +++ b/frontend/squeak-node-frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js @@ -1,6 +1,7 @@ import React, { useState } from "react"; import { Paper, + Button, IconButton, Menu, MenuItem, @@ -15,6 +16,9 @@ import classnames from "classnames"; import LockIcon from '@material-ui/icons/Lock'; +// components +import BuyOfferDialog from "../../components/BuyOfferDialog"; + // styles import useStyles from "./styles"; @@ -28,8 +32,9 @@ export default function BuyOfferDetailItem({ ...props }) { var classes = useStyles(); - const history = useHistory(); + const [payOfferDialogOpen, setPayOfferDialogOpen] = useState(false); + const preventDefault = (event) => event.preventDefault(); @@ -52,6 +57,15 @@ export default function BuyOfferDetailItem({ } }; + const handleClickPayOffer = () => { + console.log("Handle click pay offer."); + setPayOfferDialogOpen(true); + }; + + const handleClosePayOfferDialog = () => { + setPayOfferDialogOpen(false); + }; + function OfferContent() { return ( + + + {PayOfferButton()} + + ) } + function PayOfferButton() { + return ( + <> + + + ) + } + + function PayOfferDialogContent() { + return ( + <> + + + ) + } + return ( + <> + {PayOfferDialogContent()} + ) } diff --git a/frontend/squeak-node-frontend/src/components/BuyOfferDialog/BuyOfferDialog.js b/frontend/squeak-node-frontend/src/components/BuyOfferDialog/BuyOfferDialog.js index 1f7eba2a..1ca94e38 100644 --- a/frontend/squeak-node-frontend/src/components/BuyOfferDialog/BuyOfferDialog.js +++ b/frontend/squeak-node-frontend/src/components/BuyOfferDialog/BuyOfferDialog.js @@ -29,74 +29,64 @@ import useStyles from "./styles"; import Widget from "../../components/Widget"; import SqueakThreadItem from "../../components/SqueakThreadItem"; + import { CloseChannelRequest, ChannelPoint, } from "../../proto/lnd_pb" +import { + PayOfferRequest, +} from "../../proto/squeak_admin_pb" + import { client } from "../../squeakclient/squeakclient" -export default function CloseChannelDialog({ +export default function BuyOfferDialog({ open, - txId, - outputIndex, + offer, handleClose, ...props }) { var classes = useStyles(); const history = useHistory(); - var [amount, setAmount] = useState(0); + const payOffer = (offerId) => { + console.log("called payOffer"); - const resetFields = () => { - setAmount(0); - }; + var payOfferRequest = new PayOfferRequest(); + payOfferRequest.setOfferId(offerId); + console.log(payOfferRequest); - const handleChangeAmount = (event) => { - setAmount(event.target.value); - }; - - const closeChannel = (txId, outputIndex) => { - console.log("called closeChannel"); - - var closeChannelRequest = new CloseChannelRequest() - var channelPoint = new ChannelPoint(); - channelPoint.setFundingTxidStr(txId); - channelPoint.setOutputIndex(outputIndex); - closeChannelRequest.setChannelPoint(channelPoint); - console.log(closeChannelRequest); - - client.lndCloseChannel(closeChannelRequest, {}, (err, response) => { + client.payOffer(payOfferRequest, {}, (err, response) => { if (err) { console.log(err.message); - alert('Error closing channel: ' + err.message); + alert('Error paying offer: ' + err.message); return; } console.log(response); - // goToProfilePage(response.getProfileId()); + goToSqueakPage(offer.getSqueakHash()); }); }; - // const goToProfilePage = (profileId) => { - // history.push("/app/profile/" + profileId); - // }; + const goToSqueakPage = (squeakHash) => { + history.push("/app/squeak/" + squeakHash); + }; function handleSubmit(event) { event.preventDefault(); - console.log( 'txId:', txId); - console.log( 'outputIndex:', outputIndex); - closeChannel(txId, outputIndex); + console.log( 'Offer ID:', offer.getOfferId()); + payOffer(offer.getOfferId()); handleClose(); } - function TxIdInput() { + function OfferIdInput() { return ( - ) - } - - function LocalFundingAmountInput() { - return ( - - ) - } - function CancelButton() { return ( ) } return ( - - Close Channel + + Buy Offer
- {TxIdInput()} - - - {OutputIndexInput()} + {OfferIdInput()} {CancelButton()} - {CloseChannelButton()} + {PayOfferButton()}