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

Display EVM addresses in events #1364

Merged
merged 6 commits into from
Apr 5, 2024
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/1364.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Display EVM addresses in events
6 changes: 4 additions & 2 deletions src/app/components/Account/AccountLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import { RouteUtils } from '../../utils/route-utils'
import Typography from '@mui/material/Typography'
import { SearchScope } from '../../../types/searchScope'

export const AccountLink: FC<{
interface Props {
scope: SearchScope
address: string
alwaysTrim?: boolean
}> = ({ scope, address, alwaysTrim }) => {
}

export const AccountLink: FC<Props> = ({ scope, address, alwaysTrim }) => {
const { isTablet } = useScreenSize()
const to = RouteUtils.getAccountRoute(scope, address)
return (
Expand Down
4 changes: 4 additions & 0 deletions src/app/components/Account/AccountLinkWithAddressSwitch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { AccountLink } from './AccountLink'
import { withAddressSwitch } from './withAddressSwitch'

export const AccountLinkWithAddressSwitch = withAddressSwitch(AccountLink)
32 changes: 32 additions & 0 deletions src/app/components/Account/withAddressSwitch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { FC } from 'react'
import { AddressSwitchOption } from '../AddressSwitch'
import { CopyToClipboard } from '../CopyToClipboard'

interface WithAddressSwitchProps {
addressSwitchOption: AddressSwitchOption
ethAddress?: string
oasisAddress?: string
}

interface WrappedComponentBaseProps {
address?: string
}

export const withAddressSwitch =
<T extends WrappedComponentBaseProps>(Component: FC<T>) =>
(props: Omit<T, 'address'> & WithAddressSwitchProps) => {
const { addressSwitchOption, ethAddress, oasisAddress, ...restProps } = props

const addressesByType = {
[AddressSwitchOption.Oasis]: oasisAddress,
[AddressSwitchOption.ETH]: ethAddress,
}
const displayedAddress = addressesByType[addressSwitchOption] ?? ethAddress ?? oasisAddress

return (
<>
<Component {...(restProps as unknown as T)} address={displayedAddress} />
{displayedAddress && <CopyToClipboard value={displayedAddress} />}
</>
)
}
83 changes: 55 additions & 28 deletions src/app/components/RuntimeEvents/RuntimeEventDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { UndelegateStartIcon } from '../CustomIcons/UndelegateStart'
import { UndelegateFinishIcon } from '../CustomIcons/UndelegateFinish'
import { DelegateIcon } from '../CustomIcons/Delegate'
import { MaybeEventErrorLine } from './EventError'
import { AccountLinkWithAddressSwitch } from '../Account/AccountLinkWithAddressSwitch'

export const EventTypeIcon: FC<{
eventType: RuntimeEventType
Expand Down Expand Up @@ -203,10 +204,12 @@ export const RuntimeEventDetails: FC<{
<StyledDescriptionList titleWidth={isMobile ? '100px' : '200px'}>
<dt>{t('runtimeEvent.fields.owner')}</dt>
<dd>
<AccountLink address={event.body.owner} scope={scope} />
{addressSwitchOption === AddressSwitchOption.Oasis && (
<CopyToClipboard value={event.body.owner} />
)}
lubej marked this conversation as resolved.
Show resolved Hide resolved
<AccountLinkWithAddressSwitch
lubej marked this conversation as resolved.
Show resolved Hide resolved
scope={scope}
addressSwitchOption={addressSwitchOption}
ethAddress={event.body.owner_eth}
oasisAddress={event.body.owner}
/>
</dd>
<dt>{t('runtimeEvent.fields.amount')}</dt>
<dd>
Expand All @@ -228,15 +231,21 @@ export const RuntimeEventDetails: FC<{
<MaybeEventErrorLine event={event} />
<dt>{t('common.from')}</dt>
<dd>
<AccountLink address={event.body.from} scope={scope} />
{addressSwitchOption === AddressSwitchOption.Oasis && (
<CopyToClipboard value={event.body.from} />
)}
<AccountLinkWithAddressSwitch
scope={scope}
addressSwitchOption={addressSwitchOption}
ethAddress={event.body.from_eth}
oasisAddress={event.body.from}
/>
</dd>
<dt>{t('common.to')}</dt>
<dd>
<AccountLink address={event.body.to} scope={scope} />
{addressSwitchOption === AddressSwitchOption.Oasis && <CopyToClipboard value={event.body.to} />}
<AccountLinkWithAddressSwitch
scope={scope}
addressSwitchOption={addressSwitchOption}
ethAddress={event.body.to_eth}
oasisAddress={event.body.to}
/>
</dd>
<dt>{t('runtimeEvent.fields.amount')}</dt>
<dd>
Expand All @@ -256,15 +265,21 @@ export const RuntimeEventDetails: FC<{
<MaybeEventErrorLine event={event} />
<dt>{t('common.from')}</dt>
<dd>
<AccountLink address={event.body.from} scope={scope} />
{addressSwitchOption === AddressSwitchOption.Oasis && (
<CopyToClipboard value={event.body.from} />
)}
<AccountLinkWithAddressSwitch
scope={scope}
addressSwitchOption={addressSwitchOption}
ethAddress={event.body.from_eth}
oasisAddress={event.body.from}
/>
</dd>
<dt>{t('common.to')}</dt>
<dd>
<AccountLink address={event.body.to} scope={scope} />
{addressSwitchOption === AddressSwitchOption.Oasis && <CopyToClipboard value={event.body.to} />}
<AccountLinkWithAddressSwitch
scope={scope}
addressSwitchOption={addressSwitchOption}
ethAddress={event.body.to_eth}
oasisAddress={event.body.to}
/>
</dd>
<dt>{t('runtimeEvent.fields.amount')}</dt>
<dd>
Expand All @@ -284,15 +299,21 @@ export const RuntimeEventDetails: FC<{
<MaybeEventErrorLine event={event} />
<dt>{t('common.from')}</dt>
<dd>
<AccountLink address={event.body.from} scope={scope} />
{addressSwitchOption === AddressSwitchOption.Oasis && (
<CopyToClipboard value={event.body.from} />
)}
<AccountLinkWithAddressSwitch
scope={scope}
addressSwitchOption={addressSwitchOption}
ethAddress={event.body.from_eth}
oasisAddress={event.body.from}
/>
</dd>
<dt>{t('common.to')}</dt>
<dd>
<AccountLink address={event.body.to} scope={scope} />
{addressSwitchOption === AddressSwitchOption.Oasis && <CopyToClipboard value={event.body.to} />}
<AccountLinkWithAddressSwitch
scope={scope}
addressSwitchOption={addressSwitchOption}
ethAddress={event.body.to_eth}
oasisAddress={event.body.to}
/>
</dd>
<dt>{t('runtimeEvent.fields.activeShares')}</dt>
<dd>
Expand All @@ -311,15 +332,21 @@ export const RuntimeEventDetails: FC<{
<MaybeEventErrorLine event={event} />
<dt>{t('common.from')}</dt>
<dd>
<AccountLink address={event.body.from} scope={scope} />
{addressSwitchOption === AddressSwitchOption.Oasis && (
<CopyToClipboard value={event.body.from} />
)}
<AccountLinkWithAddressSwitch
scope={scope}
addressSwitchOption={addressSwitchOption}
ethAddress={event.body.from_eth}
oasisAddress={event.body.from}
/>
</dd>
<dt>{t('common.to')}</dt>
<dd>
<AccountLink address={event.body.to} scope={scope} />
{addressSwitchOption === AddressSwitchOption.Oasis && <CopyToClipboard value={event.body.to} />}
<AccountLinkWithAddressSwitch
scope={scope}
addressSwitchOption={addressSwitchOption}
ethAddress={event.body.to_eth}
oasisAddress={event.body.to}
/>
</dd>
<dt>{t('runtimeEvent.fields.amount')}</dt>
<dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SearchScope } from '../../../types/searchScope'
import { RuntimeEvent } from '../../../oasis-nexus/api'
import { AddressSwitchOption } from '../AddressSwitch'
import { useTranslation } from 'react-i18next'
import { CardEmptyState } from '../../components/CardEmptyState'
import { CardEmptyState } from '../CardEmptyState'
import { TextSkeleton } from '../Skeleton'
import { RuntimeEventDetails } from './RuntimeEventDetails'
import Divider from '@mui/material/Divider'
Expand Down
Loading