1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-06-26 11:16:51 +02:00

fetch history published/shares/transactions/downloads using url account id and dynamic compute tab

This commit is contained in:
Bogdan Fazakas 2021-08-04 18:30:14 +03:00
parent 86a8c3b374
commit e998a989b5
7 changed files with 63 additions and 31 deletions

View File

@ -129,12 +129,13 @@ const columnsMinimal = [columns[0], columns[3]]
export default function PoolTransactions({ export default function PoolTransactions({
poolAddress, poolAddress,
minimal minimal,
accountId
}: { }: {
poolAddress?: string poolAddress?: string
minimal?: boolean minimal?: boolean
accountId: string
}): ReactElement { }): ReactElement {
const { accountId } = useWeb3()
const [logs, setLogs] = useState<PoolTransaction[]>() const [logs, setLogs] = useState<PoolTransaction[]>()
const [isLoading, setIsLoading] = useState<boolean>(false) const [isLoading, setIsLoading] = useState<boolean>(false)
const { chainIds } = useUserPreferences() const { chainIds } = useUserPreferences()

View File

@ -386,7 +386,11 @@ export default function Pool(): ReactElement {
{accountId && ( {accountId && (
<AssetActionHistoryTable title="Your Pool Transactions"> <AssetActionHistoryTable title="Your Pool Transactions">
<PoolTransactions poolAddress={price?.address} minimal /> <PoolTransactions
accountId={accountId}
poolAddress={price?.address}
minimal
/>
</AssetActionHistoryTable> </AssetActionHistoryTable>
)} )}
</> </>

View File

@ -65,8 +65,11 @@ const columns = [
} }
] ]
export default function ComputeDownloads(): ReactElement { export default function ComputeDownloads({
const { accountId } = useWeb3() accountId
}: {
accountId: string
}): ReactElement {
const { appConfig } = useSiteMetadata() const { appConfig } = useSiteMetadata()
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
const [orders, setOrders] = useState<DownloadedAssets[]>() const [orders, setOrders] = useState<DownloadedAssets[]>()

View File

@ -154,8 +154,11 @@ const columns = [
} }
] ]
export default function PoolShares(): ReactElement { export default function PoolShares({
const { accountId } = useWeb3() accountId
}: {
accountId: string
}): ReactElement {
const [assets, setAssets] = useState<Asset[]>() const [assets, setAssets] = useState<Asset[]>()
const [loading, setLoading] = useState<boolean>(false) const [loading, setLoading] = useState<boolean>(false)
const [data, setData] = useState<PoolShare[]>() const [data, setData] = useState<PoolShare[]>()

View File

@ -11,8 +11,11 @@ import { useWeb3 } from '../../../../providers/Web3'
import { useSiteMetadata } from '../../../../hooks/useSiteMetadata' import { useSiteMetadata } from '../../../../hooks/useSiteMetadata'
import { useUserPreferences } from '../../../../providers/UserPreferences' import { useUserPreferences } from '../../../../providers/UserPreferences'
export default function PublishedList(): ReactElement { export default function PublishedList({
const { accountId } = useWeb3() accountId
}: {
accountId: string
}): ReactElement {
const { appConfig } = useSiteMetadata() const { appConfig } = useSiteMetadata()
const { chainIds } = useUserPreferences() const { chainIds } = useUserPreferences()

View File

@ -8,25 +8,34 @@ import ComputeJobs from './ComputeJobs'
import styles from './index.module.css' import styles from './index.module.css'
import { useUserPreferences } from '../../../../providers/UserPreferences' import { useUserPreferences } from '../../../../providers/UserPreferences'
import OceanProvider from '../../../../providers/Ocean' import OceanProvider from '../../../../providers/Ocean'
import { useWeb3 } from '../../../../providers/Web3'
const tabs = [ interface HistoryTab {
{ title: string
title: 'Published', content: JSX.Element
content: <PublishedList /> }
},
{ function getTabs(accountIdentifier: string): HistoryTab[] {
title: 'Pool Shares', const { accountId } = useWeb3()
content: <PoolShares /> const defaultTabs: HistoryTab[] = [
}, {
{ title: 'Published',
title: 'Pool Transactions', content: <PublishedList accountId={accountIdentifier} />
content: <PoolTransactions /> },
}, {
{ title: 'Pool Shares',
title: 'Downloads', content: <PoolShares accountId={accountIdentifier} />
content: <Downloads /> },
}, {
{ title: 'Pool Transactions',
content: <PoolTransactions accountId={accountIdentifier} />
},
{
title: 'Downloads',
content: <Downloads accountId={accountIdentifier} />
}
]
const computeTab: HistoryTab = {
title: 'Compute Jobs', title: 'Compute Jobs',
content: ( content: (
<OceanProvider> <OceanProvider>
@ -34,12 +43,21 @@ const tabs = [
</OceanProvider> </OceanProvider>
) )
} }
] if (accountIdentifier === accountId) {
defaultTabs.push(computeTab)
}
return defaultTabs
}
export default function HistoryPage(): ReactElement { export default function HistoryPage({
accountId
}: {
accountId: string
}): ReactElement {
const { chainIds } = useUserPreferences() const { chainIds } = useUserPreferences()
const url = new URL(window.location.href) const url = new URL(window.location.href)
const defaultTab = url.searchParams.get('defaultTab') const defaultTab = url.searchParams.get('defaultTab')
const tabs = getTabs(accountId)
let defaultTabIndex = 0 let defaultTabIndex = 0
defaultTab === 'ComputeJobs' ? (defaultTabIndex = 4) : (defaultTabIndex = 0) defaultTab === 'ComputeJobs' ? (defaultTabIndex = 4) : (defaultTabIndex = 0)
return ( return (

View File

@ -5,7 +5,7 @@ import { useWeb3 } from '../../../providers/Web3'
export default function AccountPage({ export default function AccountPage({
accountIdentifier accountIdentifier
}: { }: {
accountIdentifier: ReactElement | string accountIdentifier: string
}): ReactElement { }): ReactElement {
const { accountId } = useWeb3() const { accountId } = useWeb3()
if (!accountIdentifier) accountIdentifier = accountId if (!accountIdentifier) accountIdentifier = accountId
@ -17,7 +17,7 @@ export default function AccountPage({
) : ( ) : (
<p>Please connect your Web3 wallet.</p> <p>Please connect your Web3 wallet.</p>
)} )}
<HistoryPage /> <HistoryPage accountId={accountIdentifier} />
</article> </article>
) )
} }