Skip to content

Commit

Permalink
Move tx helpers to api layer
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Jul 17, 2024
1 parent e572688 commit f4ca013
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/app/pages/ConsensusTransactionDetailPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useParams } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { styled } from '@mui/material/styles'
import { Transaction, useGetConsensusTransactionsTxHash } from '../../../oasis-nexus/api'
import { getConsensusTransactionAmount, getConsensusTransactionToAddress } from '../../utils/transaction'
import { StyledDescriptionList } from '../../components/StyledDescriptionList'
import { PageLayout } from '../../components/PageLayout'
import { SubPageCard } from '../../components/SubPageCard'
Expand Down Expand Up @@ -70,8 +69,6 @@ export const ConsensusTransactionDetailView: FC<{
if (isLoading) return <TextSkeleton numberOfRows={detailsPage ? 13 : 7} />
if (!transaction) return <></>

const to = getConsensusTransactionToAddress(transaction)
const amount = getConsensusTransactionAmount(transaction)
const tokenPriceInfo = tokenPrices?.[transaction.ticker]

return (
Expand Down Expand Up @@ -104,37 +101,40 @@ export const ConsensusTransactionDetailView: FC<{
<AccountLink scope={transaction} address={transaction.sender} />
<CopyToClipboard value={transaction.sender} />
</dd>
{to && (
{transaction.to && (
<>
<dt>{t('common.to')}</dt>
<dd>
<AccountLink scope={{ layer: transaction.layer, network: transaction.network }} address={to} />
<CopyToClipboard value={to} />
<AccountLink
scope={{ layer: transaction.layer, network: transaction.network }}
address={transaction.to}
/>
<CopyToClipboard value={transaction.to} />
</dd>
</>
)}
{amount && (
{transaction.amount && (
<>
<dt>{t('common.value')}</dt>
<dd>
{t('common.valueInToken', {
...getPreciseNumberFormat(amount),
...getPreciseNumberFormat(transaction.amount),
ticker: transaction.ticker,
})}
</dd>
</>
)}
{detailsPage && (
<>
{amount &&
{transaction.amount &&
!!tokenPriceInfo &&
!tokenPriceInfo.isLoading &&
!tokenPriceInfo.isFree &&
tokenPriceInfo.price !== undefined && (
<>
<dt>{t('currentFiatValue.title')}</dt>
<dd>
<CurrentFiatValue amount={amount} {...tokenPriceInfo} />
<CurrentFiatValue amount={transaction.amount} {...tokenPriceInfo} />
</dd>
</>
)}
Expand Down
7 changes: 7 additions & 0 deletions src/oasis-nexus/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Ticker } from '../types/ticker'
import { getRPCAccountBalances } from '../app/utils/getRPCAccountBalances'
import { toChecksumAddress } from '@ethereumjs/util'
import { fromBaseUnits } from '../app/utils/number-utils'
import { getConsensusTransactionAmount, getConsensusTransactionToAddress } from '../app/utils/transaction'

export * from './generated/api'
export type { RuntimeEvmBalance as Token } from './generated/api'
Expand All @@ -31,6 +32,8 @@ export type HasScope = SearchScope

declare module './generated/api' {
export interface Transaction {
amount: string | undefined
to: string | undefined
network: Network
layer: Layer
ticker: Ticker
Expand Down Expand Up @@ -250,8 +253,12 @@ export const useGetConsensusTransactionsTxHash: typeof generated.useGetConsensus
...arrayify(axios.defaults.transformResponse),
(transaction: generated.Transaction, headers, status) => {
if (status !== 200) return transaction
const amount = getConsensusTransactionAmount(transaction)
const to = getConsensusTransactionToAddress(transaction)
return {
...transaction,
amount: amount ? fromBaseUnits(amount, consensusDecimals) : undefined,
to,
body: {
...transaction.body,
amount: transaction.body?.amount
Expand Down

0 comments on commit f4ca013

Please sign in to comment.