2020-04-10 19:31:36 +02:00
|
|
|
// @flow
|
2019-06-17 22:32:38 +02:00
|
|
|
import React from 'react';
|
2021-08-13 19:59:43 +02:00
|
|
|
import { useHistory } from 'react-router';
|
2019-06-17 22:32:38 +02:00
|
|
|
import WalletBalance from 'component/walletBalance';
|
2020-04-10 19:31:36 +02:00
|
|
|
import TxoList from 'component/txoList';
|
2019-06-17 22:32:38 +02:00
|
|
|
import Page from 'component/page';
|
2021-08-13 19:59:43 +02:00
|
|
|
import * as PAGES from 'constants/pages';
|
2020-06-01 19:03:19 +02:00
|
|
|
import Spinner from 'component/spinner';
|
2020-08-26 19:19:03 +02:00
|
|
|
import YrblWalletEmpty from 'component/yrblWalletEmpty';
|
2021-08-13 19:59:43 +02:00
|
|
|
import { Tabs, TabList, Tab, TabPanels, TabPanel } from 'component/common/tabs';
|
|
|
|
|
|
|
|
const TAB_QUERY = 'tab';
|
|
|
|
|
|
|
|
const TABS = {
|
|
|
|
LBRY_CREDITS_TAB: 'credits',
|
|
|
|
ACCOUNT_HISTORY: 'fiat-account-history',
|
|
|
|
PAYMENT_HISTORY: 'fiat-payment-history',
|
|
|
|
};
|
|
|
|
|
2020-04-10 19:31:36 +02:00
|
|
|
type Props = {
|
2021-07-03 20:32:06 +02:00
|
|
|
history: { action: string, push: (string) => void, replace: (string) => void },
|
2020-04-10 19:31:36 +02:00
|
|
|
location: { search: string, pathname: string },
|
2021-02-05 18:46:07 +01:00
|
|
|
totalBalance: ?number,
|
2020-04-10 19:31:36 +02:00
|
|
|
};
|
2019-06-17 22:32:38 +02:00
|
|
|
|
2020-04-10 19:31:36 +02:00
|
|
|
const WalletPage = (props: Props) => {
|
2021-08-13 19:59:43 +02:00
|
|
|
const {
|
|
|
|
location: { search },
|
|
|
|
push,
|
|
|
|
} = useHistory();
|
|
|
|
|
|
|
|
// @if TARGET='web'
|
|
|
|
const urlParams = new URLSearchParams(search);
|
|
|
|
|
|
|
|
const currentView = urlParams.get(TAB_QUERY) || TABS.LBRY_CREDITS_TAB;
|
|
|
|
|
|
|
|
let tabIndex;
|
|
|
|
switch (currentView) {
|
|
|
|
case TABS.LBRY_CREDITS_TAB:
|
|
|
|
tabIndex = 0;
|
|
|
|
break;
|
|
|
|
case TABS.PAYMENT_HISTORY:
|
|
|
|
tabIndex = 1;
|
|
|
|
break;
|
|
|
|
case TABS.ACCOUNT_HISTORY:
|
|
|
|
tabIndex = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tabIndex = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTabChange(newTabIndex) {
|
|
|
|
let url = `/$/${PAGES.WALLET}?`;
|
|
|
|
|
|
|
|
if (newTabIndex === 0) {
|
|
|
|
url += `${TAB_QUERY}=${TABS.LBRY_CREDITS_TAB}`;
|
|
|
|
} else if (newTabIndex === 1) {
|
|
|
|
url += `${TAB_QUERY}=${TABS.PAYMENT_HISTORY}`;
|
|
|
|
} else if (newTabIndex === 2) {
|
|
|
|
url += `${TAB_QUERY}=${TABS.ACCOUNT_HISTORY}`;
|
|
|
|
} else {
|
|
|
|
url += `${TAB_QUERY}=${TABS.LBRY_CREDITS_TAB}`;
|
|
|
|
}
|
|
|
|
push(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @endif
|
|
|
|
|
|
|
|
const { totalBalance } = props;
|
2021-02-05 18:46:07 +01:00
|
|
|
const showIntro = totalBalance === 0;
|
|
|
|
const loading = totalBalance === undefined;
|
2020-04-10 19:31:36 +02:00
|
|
|
|
|
|
|
return (
|
2021-08-13 19:59:43 +02:00
|
|
|
<>
|
2021-08-18 20:06:12 +02:00
|
|
|
{/* @if TARGET='web' */}
|
|
|
|
<Page>
|
|
|
|
<Tabs onChange={onTabChange} index={tabIndex}>
|
|
|
|
<TabList className="tabs__list--collection-edit-page">
|
|
|
|
<Tab>{__('Balance')}</Tab>
|
|
|
|
<Tab>{__('Transactions')}</Tab>
|
|
|
|
</TabList>
|
|
|
|
<TabPanels>
|
|
|
|
{/* balances for lbc and fiat */}
|
|
|
|
<TabPanel>
|
|
|
|
<WalletBalance />
|
|
|
|
</TabPanel>
|
|
|
|
{/* transactions panel */}
|
|
|
|
<TabPanel>
|
|
|
|
<div className="section card-stack">
|
|
|
|
<div className="lbc-transactions">
|
|
|
|
{/* if the transactions are loading */}
|
|
|
|
{loading && (
|
|
|
|
<div className="main--empty">
|
|
|
|
<Spinner delayed />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{/* when the transactions are finished loading */}
|
|
|
|
{!loading && (
|
|
|
|
<>
|
|
|
|
{showIntro ? (
|
|
|
|
<YrblWalletEmpty includeWalletLink />
|
|
|
|
) : (
|
|
|
|
<div className="card-stack">
|
|
|
|
<TxoList search={search} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
2021-08-13 19:59:43 +02:00
|
|
|
</div>
|
2021-08-18 20:06:12 +02:00
|
|
|
</div>
|
|
|
|
</TabPanel>
|
|
|
|
</TabPanels>
|
|
|
|
</Tabs>
|
|
|
|
</Page>
|
|
|
|
{/* @endif */}
|
|
|
|
{/* @if TARGET='app' */}
|
|
|
|
<Page>
|
|
|
|
{loading && (
|
|
|
|
<div className="main--empty">
|
|
|
|
<Spinner delayed />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{!loading && (
|
|
|
|
<>
|
|
|
|
{showIntro ? (
|
|
|
|
<YrblWalletEmpty includeWalletLink />
|
|
|
|
) : (
|
|
|
|
<div className="card-stack">
|
|
|
|
<TxoList search={search} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Page>
|
|
|
|
{/* @endif */}
|
2021-08-13 19:59:43 +02:00
|
|
|
</>
|
2020-04-10 19:31:36 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-08-13 19:59:43 +02:00
|
|
|
export default WalletPage;
|