From f2c1474d425d662d52d66664bd983e040cdee292 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 24 Jul 2021 23:03:09 +0200 Subject: [PATCH] calculate fiat tips properly --- ui/component/livestreamComments/view.jsx | 40 ++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/ui/component/livestreamComments/view.jsx b/ui/component/livestreamComments/view.jsx index 2eb1cbcd5..6944cdfee 100644 --- a/ui/component/livestreamComments/view.jsx +++ b/ui/component/livestreamComments/view.jsx @@ -24,6 +24,7 @@ type Props = { superChats: Array, superChatsReversed: Array, superChatsTotalAmount: number, + superChatsFiatAmount: number, myChannels: ?Array, }; @@ -48,7 +49,42 @@ export default function LivestreamComments(props: Props) { superChats, // superchats organized by tip amount } = props; - let { superChatsReversed } = props; + let { superChatsReversed, superChatsFiatAmount } = props; + + superChatsFiatAmount = 0; + + if(superChats){ + console.log(superChats); + + let fiatAmount = 0; + for(const superChat of superChats){ + if(superChat.is_fiat){ + fiatAmount = fiatAmount + superChat.support_amount; + } + } + + superChatsFiatAmount = fiatAmount; + + } + + // TODO: why doesn't this work? + React.useEffect(() => { + if(superChats){ + console.log(superChats); + + // let fiatAmount = 0; + // for(const superChat of superChats){ + // if(superChat.is_fiat){ + // fiatAmount = fiatAmount + superChat.support_amount; + // } + // } + // + // console.log(fiatAmount); + // + // superChatsFiatAmount = fiatAmount.toString(); + } + }, [superChats]); + if (superChats) { const clonedSuperchats = JSON.parse(JSON.stringify(superChats)); @@ -172,7 +208,7 @@ export default function LivestreamComments(props: Props) { label={ <> / - {' '}{__('Tipped')} + {' '}{__('Tipped')} } onClick={function() {