From 262d54cc43451d9b4dd6746f4ae32c08d35b1a97 Mon Sep 17 00:00:00 2001 From: MTG2000 Date: Mon, 17 Jan 2022 16:29:14 +0200 Subject: [PATCH] fix: silent "Tip not confirmed" error Currently, the payment is made but the graphql api is not able to confirm it, so I just wrapped it with a catch to silent the error, however it has to be fixed from the backend soon --- .../ProjectsSection/ProjectsSection.tsx | 2 +- src/pages/ProjectPage/Tip/TipCard.tsx | 31 ++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/pages/ExplorePage/ProjectsSection/ProjectsSection.tsx b/src/pages/ExplorePage/ProjectsSection/ProjectsSection.tsx index ebbbeb5..613709c 100644 --- a/src/pages/ExplorePage/ProjectsSection/ProjectsSection.tsx +++ b/src/pages/ExplorePage/ProjectsSection/ProjectsSection.tsx @@ -10,7 +10,7 @@ import { ALL_CATEGORIES_PROJECTS_QUERY, ALL_CATEGORIES_PROJECTS_RES } from "./qu export default function ProjectsSection() { const { data, loading } = useQuery(ALL_CATEGORIES_PROJECTS_QUERY); - console.log(data, loading); + if (loading || !data) return
{Array(3).fill(0).map((_, idx) => )} diff --git a/src/pages/ProjectPage/Tip/TipCard.tsx b/src/pages/ProjectPage/Tip/TipCard.tsx index e774999..6334569 100644 --- a/src/pages/ProjectPage/Tip/TipCard.tsx +++ b/src/pages/ProjectPage/Tip/TipCard.tsx @@ -68,17 +68,24 @@ export default function TipCard({ onClose, direction, tipValue, ...props }: Prop const [vote, { data }] = useMutation(VOTE, { onCompleted: async (votingData) => { - setPaymentStatus(PaymentStatus.AWAITING_PAYMENT); - const webln = await Wallet_Service.getWebln() - webln.sendPayment(votingData.vote.payment_request).then((res: any) => { - console.log("waiting for payment", res); - confirmVote({ variables: { paymentRequest: votingData.vote.payment_request, preimage: res.preimage } }); + try { + setPaymentStatus(PaymentStatus.AWAITING_PAYMENT); + const webln = await Wallet_Service.getWebln() + const paymentResponse = await webln.sendPayment(votingData.vote.payment_request); setPaymentStatus(PaymentStatus.PAID); - }) - .catch((err: any) => { - console.log(err); - setPaymentStatus(PaymentStatus.NOT_PAID); - }); + confirmVote({ variables: { paymentRequest: votingData.vote.payment_request, preimage: paymentResponse.preimage } }) + .catch() // ONLY TEMPROARY !!! SHOULD BE FIXED FROM BACKEND + .finally(() => { + setTimeout(() => { + onClose?.(); + }, 2000); + }) + + } catch (error) { + console.log(error); + setPaymentStatus(PaymentStatus.NOT_PAID); + } + } }); @@ -88,7 +95,9 @@ export default function TipCard({ onClose, direction, tipValue, ...props }: Prop setTimeout(() => { onClose?.(); }, 2000); - } + }, + onError: () => { } + }); const onChangeInput = (event: React.ChangeEvent) => {