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 function name in verified contract calls #1565

Merged
merged 2 commits into from
Oct 14, 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/1565.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Display EVM function name in verified contract calls
1 change: 0 additions & 1 deletion src/app/components/ConsensusTransactionMethod/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ const MethodIconContent: FC<MethodIconContentProps> = ({
<Typography
sx={{
fontWeight: 'inherit',
textTransform: 'capitalize',
buberdds marked this conversation as resolved.
Show resolved Hide resolved
order: reverseLabel ? -1 : 0,
...(truncate
? {
Expand Down
46 changes: 27 additions & 19 deletions src/app/components/RuntimeTransactionMethod/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import QuestionMarkIcon from '@mui/icons-material/QuestionMark'
import LanIcon from '@mui/icons-material/Lan'
import LanOutlinedIcon from '@mui/icons-material/LanOutlined'
import { MethodIcon } from '../ConsensusTransactionMethod'
import { RuntimeTransaction } from '../../../oasis-nexus/api'

const getRuntimeTransactionLabel = (t: TFunction, method: string | undefined) => {
switch (method) {
Expand All @@ -35,6 +36,21 @@ const getRuntimeTransactionLabel = (t: TFunction, method: string | undefined) =>
}
}

/**
* The method call body. Defined by the runtime.
*
* May be undefined if the transaction was malformed.
*
* In theory, this could be any string as the runtimes evolve.
* In practice, the nexus currently expects only the following methods:
* - "accounts.Transfer"
* - "consensus.Deposit"
* - "consensus.Withdraw"
* - "consensus.Delegate"
* - "consensus.Undelegate"
* - "evm.Create"
* - "evm.Call"
*/
const getRuntimeTransactionIcon = (method: string | undefined, label: string, truncate?: boolean) => {
const props = {
border: false,
Expand Down Expand Up @@ -63,28 +79,20 @@ const getRuntimeTransactionIcon = (method: string | undefined, label: string, tr
}

type RuntimeTransactionLabelProps = {
/**
* The method call body. Defined by the runtime.
*
* May be undefined if the transaction was malformed.
*
* In theory, this could be any string as the runtimes evolve.
* In practice, the nexus currently expects only the following methods:
* - "accounts.Transfer"
* - "consensus.Deposit"
* - "consensus.Withdraw"
* - "consensus.Delegate"
* - "consensus.Undelegate"
* - "evm.Create"
* - "evm.Call"
*/
method?: string
transaction: RuntimeTransaction
truncate?: boolean
}

export const RuntimeTransactionMethod: FC<RuntimeTransactionLabelProps> = ({ method, truncate }) => {
export const RuntimeTransactionMethod: FC<RuntimeTransactionLabelProps> = ({ transaction, truncate }) => {
const { t } = useTranslation()
const label = getRuntimeTransactionLabel(t, method)
let label = getRuntimeTransactionLabel(t, transaction.method)
if (transaction.evm_fn_name) {
if (truncate) {
label = `${transaction.evm_fn_name}`
} else {
label += `: ${transaction.evm_fn_name}`
}
}

return <>{getRuntimeTransactionIcon(method, label, truncate)}</>
return <>{getRuntimeTransactionIcon(transaction.method, label, truncate)}</>
}
2 changes: 1 addition & 1 deletion src/app/components/Transactions/RuntimeTransactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const RuntimeTransactions: FC<TransactionsProps> = ({
...(verbose
? [
{
content: <RuntimeTransactionMethod method={transaction.method} truncate />,
content: <RuntimeTransactionMethod transaction={transaction} truncate />,
Copy link
Contributor

@buberdds buberdds Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks cool in details, but do we really want it in lists (where we present more general info) ?
Screenshot from 2024-10-08 18-34-13

cc: @donouwens

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw the names should be trimmed in the list, but trimming is buggy #1399

key: 'type',
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/RuntimeTransactionDetailPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const RuntimeTransactionDetailView: FC<{

<dt>{t('common.type')}</dt>
<dd>
<RuntimeTransactionMethod method={transaction.method} />
<RuntimeTransactionMethod transaction={transaction} />
</dd>

<dt>{t('transactions.encryption.format')}</dt>
Expand Down
4 changes: 2 additions & 2 deletions src/stories/Icons.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ConsensusTransactionMethod } from '../app/components/ConsensusTransacti
import { RuntimeTransactionMethod } from '../app/components/RuntimeTransactionMethod'
import { TokenTransferIcon } from '../app/components/Tokens/TokenTransferIcon'
import { EventTypeIcon } from '../app/components/RuntimeEvents/RuntimeEventDetails'
import { ConsensusTxMethod, RuntimeEventType } from '../oasis-nexus/api'
import { ConsensusTxMethod, RuntimeEventType, RuntimeTransaction } from '../oasis-nexus/api'
import { COLORS } from '../styles/theme/colors'

export default {
Expand Down Expand Up @@ -53,7 +53,7 @@ const RuntimeTemplate: StoryFn = () => {
gap={4}
sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', paddingBottom: 4 }}
>
<RuntimeTransactionMethod method={method} />
<RuntimeTransactionMethod transaction={{ method } as RuntimeTransaction} />
<Typography sx={{ color: COLORS.grayMedium, fontSize: '12px' }}>({method})</Typography>
</Box>
))}
Expand Down
Loading