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

fix: Align decoded tx ui for batch execute #2275

Merged
merged 2 commits into from
Jul 11, 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
2 changes: 1 addition & 1 deletion src/components/transactions/BatchExecuteButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const BatchExecuteButton = () => {
label: batchableTransactions.length,
})

setTxFlow(<ExecuteBatchFlow txs={batchableTransactions} />)
setTxFlow(<ExecuteBatchFlow txs={batchableTransactions} />, undefined, false)
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useState, useEffect } from 'react'
import type { Dispatch, ReactElement, SetStateAction } from 'react'
import type { AccordionProps } from '@mui/material/Accordion/Accordion'
import SingleTxDecoded from '@/components/transactions/TxDetails/TxData/DecodedData/SingleTxDecoded'
import { Box, Button, Divider, Stack } from '@mui/material'
import { Button, Divider, Stack } from '@mui/material'
import css from './styles.module.css'
import classnames from 'classnames'

Expand All @@ -15,22 +15,24 @@ type MultisendProps = {
compact?: boolean
}

const MultisendActionsHeader = ({
export const MultisendActionsHeader = ({
setOpen,
amount,
compact = false,
title = 'All actions',
}: {
setOpen: Dispatch<SetStateAction<Record<number, boolean> | undefined>>
amount: number
compact?: boolean
title?: string
}) => {
const onClickAll = (expanded: boolean) => () => {
setOpen(Array(amount).fill(expanded))
}

return (
<div className={classnames(css.actionsHeader, { [css.compactHeader]: compact })}>
All actions
{title}
<Stack direction="row" divider={<Divider className={css.divider} />}>
<Button onClick={onClickAll(true)} variant="text">
Expand all
Expand Down Expand Up @@ -83,7 +85,7 @@ export const Multisend = ({
<>
<MultisendActionsHeader setOpen={setOpenMap} amount={multiSendTransactions.length} compact={compact} />

<Box display="flex" flexDirection="column" className={compact ? css.compact : ''}>
<div className={compact ? css.compact : ''}>
{multiSendTransactions.map(({ dataDecoded, data, value, to, operation }, index) => {
const onChange: AccordionProps['onChange'] = (_, expanded) => {
setOpenMap((prev) => ({
Expand Down Expand Up @@ -111,7 +113,7 @@ export const Multisend = ({
/>
)
})}
</Box>
</div>
</>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.actionsHeader {
border-bottom: 1px solid var(--color-border-light);
cursor: auto !important;
padding-left: 16px;
padding-left: 0;
padding-right: 0;
display: flex;
justify-content: space-between;
Expand All @@ -23,6 +23,11 @@
border: 1px solid var(--color-border-light);
}

.compact {
display: flex;
flex-direction: column;
}

.compact > div:first-child {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
Expand Down
94 changes: 56 additions & 38 deletions src/components/tx-flow/flows/ExecuteBatch/DecodedTxs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,69 @@ import useSafeInfo from '@/hooks/useSafeInfo'
import extractTxInfo from '@/services/tx/extractTxInfo'
import { isCustomTxInfo, isNativeTokenTransfer, isTransferTxInfo } from '@/utils/transaction-guards'
import SingleTxDecoded from '@/components/transactions/TxDetails/TxData/DecodedData/SingleTxDecoded'
import css from '@/components/transactions/TxDetails/TxData/DecodedData/Multisend/styles.module.css'
import { useState } from 'react'
import { MultisendActionsHeader } from '@/components/transactions/TxDetails/TxData/DecodedData/Multisend'
import { type AccordionProps } from '@mui/material/Accordion/Accordion'

const DecodedTxs = ({ txs }: { txs: TransactionDetails[] | undefined }) => {
const [openMap, setOpenMap] = useState<Record<number, boolean>>()
const { safeAddress } = useSafeInfo()

if (!txs) return null

return (
<Box mt={1} display="flex" flexDirection="column" gap={1}>
{txs.map((transaction, idx) => {
if (!transaction.txData) return null

const { txParams } = extractTxInfo(transaction, safeAddress)

let decodedDataParams: DataDecoded = {
method: '',
parameters: undefined,
}

if (isCustomTxInfo(transaction.txInfo) && transaction.txInfo.isCancellation) {
decodedDataParams.method = 'On-chain rejection'
}

if (isTransferTxInfo(transaction.txInfo) && isNativeTokenTransfer(transaction.txInfo.transferInfo)) {
decodedDataParams.method = 'transfer'
}

const dataDecoded = transaction.txData.dataDecoded || decodedDataParams

return (
<SingleTxDecoded
key={transaction.txId}
tx={{
dataDecoded,
data: txParams.data,
value: txParams.value,
to: txParams.to,
operation: 0,
}}
txData={transaction.txData}
actionTitle={`${idx + 1}`}
showDelegateCallWarning={false}
/>
)
})}
</Box>
<>
<MultisendActionsHeader title="Batched transactions" setOpen={setOpenMap} amount={txs.length} compact />

Comment on lines +19 to +21
Copy link
Member Author

Choose a reason for hiding this comment

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

There is some duplication between this and the Multisend component because of the data type difference but I suggest we refactor it as a future task.

<Box className={css.compact}>
{txs.map((transaction, idx) => {
if (!transaction.txData) return null

const onChange: AccordionProps['onChange'] = (_, expanded) => {
setOpenMap((prev) => ({
...prev,
[idx]: expanded,
}))
}

const { txParams } = extractTxInfo(transaction, safeAddress)

let decodedDataParams: DataDecoded = {
method: '',
parameters: undefined,
}

if (isCustomTxInfo(transaction.txInfo) && transaction.txInfo.isCancellation) {
decodedDataParams.method = 'On-chain rejection'
}

if (isTransferTxInfo(transaction.txInfo) && isNativeTokenTransfer(transaction.txInfo.transferInfo)) {
decodedDataParams.method = 'transfer'
}

const dataDecoded = transaction.txData.dataDecoded || decodedDataParams

return (
<SingleTxDecoded
key={transaction.txId}
tx={{
dataDecoded,
data: txParams.data,
value: txParams.value,
to: txParams.to,
operation: 0,
}}
txData={transaction.txData}
actionTitle={`${idx + 1}`}
showDelegateCallWarning={false}
expanded={openMap?.[idx] ?? false}
onChange={onChange}
/>
)
})}
</Box>
</>
)
}

Expand Down
5 changes: 1 addition & 4 deletions src/components/tx-flow/flows/ExecuteBatch/ReviewBatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ export const ReviewBatch = ({ params }: { params: ExecuteBatchFlowProps }) => {
)}

<div>
<Typography variant="body2" color="text.secondary">
Batched transactions:
</Typography>
<DecodedTxs txs={txsWithDetails} />
</div>
</TxCard>
Expand Down Expand Up @@ -198,7 +195,7 @@ export const ReviewBatch = ({ params }: { params: ExecuteBatchFlowProps }) => {
<CheckWallet allowNonOwner={true}>
{(isOk) => (
<Button variant="contained" type="submit" disabled={!isOk || submitDisabled} onClick={handleSubmit}>
Send
Submit
</Button>
)}
</CheckWallet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Typography, Grid, Alert } from '@mui/material'

import SpendingLimitLabel from '@/components/common/SpendingLimitLabel'
import { getResetTimeOptions } from '@/components/transactions/TxDetails/TxData/SpendingLimits'
import { AmountBlock } from '@/components/tx-flow/flows/TokenTransfer/SendAmountBlock'
import SendAmountBlock from '@/components/tx-flow/flows/TokenTransfer/SendAmountBlock'
import SignOrExecuteForm from '@/components/tx/SignOrExecuteForm'
import useBalances from '@/hooks/useBalances'
import useChainId from '@/hooks/useChainId'
Expand Down Expand Up @@ -59,33 +59,26 @@ export const ReviewSpendingLimit = ({ params }: { params: NewSpendingLimitFlowPr
return (
<SignOrExecuteForm onSubmit={onFormSubmit}>
{token && (
<Grid container gap={1} alignItems="center">
<Grid item xs={4} md={2}>
<Typography variant="body2" color="text.secondary">
Amount
</Typography>
</Grid>
<AmountBlock amount={params.amount} tokenInfo={token.tokenInfo}>
{!!existingSpendingLimit && (
<>
<Typography color="error" sx={{ textDecoration: 'line-through' }} component="span">
{formatVisualAmount(BigNumber.from(existingSpendingLimit.amount), decimals)}
</Typography>
{'→'}
</>
)}
</AmountBlock>
</Grid>
<SendAmountBlock amount={params.amount} tokenInfo={token.tokenInfo} title="Amount">
{!!existingSpendingLimit && (
<>
<Typography color="error" sx={{ textDecoration: 'line-through' }} component="span">
{formatVisualAmount(BigNumber.from(existingSpendingLimit.amount), decimals)}
</Typography>
{'→'}
</>
)}
</SendAmountBlock>
)}

<Grid container gap={1} alignItems="center">
<Grid item xs={4} md={2}>
<Grid item md>
<Typography variant="body2" color="text.secondary">
Beneficiary
</Typography>
</Grid>

<Grid item>
<Grid item md={10}>
<EthHashInfo
address={params.beneficiary}
shortAddress={false}
Expand All @@ -97,12 +90,12 @@ export const ReviewSpendingLimit = ({ params }: { params: NewSpendingLimitFlowPr
</Grid>

<Grid container gap={1} alignItems="center">
<Grid item xs={4} md={2}>
<Grid item md>
<Typography variant="body2" color="text.secondary">
Reset time
</Typography>
</Grid>
<Grid item>
<Grid item md={10}>
{existingSpendingLimit ? (
<>
<SpendingLimitLabel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { SpendingLimitState } from '@/store/spendingLimitsSlice'
import { relativeTime } from '@/utils/date'
import { trackEvent, SETTINGS_EVENTS } from '@/services/analytics'
import useBalances from '@/hooks/useBalances'
import { AmountBlock } from '@/components/tx-flow/flows/TokenTransfer/SendAmountBlock'
import SendAmountBlock from '@/components/tx-flow/flows/TokenTransfer/SendAmountBlock'
import { safeFormatUnits } from '@/utils/formatters'
import SpendingLimitLabel from '@/components/common/SpendingLimitLabel'
import { createTx } from '@/services/tx/tx-sender'
Expand Down Expand Up @@ -49,35 +49,42 @@ export const RemoveSpendingLimit = ({ params }: { params: SpendingLimitState })
return (
<SignOrExecuteForm onSubmit={onFormSubmit}>
{token && (
<Grid container gap={1} alignItems="center">
<Grid item xs={4} md={2}>
<Typography variant="body2" color="text.secondary">
Amount
</Typography>
</Grid>
<AmountBlock amount={safeFormatUnits(params.amount, token.tokenInfo.decimals)} tokenInfo={token.tokenInfo} />
</Grid>
<SendAmountBlock
amount={safeFormatUnits(params.amount, token.tokenInfo.decimals)}
tokenInfo={token.tokenInfo}
title="Amount"
/>
)}

<Grid container gap={1} alignItems="center">
<Grid item xs={4} md={2}>
<Grid item md>
<Typography variant="body2" color="text.secondary">
Beneficiary
</Typography>
</Grid>
<EthHashInfo address={params.beneficiary} showCopyButton hasExplorer shortAddress={false} showAvatar={false} />
<Grid item md={10}>
<EthHashInfo
address={params.beneficiary}
showCopyButton
hasExplorer
shortAddress={false}
showAvatar={false}
/>
</Grid>
</Grid>

<Grid container gap={1} alignItems="center">
<Grid item xs={4} md={2}>
<Grid item md>
<Typography variant="body2" color="text.secondary">
Reset time
</Typography>
</Grid>
<SpendingLimitLabel
label={relativeTime(params.lastResetMin, params.resetTimeMin)}
isOneTime={params.resetTimeMin === '0'}
/>
<Grid item md={10}>
<SpendingLimitLabel
label={relativeTime(params.lastResetMin, params.resetTimeMin)}
isOneTime={params.resetTimeMin === '0'}
/>
</Grid>
</Grid>
</SignOrExecuteForm>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import TokenIcon from '@/components/common/TokenIcon'
import { formatAmountPrecise } from '@/utils/formatNumber'
import { PSEUDO_APPROVAL_VALUES } from '@/components/tx/ApprovalEditor/utils/approvals'

export const AmountBlock = ({
const AmountBlock = ({
amount,
tokenInfo,
children,
Expand Down