From 4cd9062cfc937044417efe06e44611dc95528367 Mon Sep 17 00:00:00 2001 From: Anthony Date: Thu, 19 Aug 2021 21:50:44 +0200 Subject: [PATCH] make fiat balance programatic again --- ui/component/walletBalance/view.jsx | 27 ++---------- ui/component/walletFiatBalance/view.jsx | 56 ++++++++++++++++++++----- ui/page/wallet/view.jsx | 11 +---- 3 files changed, 49 insertions(+), 45 deletions(-) diff --git a/ui/component/walletBalance/view.jsx b/ui/component/walletBalance/view.jsx index b30dc0760..4b6c06ca5 100644 --- a/ui/component/walletBalance/view.jsx +++ b/ui/component/walletBalance/view.jsx @@ -11,6 +11,7 @@ import LbcSymbol from 'component/common/lbc-symbol'; import I18nMessage from 'component/i18nMessage'; import { formatNumberWithCommas } from 'util/number'; import Icon from 'component/common/icon'; +import WalletFiatBalance from 'component/walletFiatBalance'; type Props = { balance: number, @@ -184,30 +185,8 @@ const WalletBalance = (props: Props) => { } /> - 32 USD} - subtitle={32 && - - This is your pending balance that will be automatically sent to your bank account - - } - actions={ - <> -

- $32 Total Received Tips -

- -

- $0 Withdrawn -

- -
-
- - } - /> + {/* fiat balance card */} + ); }; diff --git a/ui/component/walletFiatBalance/view.jsx b/ui/component/walletFiatBalance/view.jsx index a91b5ecd7..a58373e7f 100644 --- a/ui/component/walletFiatBalance/view.jsx +++ b/ui/component/walletFiatBalance/view.jsx @@ -6,32 +6,66 @@ import Button from 'component/button'; import Card from 'component/common/card'; import Icon from 'component/common/icon'; import I18nMessage from 'component/i18nMessage'; +import { Lbryio } from 'lbryinc'; +import { STRIPE_PUBLIC_KEY } from 'config'; -type Props = { - accountDetails: any, -}; +let stripeEnvironment = 'test'; +// if the key contains pk_live it's a live key +// update the environment for the calls to the backend to indicate which environment to hit +if (STRIPE_PUBLIC_KEY.indexOf('pk_live') > -1) { + stripeEnvironment = 'live'; +} const WalletBalance = (props: Props) => { - const { - accountDetails, - } = props; + const [accountStatusResponse, setAccountStatusResponse] = React.useState(); + + function getAccountStatus() { + return Lbryio.call( + 'account', + 'status', + { + environment: stripeEnvironment, + }, + 'post' + ); + } + + // calculate account transactions section + React.useEffect(() => { + (async function () { + try { + if (!stripeEnvironment) { + return; + } + const response = await getAccountStatus(); + + setAccountStatusResponse(response); + + } catch (err) { + console.log(err); + } + })(); + }, [stripeEnvironment]); return ( <>{{(accountDetails && ((accountDetails.total_received_unpaid - accountDetails.total_paid_out) / 100)) || 0} USD} - subtitle={accountDetails && accountDetails.total_received_unpaid > 0 && + title={<>{(accountStatusResponse && ((accountStatusResponse.total_received_unpaid - accountStatusResponse.total_paid_out) / 100)) || 0} USD} + subtitle={accountStatusResponse && accountStatusResponse.total_received_unpaid > 0 ? ( This is your pending balance that will be automatically sent to your bank account - + ) : ( + + When you begin to receive tips your balance will be updated here + ) } actions={ <>

- ${(accountDetails && (accountDetails.total_received_unpaid / 100)) || 0} Total Received Tips + ${(accountStatusResponse && (accountStatusResponse.total_received_unpaid / 100)) || 0} Total Received Tips

- ${(accountDetails && (accountDetails.total_paid_out / 100)) || 0} Withdrawn + ${(accountStatusResponse && (accountStatusResponse.total_paid_out / 100)) || 0} Withdrawn

diff --git a/ui/page/wallet/view.jsx b/ui/page/wallet/view.jsx index 011aeb332..cc4d8af16 100644 --- a/ui/page/wallet/view.jsx +++ b/ui/page/wallet/view.jsx @@ -74,16 +74,7 @@ const WalletPage = (props: Props) => { push(url); } - function getAccountStatus() { - return Lbryio.call( - 'account', - 'status', - { - environment: stripeEnvironment, - }, - 'post' - ); - } + // @endif const { totalBalance } = props; const showIntro = totalBalance === 0;