make fiat balance programatic again
This commit is contained in:
parent
29cec219d3
commit
4cd9062cfc
3 changed files with 49 additions and 45 deletions
|
@ -11,6 +11,7 @@ import LbcSymbol from 'component/common/lbc-symbol';
|
||||||
import I18nMessage from 'component/i18nMessage';
|
import I18nMessage from 'component/i18nMessage';
|
||||||
import { formatNumberWithCommas } from 'util/number';
|
import { formatNumberWithCommas } from 'util/number';
|
||||||
import Icon from 'component/common/icon';
|
import Icon from 'component/common/icon';
|
||||||
|
import WalletFiatBalance from 'component/walletFiatBalance';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
balance: number,
|
balance: number,
|
||||||
|
@ -184,30 +185,8 @@ const WalletBalance = (props: Props) => {
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Card
|
{/* fiat balance card */}
|
||||||
title={<><Icon size={18} icon={ICONS.FINANCE} />32 USD</>}
|
<WalletFiatBalance />
|
||||||
subtitle={32 &&
|
|
||||||
<I18nMessage>
|
|
||||||
This is your pending balance that will be automatically sent to your bank account
|
|
||||||
</I18nMessage>
|
|
||||||
}
|
|
||||||
actions={
|
|
||||||
<>
|
|
||||||
<h2 className="section__title--small">
|
|
||||||
$32 Total Received Tips
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<h2 className="section__title--small">
|
|
||||||
$0 Withdrawn
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<div className="section__actions">
|
|
||||||
<Button button="secondary" label={__('Manage Accounts')} icon={ICONS.SETTINGS} navigate={`/$/${PAGES.SETTINGS_STRIPE_ACCOUNT}`} />
|
|
||||||
<Button button="secondary" label={__('Manage Cards')} icon={ICONS.SETTINGS} navigate={`/$/${PAGES.SETTINGS_STRIPE_CARD}`} />
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,32 +6,66 @@ import Button from 'component/button';
|
||||||
import Card from 'component/common/card';
|
import Card from 'component/common/card';
|
||||||
import Icon from 'component/common/icon';
|
import Icon from 'component/common/icon';
|
||||||
import I18nMessage from 'component/i18nMessage';
|
import I18nMessage from 'component/i18nMessage';
|
||||||
|
import { Lbryio } from 'lbryinc';
|
||||||
|
import { STRIPE_PUBLIC_KEY } from 'config';
|
||||||
|
|
||||||
type Props = {
|
let stripeEnvironment = 'test';
|
||||||
accountDetails: any,
|
// 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 WalletBalance = (props: Props) => {
|
||||||
const {
|
const [accountStatusResponse, setAccountStatusResponse] = React.useState();
|
||||||
accountDetails,
|
|
||||||
} = props;
|
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 (
|
return (
|
||||||
<>{<Card
|
<>{<Card
|
||||||
title={<><Icon size={18} icon={ICONS.FINANCE} />{(accountDetails && ((accountDetails.total_received_unpaid - accountDetails.total_paid_out) / 100)) || 0} USD</>}
|
title={<><Icon size={18} icon={ICONS.FINANCE} />{(accountStatusResponse && ((accountStatusResponse.total_received_unpaid - accountStatusResponse.total_paid_out) / 100)) || 0} USD</>}
|
||||||
subtitle={accountDetails && accountDetails.total_received_unpaid > 0 &&
|
subtitle={accountStatusResponse && accountStatusResponse.total_received_unpaid > 0 ? (
|
||||||
<I18nMessage>
|
<I18nMessage>
|
||||||
This is your pending balance that will be automatically sent to your bank account
|
This is your pending balance that will be automatically sent to your bank account
|
||||||
</I18nMessage>
|
</I18nMessage>) : (
|
||||||
|
<I18nMessage>
|
||||||
|
When you begin to receive tips your balance will be updated here
|
||||||
|
</I18nMessage>)
|
||||||
}
|
}
|
||||||
actions={
|
actions={
|
||||||
<>
|
<>
|
||||||
<h2 className="section__title--small">
|
<h2 className="section__title--small">
|
||||||
${(accountDetails && (accountDetails.total_received_unpaid / 100)) || 0} Total Received Tips
|
${(accountStatusResponse && (accountStatusResponse.total_received_unpaid / 100)) || 0} Total Received Tips
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<h2 className="section__title--small">
|
<h2 className="section__title--small">
|
||||||
${(accountDetails && (accountDetails.total_paid_out / 100)) || 0} Withdrawn
|
${(accountStatusResponse && (accountStatusResponse.total_paid_out / 100)) || 0} Withdrawn
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<div className="section__actions">
|
<div className="section__actions">
|
||||||
|
|
|
@ -74,16 +74,7 @@ const WalletPage = (props: Props) => {
|
||||||
push(url);
|
push(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAccountStatus() {
|
// @endif
|
||||||
return Lbryio.call(
|
|
||||||
'account',
|
|
||||||
'status',
|
|
||||||
{
|
|
||||||
environment: stripeEnvironment,
|
|
||||||
},
|
|
||||||
'post'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { totalBalance } = props;
|
const { totalBalance } = props;
|
||||||
const showIntro = totalBalance === 0;
|
const showIntro = totalBalance === 0;
|
||||||
|
|
Loading…
Reference in a new issue