From a9f0f385d5bd064ab9d3a28e178a710491eb0640 Mon Sep 17 00:00:00 2001 From: Anthony Date: Thu, 22 Jul 2021 22:37:49 +0200 Subject: [PATCH 01/17] fix frontend bug --- ui/component/walletSendTip/view.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/component/walletSendTip/view.jsx b/ui/component/walletSendTip/view.jsx index 97fe1186e..4f99fbbb4 100644 --- a/ui/component/walletSendTip/view.jsx +++ b/ui/component/walletSendTip/view.jsx @@ -444,7 +444,7 @@ function WalletSendTip(props: Props) { {/* short explainer under the button */}
- {explainerText} + {explainerText + ' '} {/* {activeTab === TAB_FIAT && !hasCardSaved &&
-- 2.45.2 From 39b4dac86a0bab2026daf22fbd3af9c73fe02f64 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 24 Jul 2021 20:55:09 +0200 Subject: [PATCH 02/17] show superchats in order properly --- ui/component/livestreamComments/view.jsx | 44 +++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/ui/component/livestreamComments/view.jsx b/ui/component/livestreamComments/view.jsx index f4b073fef..43cd71bfc 100644 --- a/ui/component/livestreamComments/view.jsx +++ b/ui/component/livestreamComments/view.jsx @@ -22,6 +22,7 @@ type Props = { fetchingComments: boolean, doSuperChatList: (string) => void, superChats: Array, + superChatsReversed: Array, superChatsTotalAmount: number, myChannels: ?Array, }; @@ -38,15 +39,30 @@ export default function LivestreamComments(props: Props) { embed, doCommentSocketConnect, doCommentSocketDisconnect, - comments, + comments, // superchats in chronological format doCommentList, fetchingComments, doSuperChatList, - superChats, superChatsTotalAmount, myChannels, + superChats, // superchats organized by tip amount } = props; + let { superChatsReversed } = props; + + if (superChats) { + const clonedSuperchats = JSON.parse(JSON.stringify(superChats)); + + // sort by fiat first then by support amount + superChatsReversed = clonedSuperchats.sort(function(a,b) { + if (a.is_fiat === b.is_fiat) { + return b.support_amount - a.support_amount; + } else { + return (a.is_fiat === b.is_fiat) ? 0 : a.is_fiat ? -1 : 1; + } + }).reverse(); + } + const commentsRef = React.createRef(); const [scrollBottom, setScrollBottom] = React.useState(true); const [viewMode, setViewMode] = React.useState(VIEW_MODE_CHAT); @@ -71,6 +87,7 @@ export default function LivestreamComments(props: Props) { } React.useEffect(() => { + if (claimId) { doCommentList(uri, '', 1, 75); doSuperChatList(uri); @@ -132,6 +149,8 @@ export default function LivestreamComments(props: Props) {
{__('Live discussion')}
{superChatsTotalAmount > 0 && (
+ + {/* the superchats in chronological order button */}
)} + {/* top to bottom comment display */} {!fetchingComments && comments.length > 0 ? (
- {commentsToDisplay.map((comment) => ( + {viewMode === VIEW_MODE_CHAT && commentsToDisplay.map((comment) => ( ))} + + {viewMode === VIEW_MODE_SUPER_CHAT && superChatsReversed && superChatsReversed.map((comment) => ( + + ))} +
) : (
-- 2.45.2 From fb411c46f653f6c64ac5e824f71494da2c19734d Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 24 Jul 2021 22:32:51 +0200 Subject: [PATCH 03/17] scroll properly when switching tabs --- ui/component/livestreamComments/view.jsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ui/component/livestreamComments/view.jsx b/ui/component/livestreamComments/view.jsx index 43cd71bfc..2eb1cbcd5 100644 --- a/ui/component/livestreamComments/view.jsx +++ b/ui/component/livestreamComments/view.jsx @@ -156,10 +156,15 @@ export default function LivestreamComments(props: Props) { 'button-toggle--active': viewMode === VIEW_MODE_CHAT, })} label={__('Chat')} - onClick={() => setViewMode(VIEW_MODE_CHAT)} + onClick={function() { + setViewMode(VIEW_MODE_CHAT); + const livestreamCommentsDiv = document.getElementsByClassName('livestream__comments')[0] + const divHeight = livestreamCommentsDiv.scrollHeight; + livestreamCommentsDiv.scrollTop = divHeight; + }} /> - {/* the list by tip amount value button */} + {/* the button to show superchats listed by most to least support amount */}
)} @@ -236,7 +246,6 @@ export default function LivestreamComments(props: Props) { commentIsMine={comment.channel_id && isMyComment(comment.channel_id)} /> ))} - ) : (
-- 2.45.2 From df62e9c0db159244873093929fdfdefedba2e99d Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 24 Jul 2021 23:03:09 +0200 Subject: [PATCH 04/17] 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() { -- 2.45.2 From a60f2d19c322d1a923bed80d71b52548b8363ba9 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sun, 25 Jul 2021 20:03:54 +0200 Subject: [PATCH 05/17] sum up lbc amounts --- ui/component/livestreamComments/view.jsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ui/component/livestreamComments/view.jsx b/ui/component/livestreamComments/view.jsx index 6944cdfee..8d1574ee4 100644 --- a/ui/component/livestreamComments/view.jsx +++ b/ui/component/livestreamComments/view.jsx @@ -44,27 +44,27 @@ export default function LivestreamComments(props: Props) { doCommentList, fetchingComments, doSuperChatList, - superChatsTotalAmount, myChannels, superChats, // superchats organized by tip amount } = props; - let { superChatsReversed, superChatsFiatAmount } = props; - - superChatsFiatAmount = 0; + let { superChatsReversed, superChatsFiatAmount, superChatsTotalAmount } = props; + // sum total amounts for fiat tips and lbc tips if(superChats){ - console.log(superChats); let fiatAmount = 0; + let LBCAmount = 0; for(const superChat of superChats){ if(superChat.is_fiat){ fiatAmount = fiatAmount + superChat.support_amount; + } else { + LBCAmount = LBCAmount + superChat.support_amount; } } superChatsFiatAmount = fiatAmount; - + superChatsTotalAmount = LBCAmount; } // TODO: why doesn't this work? -- 2.45.2 From 4e07558c9b412885cba301ade97f9f99e55707fe Mon Sep 17 00:00:00 2001 From: Anthony Date: Sun, 25 Jul 2021 21:30:35 +0200 Subject: [PATCH 06/17] refactor code a bit remove why isnt this working bit --- ui/component/livestreamComments/view.jsx | 79 +++++++++--------------- 1 file changed, 30 insertions(+), 49 deletions(-) diff --git a/ui/component/livestreamComments/view.jsx b/ui/component/livestreamComments/view.jsx index 8d1574ee4..0ed35c9e3 100644 --- a/ui/component/livestreamComments/view.jsx +++ b/ui/component/livestreamComments/view.jsx @@ -50,55 +50,6 @@ export default function LivestreamComments(props: Props) { let { superChatsReversed, superChatsFiatAmount, superChatsTotalAmount } = props; - // sum total amounts for fiat tips and lbc tips - if(superChats){ - - let fiatAmount = 0; - let LBCAmount = 0; - for(const superChat of superChats){ - if(superChat.is_fiat){ - fiatAmount = fiatAmount + superChat.support_amount; - } else { - LBCAmount = LBCAmount + superChat.support_amount; - } - } - - superChatsFiatAmount = fiatAmount; - superChatsTotalAmount = LBCAmount; - } - - // 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)); - - // sort by fiat first then by support amount - superChatsReversed = clonedSuperchats.sort(function(a,b) { - if (a.is_fiat === b.is_fiat) { - return b.support_amount - a.support_amount; - } else { - return (a.is_fiat === b.is_fiat) ? 0 : a.is_fiat ? -1 : 1; - } - }).reverse(); - } - const commentsRef = React.createRef(); const [scrollBottom, setScrollBottom] = React.useState(true); const [viewMode, setViewMode] = React.useState(VIEW_MODE_CHAT); @@ -110,6 +61,36 @@ export default function LivestreamComments(props: Props) { const discussionElement = document.querySelector('.livestream__comments'); const commentElement = document.querySelector('.livestream-comment'); + // sum total amounts for fiat tips and lbc tips + if (superChats) { + let fiatAmount = 0; + let LBCAmount = 0; + for (const superChat of superChats) { + if (superChat.is_fiat) { + fiatAmount = fiatAmount + superChat.support_amount; + } else { + LBCAmount = LBCAmount + superChat.support_amount; + } + } + + superChatsFiatAmount = fiatAmount; + superChatsTotalAmount = LBCAmount; + } + + // array of superchats organized by fiat or not first, then support amount + if (superChats) { + const clonedSuperchats = JSON.parse(JSON.stringify(superChats)); + + // sort by fiat first then by support amount + superChatsReversed = clonedSuperchats.sort(function(a,b) { + if (a.is_fiat === b.is_fiat) { + return b.support_amount - a.support_amount; + } else { + return (a.is_fiat === b.is_fiat) ? 0 : a.is_fiat ? -1 : 1; + } + }).reverse(); + } + // todo: implement comment_list --mine in SDK so redux can grab with selectCommentIsMine function isMyComment(channelId: string) { if (myChannels != null && channelId != null) { -- 2.45.2 From 7097b4fdab96bacc8e812114e1424e0cdf6ef29a Mon Sep 17 00:00:00 2001 From: Anthony Date: Sun, 25 Jul 2021 21:34:37 +0200 Subject: [PATCH 07/17] bugfix cant tip fiat if no lbc balance --- ui/component/walletSendTip/view.jsx | 31 +++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/ui/component/walletSendTip/view.jsx b/ui/component/walletSendTip/view.jsx index 4f99fbbb4..4a87141c8 100644 --- a/ui/component/walletSendTip/view.jsx +++ b/ui/component/walletSendTip/view.jsx @@ -362,7 +362,7 @@ function WalletSendTip(props: Props) { return (
{/* if there is no LBC balance, show user frontend to get credits */} - {noBalance ? ( + {1 == 2 ? ( }}>Supporting content requires %lbc%} subtitle={ @@ -479,8 +479,10 @@ function WalletSendTip(props: Props) {
- ) : ( - <> + // only show the prompt to earn more if its lbc or boost tab and no balance + // otherwise you can show the full prompt + ) : (!((activeTab === TAB_LBC || activeTab === TAB_BOOST) && noBalance) + ? <>
@@ -591,7 +593,28 @@ function WalletSendTip(props: Props) { ) : (
{__('The payment will be made from your saved card')}
)} - + : <> + }}>Supporting content requires %lbc%} + subtitle={ + }}> + With %lbc%, you can send tips to your favorite creators, or help boost their content for more people to + see. + + } + actions={ +
+
+ } + /> ) } /> -- 2.45.2 From b2e990c9dde1b45fa817a7da8d84896bc7e7fe00 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sun, 25 Jul 2021 23:17:44 +0200 Subject: [PATCH 08/17] add toast when someone does a tip for a comment --- ui/component/commentCreate/view.jsx | 36 +++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/ui/component/commentCreate/view.jsx b/ui/component/commentCreate/view.jsx index 8e113f269..a7a0d64eb 100644 --- a/ui/component/commentCreate/view.jsx +++ b/ui/component/commentCreate/view.jsx @@ -131,6 +131,7 @@ export function CommentCreate(props: Props) { return; } + // if comment post didn't work, but tip was already made, try againt o create comment if (commentFailure && tipAmount === successTip.tipAmount) { handleCreateComment(successTip.txid); return; @@ -147,6 +148,21 @@ export function CommentCreate(props: Props) { const activeChannelName = activeChannelClaim && activeChannelClaim.name; const activeChannelId = activeChannelClaim && activeChannelClaim.claim_id; + // setup variables for tip API + let channelClaimId, tipChannelName; + // if there is a signing channel it's on a file + if (claim.signing_channel) { + channelClaimId = claim.signing_channel.claim_id; + tipChannelName = claim.signing_channel.name; + + // otherwise it's on the channel page + } else { + channelClaimId = claim.claim_id; + tipChannelName = claim.name; + } + + console.log(activeChannelClaim); + setIsSubmitting(true); if (activeTab === TAB_LBC) { @@ -160,6 +176,14 @@ export function CommentCreate(props: Props) { setTimeout(() => { handleCreateComment(txid); }, 1500); + + doToast({ + message: __("You sent %tipAmount% LBRY Credits as a tip to %tipChannelName%, I'm sure they appreciate it!", { + tipAmount: tipAmount, // force show decimal places + tipChannelName + }), + }); + setSuccessTip({ txid, tipAmount }); }, () => { @@ -168,18 +192,6 @@ export function CommentCreate(props: Props) { } ); } else { - // setup variables for tip API - let channelClaimId, tipChannelName; - // if there is a signing channel it's on a file - if (claim.signing_channel) { - channelClaimId = claim.signing_channel.claim_id; - tipChannelName = claim.signing_channel.name; - - // otherwise it's on the channel page - } else { - channelClaimId = claim.claim_id; - tipChannelName = claim.name; - } const sourceClaimId = claim.claim_id; const roundedAmount = Math.round(tipAmount * 100) / 100; -- 2.45.2 From b11caa82a39936bd99e70a2d21297b6464ffeccd Mon Sep 17 00:00:00 2001 From: Anthony Date: Sun, 25 Jul 2021 23:26:57 +0200 Subject: [PATCH 09/17] add error toast for card page --- ui/page/settingsStripeCard/view.jsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ui/page/settingsStripeCard/view.jsx b/ui/page/settingsStripeCard/view.jsx index 7fd138038..f222d4f6a 100644 --- a/ui/page/settingsStripeCard/view.jsx +++ b/ui/page/settingsStripeCard/view.jsx @@ -188,10 +188,15 @@ class SettingsStripeCard extends React.Component { // instantiate stripe elements setupStripe(); }); + // 500 error from the backend being down } else if (error === 'internal_apis_down') { var displayString = 'There was an error from the server, please let support know'; doToast({ message: displayString, isError: true }); } else { + // probably an error from stripe + var displayString = 'There was an error getting your card setup, please let support know'; + doToast({ message: displayString, isError: true }); + console.log('Unseen before error'); } }); -- 2.45.2 From e0e318fc46cb09f01266a48ef3e3e75044ed1a91 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sun, 25 Jul 2021 23:31:46 +0200 Subject: [PATCH 10/17] show error on account connection page --- ui/page/settingsStripeAccount/index.js | 7 +++++-- ui/page/settingsStripeAccount/view.jsx | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ui/page/settingsStripeAccount/index.js b/ui/page/settingsStripeAccount/index.js index 633726701..87eb38809 100644 --- a/ui/page/settingsStripeAccount/index.js +++ b/ui/page/settingsStripeAccount/index.js @@ -2,12 +2,15 @@ import { connect } from 'react-redux'; import { withRouter } from 'react-router'; import StripeAccountConnection from './view'; import { selectUser } from 'redux/selectors/user'; +import { doToast } from 'redux/actions/notifications'; // function that receives state parameter and returns object of functions that accept state const select = (state) => ({ user: selectUser(state), }); -// const perform = (dispatch) => ({}); +const perform = (dispatch) => ({ + doToast: (options) => dispatch(doToast(options)), +}); -export default withRouter(connect(select)(StripeAccountConnection)); +export default withRouter(connect(select, perform)(StripeAccountConnection)); diff --git a/ui/page/settingsStripeAccount/view.jsx b/ui/page/settingsStripeAccount/view.jsx index 4276ca306..febfef6f3 100644 --- a/ui/page/settingsStripeAccount/view.jsx +++ b/ui/page/settingsStripeAccount/view.jsx @@ -31,6 +31,7 @@ if (isDev) { type Props = { source: string, user: User, + doOpenModal: (string, {}) => void, }; type State = { @@ -68,6 +69,8 @@ class StripeAccountConnection extends React.Component { componentDidMount() { const { user } = this.props; + let doToast = this.props.doToast; + // $FlowFixMe this.experimentalUiEnabled = user && user.experimental_ui; @@ -165,9 +168,13 @@ class StripeAccountConnection extends React.Component { // get stripe link and set it on the frontend getAndSetAccountLink(true); } else { + // probably an error from stripe + var displayString = 'There was an error getting your account setup, please let support know'; + doToast({ message: displayString, isError: true }); // not an error from Beamer, throw it throw new Error(error); } + }); } -- 2.45.2 From f5794005a49601c9fc95d1ad4ed98466b8e82825 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sun, 25 Jul 2021 23:58:32 +0200 Subject: [PATCH 11/17] automatically truncate to two decimals --- ui/component/walletSendTip/view.jsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ui/component/walletSendTip/view.jsx b/ui/component/walletSendTip/view.jsx index 4a87141c8..c8acff5ea 100644 --- a/ui/component/walletSendTip/view.jsx +++ b/ui/component/walletSendTip/view.jsx @@ -314,7 +314,18 @@ function WalletSendTip(props: Props) { } function handleCustomPriceChange(event: SyntheticInputEvent<*>) { - const tipAmount = parseFloat(event.target.value); + let tipAmount = parseFloat(event.target.value); + + // allow maximum two decimalds + if (activeTab === TAB_FIAT) { + tipAmount = Math.round(tipAmount * 100) / 100; + } + + // TODO: add limit to 4 digits + // can also do setTipError('Maximum 1000') that way + if(tipAmount.length > 5 && tipAmount > 1000){ + tipAmount.length = 4 + } setCustomTipAmount(tipAmount); } -- 2.45.2 From a8c79672a1e70414eb1000ee2020b8656f8c3ca0 Mon Sep 17 00:00:00 2001 From: Anthony Date: Mon, 26 Jul 2021 20:51:41 +0200 Subject: [PATCH 12/17] close to working perfectly --- ui/component/walletSendTip/view.jsx | 62 ++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/ui/component/walletSendTip/view.jsx b/ui/component/walletSendTip/view.jsx index c8acff5ea..43cf4aa02 100644 --- a/ui/component/walletSendTip/view.jsx +++ b/ui/component/walletSendTip/view.jsx @@ -313,21 +313,63 @@ function WalletSendTip(props: Props) { } } + var countDecimals = function(value) { + var text = value.toString(); + var index = text.indexOf('.'); + return (text.length - index - 1); + } + function handleCustomPriceChange(event: SyntheticInputEvent<*>) { - let tipAmount = parseFloat(event.target.value); - // allow maximum two decimalds + console.log(event.target.value); + + let tipAmountAsString = event.target.value; + + let tipAmount = parseFloat(tipAmountAsString); + + // allow maximum two decimals if (activeTab === TAB_FIAT) { - tipAmount = Math.round(tipAmount * 100) / 100; - } - // TODO: add limit to 4 digits - // can also do setTipError('Maximum 1000') that way - if(tipAmount.length > 5 && tipAmount > 1000){ - tipAmount.length = 4 - } + console.log(tipAmount); - setCustomTipAmount(tipAmount); + console.log(Number.isNaN(tipAmount)) + + if (Number.isNaN(tipAmount)) { + setCustomTipAmount(''); + } + + + const howManyDecimals = countDecimals(tipAmountAsString); + + console.log('how many decimals'); + console.log(howManyDecimals) + + if (howManyDecimals > 2) { + tipAmount = Math.floor(tipAmount * 100) / 100; + // setTipError('Value can only have two decimal places'); + } + // else { + // tipAmount = ((tipAmount * 100) / 100).toFixed(2); + // } + + + // console.log(howManyDecimals); + + console.log(tipAmount); + + const howManyDigits = Math.trunc(tipAmount).toString().length; + + if (howManyDigits > 4 && tipAmount !== 1000) { + setTipError('Value must be below 1000 dollars'); + } else if (tipAmount > 1000) { + setTipError('Value must be below 1000 dollars'); + setCustomTipAmount(tipAmount); + } else { + setCustomTipAmount(tipAmount); + } + } else { + setCustomTipAmount(tipAmount); + } } function buildButtonText() { -- 2.45.2 From aeedd443a7e3362345e644c200ea4139dbc5ce5e Mon Sep 17 00:00:00 2001 From: Anthony Date: Mon, 26 Jul 2021 21:07:16 +0200 Subject: [PATCH 13/17] show decimals value better --- ui/component/walletSendTip/view.jsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ui/component/walletSendTip/view.jsx b/ui/component/walletSendTip/view.jsx index 43cf4aa02..ac5c6727e 100644 --- a/ui/component/walletSendTip/view.jsx +++ b/ui/component/walletSendTip/view.jsx @@ -360,9 +360,9 @@ function WalletSendTip(props: Props) { const howManyDigits = Math.trunc(tipAmount).toString().length; if (howManyDigits > 4 && tipAmount !== 1000) { - setTipError('Value must be below 1000 dollars'); + setTipError('Amount cannot be over 1000 dollars'); } else if (tipAmount > 1000) { - setTipError('Value must be below 1000 dollars'); + setTipError('Amount cannot be over 1000 dollars'); setCustomTipAmount(tipAmount); } else { setCustomTipAmount(tipAmount); @@ -384,8 +384,14 @@ function WalletSendTip(props: Props) { return false; } + function convertToTwoDecimals(number){ + return (Math.round(number * 100) / 100).toFixed(2); + } + + const amountToShow = activeTab === TAB_FIAT ? convertToTwoDecimals(tipAmount) : tipAmount; + // if it's a valid number display it, otherwise do an empty string - const displayAmount = !isNan(tipAmount) ? tipAmount : ''; + const displayAmount = !isNan(tipAmount) ? amountToShow : ''; if (activeTab === TAB_BOOST) { return (claimIsMine ? __('Boost Your %claimTypeText%', {claimTypeText}) : __('Boost This %claimTypeText%', {claimTypeText})); @@ -517,7 +523,7 @@ function WalletSendTip(props: Props) {
{setConfirmLabel()}
- {activeTab === TAB_FIAT ?

$ {tipAmount}

: } + {activeTab === TAB_FIAT ?

$ {(Math.round(tipAmount * 100) / 100).toFixed(2)}

: }
-- 2.45.2 From 1a30783835ca510e472ca1cccc6b20fb83961da8 Mon Sep 17 00:00:00 2001 From: Anthony Date: Mon, 26 Jul 2021 21:40:01 +0200 Subject: [PATCH 14/17] increase size of input value --- ui/component/walletSendTip/view.jsx | 4 ++++ ui/scss/component/_form-field.scss | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ui/component/walletSendTip/view.jsx b/ui/component/walletSendTip/view.jsx index ac5c6727e..0e3d58890 100644 --- a/ui/component/walletSendTip/view.jsx +++ b/ui/component/walletSendTip/view.jsx @@ -601,6 +601,7 @@ function WalletSendTip(props: Props) { {__('Custom support amount')}{' '} @@ -620,6 +621,9 @@ function WalletSendTip(props: Props) { min="0" step="any" type="number" + style={{ + width: activeTab === TAB_FIAT ? '99px' : '160px', + }} placeholder="1.23" value={customTipAmount} onChange={(event) => handleCustomPriceChange(event)} diff --git a/ui/scss/component/_form-field.scss b/ui/scss/component/_form-field.scss index 5c4a3a2c8..2b4b161d8 100644 --- a/ui/scss/component/_form-field.scss +++ b/ui/scss/component/_form-field.scss @@ -404,9 +404,9 @@ fieldset-group { } } -.form-field--price-amount { - max-width: 6em; -} + //.form-field--price-amount { + // max-width: 6em; + //} .form-field--price-amount--auto { width: auto; -- 2.45.2 From e84c2c91c4df83dc7af99876c5172cb8d9e7e0d9 Mon Sep 17 00:00:00 2001 From: Anthony Date: Mon, 26 Jul 2021 21:55:21 +0200 Subject: [PATCH 15/17] one bug left but almost working perfectly --- ui/component/walletSendTip/view.jsx | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/ui/component/walletSendTip/view.jsx b/ui/component/walletSendTip/view.jsx index 0e3d58890..c5ce96f1a 100644 --- a/ui/component/walletSendTip/view.jsx +++ b/ui/component/walletSendTip/view.jsx @@ -321,41 +321,22 @@ function WalletSendTip(props: Props) { function handleCustomPriceChange(event: SyntheticInputEvent<*>) { - console.log(event.target.value); - let tipAmountAsString = event.target.value; let tipAmount = parseFloat(tipAmountAsString); + const howManyDecimals = countDecimals(tipAmountAsString); + // allow maximum two decimals if (activeTab === TAB_FIAT) { - console.log(tipAmount); - - console.log(Number.isNaN(tipAmount)) - if (Number.isNaN(tipAmount)) { setCustomTipAmount(''); } - - const howManyDecimals = countDecimals(tipAmountAsString); - - console.log('how many decimals'); - console.log(howManyDecimals) - if (howManyDecimals > 2) { tipAmount = Math.floor(tipAmount * 100) / 100; - // setTipError('Value can only have two decimal places'); } - // else { - // tipAmount = ((tipAmount * 100) / 100).toFixed(2); - // } - - - // console.log(howManyDecimals); - - console.log(tipAmount); const howManyDigits = Math.trunc(tipAmount).toString().length; @@ -368,6 +349,11 @@ function WalletSendTip(props: Props) { setCustomTipAmount(tipAmount); } } else { + if (howManyDecimals > 9) { + tipAmount = Number(tipAmount.toString().match(/^-?\d+(?:\.\d{0,8})?/)[0]); + + setTipError('Please only use up to 8 decimals') + } setCustomTipAmount(tipAmount); } } @@ -601,7 +587,6 @@ function WalletSendTip(props: Props) { {__('Custom support amount')}{' '} -- 2.45.2 From 3ed70ae3d12bc74305960d45028953d4e944093b Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 27 Jul 2021 19:15:15 +0200 Subject: [PATCH 16/17] reverse so newest transactions come first --- ui/page/settingsStripeAccount/view.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/page/settingsStripeAccount/view.jsx b/ui/page/settingsStripeAccount/view.jsx index febfef6f3..dc21de5b3 100644 --- a/ui/page/settingsStripeAccount/view.jsx +++ b/ui/page/settingsStripeAccount/view.jsx @@ -130,7 +130,7 @@ class StripeAccountConnection extends React.Component { ).then((accountListResponse: any) => { // TODO type this that.setState({ - accountTransactions: accountListResponse, + accountTransactions: accountListResponse.reverse(), }); console.log(accountListResponse); @@ -303,7 +303,7 @@ class StripeAccountConnection extends React.Component { {accountTransactions && - accountTransactions.reverse().map((transaction) => ( + accountTransactions.map((transaction) => ( {moment(transaction.created_at).format('LLL')} -- 2.45.2 From 15e58156cc954d2964b74237994cb72afed1e76f Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 27 Jul 2021 19:48:57 +0200 Subject: [PATCH 17/17] fixing bug caused by floating point precision --- ui/component/commentCreate/view.jsx | 4 ++-- ui/component/walletSendTip/view.jsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/component/commentCreate/view.jsx b/ui/component/commentCreate/view.jsx index a7a0d64eb..3d78b4133 100644 --- a/ui/component/commentCreate/view.jsx +++ b/ui/component/commentCreate/view.jsx @@ -199,8 +199,8 @@ export function CommentCreate(props: Props) { Lbryio.call( 'customer', 'tip', - { - amount: 100 * roundedAmount, // convert from dollars to cents + { // round to deal with floating point precision + amount: Math.round(100 * roundedAmount), // convert from dollars to cents creator_channel_name: tipChannelName, // creator_channel_name creator_channel_claim_id: channelClaimId, tipper_channel_name: activeChannelName, diff --git a/ui/component/walletSendTip/view.jsx b/ui/component/walletSendTip/view.jsx index c5ce96f1a..76f75851d 100644 --- a/ui/component/walletSendTip/view.jsx +++ b/ui/component/walletSendTip/view.jsx @@ -273,8 +273,8 @@ function WalletSendTip(props: Props) { Lbryio.call( 'customer', 'tip', - { - amount: 100 * tipAmount, // convert from dollars to cents + { // round to fix issues with floating point numbers + amount: Math.round(100 * tipAmount), // convert from dollars to cents creator_channel_name: tipChannelName, // creator_channel_name creator_channel_claim_id: channelClaimId, tipper_channel_name: sendAnonymously ? '' : activeChannelName, -- 2.45.2