Skip to content

Commit ae2996b

Browse files
authored
Merge pull request #1851 from oasisprotocol/mz/roflAppTxs
Setup ROFL app transactions card
2 parents e014a8f + c013d86 commit ae2996b

File tree

5 files changed

+155
-1
lines changed

5 files changed

+155
-1
lines changed

.changelog/1851.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Setup ROFL app transactions card
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { FC } from 'react'
2+
import Box from '@mui/material/Box'
3+
import { useScreenSize } from '../../hooks/useScreensize'
4+
import { NUMBER_OF_ITEMS_ON_SEPARATE_PAGE } from '../../config'
5+
import { transactionsContainerId } from '../../utils/tabAnchors'
6+
import { LinkableCardLayout } from '../../components/LinkableCardLayout'
7+
import { RuntimeTransactions } from '../../components/Transactions'
8+
import { RuntimeTransactionTypeFilter } from '../../components/Transactions/RuntimeTransactionTypeFilter'
9+
import { RoflAppDetailsContext, useRoflAppTransactions } from './hooks'
10+
11+
export const RoflAppTransactionsCard: FC<RoflAppDetailsContext> = context => {
12+
const { method, setMethod, scope } = context
13+
14+
const { isMobile } = useScreenSize()
15+
16+
return (
17+
<LinkableCardLayout
18+
containerId={transactionsContainerId}
19+
title={
20+
<Box
21+
sx={{
22+
display: 'flex',
23+
justifyContent: 'end',
24+
}}
25+
>
26+
{!isMobile && (
27+
<RuntimeTransactionTypeFilter layer={scope.layer} value={method} setValue={setMethod} />
28+
)}
29+
</Box>
30+
}
31+
>
32+
{isMobile && (
33+
<RuntimeTransactionTypeFilter layer={scope.layer} value={method} setValue={setMethod} expand />
34+
)}
35+
<RoflAppTransactions {...context} />
36+
</LinkableCardLayout>
37+
)
38+
}
39+
40+
const RoflAppTransactions: FC<RoflAppDetailsContext> = ({ scope, id, method }) => {
41+
const { isLoading, transactions, pagination, totalCount, isTotalCountClipped } = useRoflAppTransactions(
42+
scope,
43+
id,
44+
method,
45+
)
46+
return (
47+
<RuntimeTransactions
48+
transactions={transactions}
49+
isLoading={isLoading}
50+
limit={NUMBER_OF_ITEMS_ON_SEPARATE_PAGE}
51+
pagination={{
52+
selectedPage: pagination.selectedPage,
53+
linkToPage: pagination.linkToPage,
54+
totalCount,
55+
isTotalCountClipped,
56+
rowsPerPage: NUMBER_OF_ITEMS_ON_SEPARATE_PAGE,
57+
}}
58+
filtered={method !== 'any'}
59+
/>
60+
)
61+
}
Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
import { useOutletContext } from 'react-router-dom'
2+
import { useGetRuntimeRoflAppsIdTransactions, Layer } from '../../../oasis-nexus/api'
3+
import { AppErrors } from '../../../types/errors'
14
import { SearchScope } from '../../../types/searchScope'
5+
import { NUMBER_OF_ITEMS_ON_SEPARATE_PAGE as limit } from '../../config'
6+
import { getRuntimeTransactionMethodFilteringParam } from '../../components/RuntimeTransactionMethod'
7+
import { useSearchParamsPagination } from '../..//components/Table/useSearchParamsPagination'
28

39
export type RoflAppDetailsContext = {
410
scope: SearchScope
@@ -7,4 +13,38 @@ export type RoflAppDetailsContext = {
713
setMethod: (value: string) => void
814
}
915

10-
// TOOD: Placeholder file for a hook used within a router. Add when details page is ready
16+
export const useRoflAppDetailsProps = () => useOutletContext<RoflAppDetailsContext>()
17+
18+
export const useRoflAppTransactions = (scope: SearchScope, id: string, method: string) => {
19+
const { network, layer } = scope
20+
const pagination = useSearchParamsPagination('page')
21+
const offset = (pagination.selectedPage - 1) * limit
22+
if (layer !== Layer.sapphire) {
23+
throw AppErrors.UnsupportedLayer
24+
}
25+
26+
const query = useGetRuntimeRoflAppsIdTransactions(network, Layer.sapphire, id, {
27+
limit,
28+
offset: offset,
29+
rel: id,
30+
...getRuntimeTransactionMethodFilteringParam(method),
31+
})
32+
const { isFetched, isLoading, data } = query
33+
const transactions = data?.data.transactions
34+
35+
if (isFetched && pagination.selectedPage > 1 && !transactions?.length) {
36+
throw AppErrors.PageDoesNotExist
37+
}
38+
39+
const totalCount = data?.data.total_count
40+
const isTotalCountClipped = data?.data.is_total_count_clipped
41+
42+
return {
43+
isLoading,
44+
isFetched,
45+
transactions,
46+
pagination,
47+
totalCount,
48+
isTotalCountClipped,
49+
}
50+
}

src/oasis-nexus/api.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,3 +1538,42 @@ export const useGetRuntimeRoflAppsId: typeof generated.useGetRuntimeRoflAppsId =
15381538
},
15391539
})
15401540
}
1541+
1542+
export const useGetRuntimeRoflAppsIdTransactions: typeof generated.useGetRuntimeRoflAppsIdTransactions = (
1543+
network,
1544+
runtime,
1545+
id,
1546+
params?,
1547+
options?,
1548+
) => {
1549+
return generated.useGetRuntimeRoflAppsIdTransactions(network, runtime, id, params, {
1550+
...options,
1551+
request: {
1552+
...options?.request,
1553+
transformResponse: [
1554+
...arrayify(axios.defaults.transformResponse),
1555+
(data: generated.RuntimeTransactionList, headers, status) => {
1556+
if (status !== 200) return data
1557+
return {
1558+
...data,
1559+
transactions: data.transactions.map(tx => {
1560+
return {
1561+
...tx,
1562+
eth_hash: tx.eth_hash ? `0x${tx.eth_hash}` : undefined,
1563+
fee: fromBaseUnits(tx.fee, paraTimesConfig.sapphire.decimals),
1564+
fee_symbol: normalizeSymbol(tx.fee_symbol, { network, layer: runtime }),
1565+
charged_fee: fromBaseUnits(tx.charged_fee, paraTimesConfig.sapphire.decimals),
1566+
amount: tx.amount ? fromBaseUnits(tx.amount, paraTimesConfig.sapphire.decimals) : undefined,
1567+
amount_symbol: normalizeSymbol(tx.amount_symbol, { network, layer: runtime }),
1568+
layer: runtime,
1569+
network,
1570+
method: adjustRuntimeTransactionMethod(tx.method, tx.is_likely_native_token_transfer),
1571+
}
1572+
}),
1573+
}
1574+
},
1575+
...arrayify(options?.request?.transformResponse),
1576+
],
1577+
},
1578+
})
1579+
}

src/routes.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ import { FC, useEffect } from 'react'
7070
import { AnalyticsConsentProvider } from './app/components/AnalyticsConsent'
7171
import { HighlightingContextProvider } from './app/components/HighlightingContext'
7272
import { useLocalSettings } from './app/hooks/useLocalSettings'
73+
import { InstancesCard } from './app/pages/RoflAppDetailsPage/InstancesCard'
74+
import { useRoflAppDetailsProps } from './app/pages/RoflAppDetailsPage/hooks'
75+
import { RoflAppTransactionsCard } from './app/pages/RoflAppDetailsPage/RoflAppTransactionsCard'
7376

7477
const ScopeSpecificPart = () => {
7578
const { network, layer } = useRequiredScopeParam()
@@ -306,6 +309,16 @@ export const routes: RouteObject[] = [
306309
path: `rofl/app/:id`,
307310
element: <RoflAppDetailsPage />,
308311
loader: roflAppParamLoader(),
312+
children: [
313+
{
314+
path: '',
315+
Component: () => <RoflAppTransactionsCard {...useRoflAppDetailsProps()} />,
316+
},
317+
{
318+
path: 'instances',
319+
Component: () => <InstancesCard {...useRoflAppDetailsProps()} />,
320+
},
321+
],
309322
},
310323
],
311324
},

0 commit comments

Comments
 (0)