Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve displaying events #651

Merged
merged 6 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/651.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve displaying events
2 changes: 1 addition & 1 deletion src/app/components/StyledDescriptionList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const StyledDescriptionList = styled(InlineDescriptionList, {
})<StyledDescriptionListProps>(({ theme, standalone, highlight }) => ({
'dt, dd': {
display: 'flex',
alignItems: 'center',
alignItems: 'start',
boxShadow: `0px 1px 0px ${COLORS.grayLight}`,
':last-of-type': {
boxShadow: 'none',
Expand Down
74 changes: 70 additions & 4 deletions src/app/components/Transactions/LogEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { SearchScope } from '../../../types/searchScope'
import { AddressSwitchOption } from '../AddressSwitch'
import { getOasisAddress } from '../../utils/helpers'
import { exhaustedTypeWarning } from '../../../types/errors'
import { LongDataDisplay } from '../LongDataDisplay'

const EvmEventParamData: FC<{
scope: SearchScope
Expand Down Expand Up @@ -108,12 +109,28 @@ const DecodedLogEvent: FC<{
case RuntimeEventType.coregas_used:
return (
<span>
{t('common.gasUsed')}: {event.body.amount.toLocaleString()}
{eventName}: {event.body.amount.toLocaleString()}
</span>
)
case RuntimeEventType.evmlog:
if (!event.evm_log_name && !event.evm_log_params && event.body.data) {
return (
<div>
<div>{eventName}</div>
<br />
<LongDataDisplay
data={`0x${Buffer.from(event.body.data, 'base64').toString('hex')}`}
threshold={300}
fontWeight={400}
/>
</div>
)
}
return (
<>
<div>
<div>{eventName}</div>
<br />

<StyledDescriptionList titleWidth={isMobile ? '100px' : '200px'}>
<dt>{t('common.type')}</dt>
<dd>
Expand Down Expand Up @@ -147,25 +164,74 @@ const DecodedLogEvent: FC<{
</>
)}
</StyledDescriptionList>
</>
</div>
)

case RuntimeEventType.accountsburn:
case RuntimeEventType.accountsmint:
return (
<div>
<div>{eventName}</div>
<br />
<StyledDescriptionList titleWidth={isMobile ? '100px' : '200px'}>
<dt>{t('transactionEvent.fields.owner')}</dt>
<dd>
<AccountLink
address={event.body.owner}
scope={scope}
plain={addressSwitchOption === AddressSwitchOption.ETH}
/>
</dd>
<dt>{t('transactionEvent.fields.amount')}</dt>
<dd>
{t('common.valueInToken', {
value: event.body.amount.Amount,
ticker: event.body.amount.Denomination,
})}
</dd>
</StyledDescriptionList>
</div>
)
case RuntimeEventType.accountstransfer:
case RuntimeEventType.consensus_accountsdeposit:
case RuntimeEventType.consensus_accountswithdraw:
return (
<div>
<div>{eventName}</div>
<pre>{JSON.stringify(event, null, ' ')}</pre>
<br />
<StyledDescriptionList titleWidth={isMobile ? '100px' : '200px'}>
<dt>{t('common.from')}</dt>
<dd>
<AccountLink
address={event.body.from}
scope={scope}
plain={addressSwitchOption === AddressSwitchOption.ETH}
/>
</dd>
<dt>{t('common.to')}</dt>
<dd>
<AccountLink
address={event.body.to}
scope={scope}
plain={addressSwitchOption === AddressSwitchOption.ETH}
/>
</dd>
<dt>{t('transactionEvent.fields.amount')}</dt>
<dd>
{t('common.valueInToken', {
value: event.body.amount.Amount,
ticker: event.body.amount.Denomination,
})}
</dd>
</StyledDescriptionList>
</div>
)
default:
exhaustedTypeWarning('Unexpected event type', event.type)
return (
<div>
<div>{eventName}</div>
<br />
<pre>{JSON.stringify(event, null, ' ')}</pre>
</div>
)
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/Transactions/Logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TextSkeleton } from '../../components/Skeleton'
import { AddressSwitchOption } from '../AddressSwitch'
import { CardEmptyState } from '../../pages/AccountDetailsPage/CardEmptyState'
import { useTranslation } from 'react-i18next'
import { SearchScope } from '../../../types/searchScope'

export const TransactionLogs: FC<{
transaction: RuntimeTransaction
Expand All @@ -32,7 +33,7 @@ export const TransactionLogs: FC<{
}

export const TransactionLogsView: FC<{
scope: RuntimeTransaction
scope: SearchScope
events: RuntimeEvent[] | undefined
isLoading: boolean
isError: boolean
Expand Down
6 changes: 5 additions & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@
"consensusWithdrawal": "Withdrawal to consensus",
"decoded": "Decoded",
"evmLog": "EVM log message",
"gasUsed": "Gas used"
"gasUsed": "Gas used",
"fields": {
"amount": "Amount",
"owner": "Owner"
}
},
"transactionStats": {
"header": "Transactions Per Day",
Expand Down
28 changes: 28 additions & 0 deletions src/oasis-nexus/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,34 @@ export const useGetRuntimeEvents: typeof generated.useGetRuntimeEvents = (
return {
...data,
events: data.events.map(event => {
if (
event.type === 'accounts.transfer' ||
event.type === 'accounts.mint' ||
event.type === 'accounts.burn' ||
event.type === 'consensus_accounts.deposit' ||
event.type === 'consensus_accounts.withdraw'
) {
return {
...event,
body: {
...event.body,
amount:
// If there's no denomination then use runtime's native. Otherwise unknown (would have to get by token name?).
event.body.amount.Denomination === ''
? {
...event.body.amount,
Amount: fromBaseUnits(
event.body.amount.Amount,
paraTimesConfig[runtime].decimals,
),
Denomination: getTickerForNetwork(network),
}
: event.body.amount,
},
layer: runtime,
network,
}
}
return {
...event,
layer: runtime,
Expand Down