fix transactions bug

This commit is contained in:
Anthony 2021-08-13 17:59:50 +02:00
parent bd2d8c413f
commit 7281e6cd71
No known key found for this signature in database
GPG key ID: C386D3C93D50E356

View file

@ -14,7 +14,6 @@ import YrblWalletEmpty from 'component/yrblWalletEmpty';
import { Lbryio } from 'lbryinc'; import { Lbryio } from 'lbryinc';
import { SIMPLE_SITE, STRIPE_PUBLIC_KEY } from 'config'; import { SIMPLE_SITE, STRIPE_PUBLIC_KEY } from 'config';
import { Tabs, TabList, Tab, TabPanels, TabPanel } from 'component/common/tabs'; import { Tabs, TabList, Tab, TabPanels, TabPanel } from 'component/common/tabs';
import Card from 'component/common/card';
import { PAGE_VIEW_QUERY } from '../channel/view'; import { PAGE_VIEW_QUERY } from '../channel/view';
const TAB_QUERY = 'tab'; const TAB_QUERY = 'tab';
@ -44,6 +43,7 @@ const WalletPage = (props: Props) => {
push, push,
} = useHistory(); } = useHistory();
// @if TARGET='web'
const urlParams = new URLSearchParams(search); const urlParams = new URLSearchParams(search);
const currentView = urlParams.get(TAB_QUERY) || TABS.LBRY_CREDITS_TAB; const currentView = urlParams.get(TAB_QUERY) || TABS.LBRY_CREDITS_TAB;
@ -82,7 +82,6 @@ const WalletPage = (props: Props) => {
const [accountStatusResponse, setAccountStatusResponse] = React.useState(); const [accountStatusResponse, setAccountStatusResponse] = React.useState();
const [accountTransactionResponse, setAccountTransactionResponse] = React.useState([]); const [accountTransactionResponse, setAccountTransactionResponse] = React.useState([]);
const [customerTransactions, setCustomerTransactions] = React.useState([]); const [customerTransactions, setCustomerTransactions] = React.useState([]);
const [totalTippedAmount, setTotalTippedAmount] = React.useState(0);
function getPaymentHistory() { function getPaymentHistory() {
return Lbryio.call( return Lbryio.call(
@ -142,14 +141,6 @@ const WalletPage = (props: Props) => {
// get card payments customer has made // get card payments customer has made
const customerTransactionResponse = await getPaymentHistory(); const customerTransactionResponse = await getPaymentHistory();
let totalTippedAmount = 0;
for (const transaction of customerTransactionResponse) {
totalTippedAmount = totalTippedAmount + transaction.tipped_amount;
}
setTotalTippedAmount(totalTippedAmount / 100);
setCustomerTransactions(customerTransactionResponse); setCustomerTransactions(customerTransactionResponse);
} catch (err) { } catch (err) {
console.log(err); console.log(err);
@ -157,14 +148,15 @@ const WalletPage = (props: Props) => {
})(); })();
}, []); }, []);
const { location, totalBalance } = props; // @endif
// const { search } = location;
const { totalBalance } = props;
const showIntro = totalBalance === 0; const showIntro = totalBalance === 0;
const loading = totalBalance === undefined; const loading = totalBalance === undefined;
// @if TARGET='web'
return ( return (
<Page> <Page>
<Tabs onChange={onTabChange} index={tabIndex}> <Tabs onChange={onTabChange} index={tabIndex}>
<TabList className="tabs__list--collection-edit-page"> <TabList className="tabs__list--collection-edit-page">
<Tab>{__('LBRY Credits')}</Tab> <Tab>{__('LBRY Credits')}</Tab>
@ -205,7 +197,7 @@ const WalletPage = (props: Props) => {
</TabPanel> </TabPanel>
<TabPanel> <TabPanel>
<div className="section card-stack"> <div className="section card-stack">
<WalletFiatPaymentBalance transactions={customerTransactions} totalTippedAmount={totalTippedAmount} accountDetails={accountStatusResponse} /> <WalletFiatPaymentBalance transactions={customerTransactions} accountDetails={accountStatusResponse} />
<WalletFiatPaymentHistory transactions={customerTransactions} /> <WalletFiatPaymentHistory transactions={customerTransactions} />
</div> </div>
</TabPanel> </TabPanel>
@ -213,6 +205,32 @@ const WalletPage = (props: Props) => {
</Tabs> </Tabs>
</Page> </Page>
); );
// @endif
// @if TARGET='app'
// eslint-disable-next-line no-unreachable
return (
<Page>
{loading && (
<div className="main--empty">
<Spinner delayed />
</div>
)}
{!loading && (
<>
{showIntro ? (
<YrblWalletEmpty includeWalletLink />
) : (
<div className="card-stack">
<WalletBalance />
<TxoList search={search} />
</div>
)}
</>
)}
</Page>
);
// @endif
}; };
export default WalletPage; export default WalletPage;