calculate fiat tips properly

This commit is contained in:
Anthony 2021-07-24 23:03:09 +02:00 committed by zeppi
parent 9debf3ed08
commit f2c1474d42

View file

@ -24,6 +24,7 @@ type Props = {
superChats: Array<Comment>, superChats: Array<Comment>,
superChatsReversed: Array, superChatsReversed: Array,
superChatsTotalAmount: number, superChatsTotalAmount: number,
superChatsFiatAmount: number,
myChannels: ?Array<ChannelClaim>, myChannels: ?Array<ChannelClaim>,
}; };
@ -48,7 +49,42 @@ export default function LivestreamComments(props: Props) {
superChats, // superchats organized by tip amount superChats, // superchats organized by tip amount
} = props; } = 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) { if (superChats) {
const clonedSuperchats = JSON.parse(JSON.stringify(superChats)); const clonedSuperchats = JSON.parse(JSON.stringify(superChats));
@ -172,7 +208,7 @@ export default function LivestreamComments(props: Props) {
label={ label={
<> <>
<CreditAmount amount={superChatsTotalAmount} size={8} /> / <CreditAmount amount={superChatsTotalAmount} size={8} /> /
<CreditAmount amount={superChatsTotalAmount} size={8} isFiat={true} /> {' '}{__('Tipped')} <CreditAmount amount={superChatsFiatAmount} size={8} isFiat={true} /> {' '}{__('Tipped')}
</> </>
} }
onClick={function() { onClick={function() {