-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
295 additions
and
14 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ButtonBase, SvgIcon } from '@mui/material' | ||
import BatchIcon from '@/public/images/common/batch.svg' | ||
|
||
const BatchIndicator = ({ onClick }: { onClick?: () => void }) => { | ||
return ( | ||
<ButtonBase onClick={onClick}> | ||
<SvgIcon component={BatchIcon} inheritViewBox fontSize="small" /> | ||
</ButtonBase> | ||
) | ||
} | ||
|
||
export default BatchIndicator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Box, SvgIcon } from '@mui/material' | ||
import type { MetaTransactionData } from '@safe-global/safe-core-sdk-types' | ||
import CustomTxIcon from '@/public/images/transactions/custom.svg' | ||
import DateTime from '../DateTime' | ||
import { EthHashInfo } from '@safe-global/safe-react-components' | ||
|
||
const BatchTxItem = ({ txData, timestamp }: { txData: MetaTransactionData; timestamp: number }) => { | ||
return ( | ||
<Box display="flex" gap={2} mb={1} p={2} sx={{ border: '1px solid', borderColor: 'border.light', borderRadius: 2 }}> | ||
<SvgIcon component={CustomTxIcon} viewBox="0 0 16 16" width={24} height={24} /> | ||
<Box flex={1}> | ||
<EthHashInfo address={txData.to} showAvatar={false} /> | ||
</Box> | ||
<DateTime value={timestamp} /> | ||
</Box> | ||
) | ||
} | ||
|
||
export default BatchTxItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type { SyntheticEvent } from 'react' | ||
import { useCallback, useContext } from 'react' | ||
import { Button, Divider, Drawer, Typography } from '@mui/material' | ||
import { useDraftBatch } from '@/hooks/useDraftBatch' | ||
import css from './styles.module.css' | ||
import NewTxMenu from '@/components/tx-flow/flows/NewTx' | ||
import { TxModalContext } from '@/components/tx-flow' | ||
import BatchTxItem from './BatchTxItem' | ||
import ConfirmBatchFlow from '@/components/tx-flow/flows/ConfirmBatch' | ||
|
||
const BatchSidebar = ({ isOpen, onToggle }: { isOpen: boolean; onToggle: (open: boolean) => void }) => { | ||
const { setTxFlow } = useContext(TxModalContext) | ||
const batchTxs = useDraftBatch() | ||
const closeSidebar = useCallback(() => onToggle(false), [onToggle]) | ||
|
||
const onAddClick = useCallback( | ||
(e: SyntheticEvent) => { | ||
e.preventDefault() | ||
closeSidebar() | ||
setTxFlow(<NewTxMenu />, undefined, false) | ||
}, | ||
[closeSidebar, setTxFlow], | ||
) | ||
|
||
const onConfirmClick = useCallback( | ||
async (e: SyntheticEvent) => { | ||
e.preventDefault() | ||
if (!batchTxs.length) return | ||
closeSidebar() | ||
setTxFlow(<ConfirmBatchFlow calls={batchTxs.map((item) => item.txData)} />) | ||
}, | ||
[setTxFlow, batchTxs, closeSidebar], | ||
) | ||
|
||
return ( | ||
<Drawer variant="temporary" anchor="right" open={isOpen} onClose={closeSidebar}> | ||
<aside className={css.aside}> | ||
<Typography variant="h4" fontWeight={700} mb={1}> | ||
Batched transactions | ||
</Typography> | ||
|
||
<Divider /> | ||
|
||
<div className={css.txs}> | ||
{batchTxs.length | ||
? batchTxs.map((item, index) => <BatchTxItem key={index} {...item} />) | ||
: 'No transactions added yet'} | ||
</div> | ||
|
||
<Button onClick={onAddClick}>+ Add new transaction</Button> | ||
|
||
<Divider /> | ||
|
||
<Button variant="contained" onClick={onConfirmClick}> | ||
Confirm batch | ||
</Button> | ||
</aside> | ||
</Drawer> | ||
) | ||
} | ||
|
||
export default BatchSidebar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.aside { | ||
margin-top: var(--header-height); | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.aside h4 { | ||
width: 100%; | ||
padding: var(--space-3) var(--space-3) 0; | ||
} | ||
|
||
.aside hr { | ||
width: 100%; | ||
margin: var(--space-3) 0; | ||
} | ||
|
||
.txs { | ||
padding: 0 var(--space-3) var(--space-3); | ||
min-width: 500px; | ||
max-width: 600px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { type ReactElement, useContext, useEffect } from 'react' | ||
import SignOrExecuteForm from '@/components/tx/SignOrExecuteForm' | ||
import { createMultiSendCallOnlyTx } from '@/services/tx/tx-sender' | ||
import { SafeTxContext } from '../../SafeTxProvider' | ||
import type { MetaTransactionData } from '@safe-global/safe-core-sdk-types' | ||
import TxLayout from '../../common/TxLayout' | ||
import BatchIcon from '@/public/images/common/batch.svg' | ||
|
||
const ConfirmBatch = ({ calls }: { calls: MetaTransactionData[] }): ReactElement => { | ||
const { setSafeTx, setSafeTxError } = useContext(SafeTxContext) | ||
|
||
useEffect(() => { | ||
createMultiSendCallOnlyTx(calls).then(setSafeTx).catch(setSafeTxError) | ||
}, [calls, setSafeTx, setSafeTxError]) | ||
|
||
return <SignOrExecuteForm onSubmit={() => {}} /> | ||
} | ||
|
||
const ConfirmBatchFlow = ({ calls }: { calls: MetaTransactionData[] }) => { | ||
return ( | ||
<TxLayout | ||
title="Confirm batch" | ||
subtitle={`This batch contains ${calls.length} transactions`} | ||
icon={BatchIcon} | ||
step={0} | ||
> | ||
<ConfirmBatch calls={calls} /> | ||
</TxLayout> | ||
) | ||
} | ||
|
||
export default ConfirmBatchFlow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useCallback } from 'react' | ||
import type { MetaTransactionData, SafeTransaction } from '@safe-global/safe-core-sdk-types' | ||
import { useAppDispatch, useAppSelector } from '@/store' | ||
import useChainId from './useChainId' | ||
import useSafeAddress from './useSafeAddress' | ||
import type { DraftBatchItem } from '@/store/batchSlice' | ||
import { selectBatchBySafe, addTx } from '@/store/batchSlice' | ||
|
||
const getMetaData = (safeTx: SafeTransaction): MetaTransactionData => { | ||
return { | ||
to: safeTx.data.to, | ||
value: safeTx.data.value, | ||
data: safeTx.data.data, | ||
operation: safeTx.data.operation, | ||
} | ||
} | ||
|
||
export const useUpdateBatch = () => { | ||
const chainId = useChainId() | ||
const safeAddress = useSafeAddress() | ||
const dispatch = useAppDispatch() | ||
|
||
return useCallback( | ||
(safeTx: SafeTransaction) => { | ||
dispatch(addTx({ chainId, safeAddress, txData: getMetaData(safeTx), timestamp: Date.now() })) | ||
}, | ||
[dispatch, chainId, safeAddress], | ||
) | ||
} | ||
|
||
export const useDraftBatch = (): DraftBatchItem[] => { | ||
const chainId = useChainId() | ||
const safeAddress = useSafeAddress() | ||
const batch = useAppSelector((state) => selectBatchBySafe(state, chainId, safeAddress)) | ||
return batch | ||
} |
Oops, something went wrong.