-
Notifications
You must be signed in to change notification settings - Fork 468
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
feat: Add batch execute button and tx highlighting #352
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2cc0fac
feat: Add batch execute button and tx highlighting
usame-algan 2352b55
Merge remote-tracking branch 'origin/main' into batch-execute
usame-algan 3541a7f
fix: Disable batch execute button if there are none
usame-algan 3a82c49
fix: Only display batch execute in queue, add tooltip to button
usame-algan 5fefecf
fix: Group txs inside helper function
usame-algan 4b33419
fix: Add test definitions
usame-algan 8b14be1
fix: adjust default value of batch context
usame-algan eb71155
refactor: destructure object
usame-algan 6a47cfe
fix: Add missing tests
usame-algan e12dcbf
refactor: Move batch tx logic into hook
usame-algan d318c75
fix: Increase batch limit to 20
usame-algan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,24 @@ | ||
import { styled } from '@mui/material/styles' | ||
import Tooltip, { tooltipClasses, TooltipProps } from '@mui/material/Tooltip' | ||
|
||
const CustomTooltip = styled(({ className, ...props }: TooltipProps) => ( | ||
<Tooltip {...props} classes={{ popper: className }} /> | ||
))(({ theme }) => ({ | ||
[`& .${tooltipClasses.tooltip}`]: { | ||
color: theme.palette.common.black, | ||
backgroundColor: theme.palette.common.white, | ||
borderRadius: '8px', | ||
boxShadow: '1px 2px 10px rgba(40, 54, 61, 0.18)', | ||
fontSize: '14px', | ||
padding: '16px', | ||
lineHeight: 'normal', | ||
}, | ||
[`& .${tooltipClasses.arrow}`]: { | ||
'&::before': { | ||
backgroundColor: theme.palette.common.white, | ||
boxShadow: '1px 2px 10px rgba(40, 54, 61, 0.18)', | ||
}, | ||
}, | ||
})) | ||
|
||
export default CustomTooltip |
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
20 changes: 20 additions & 0 deletions
20
src/components/transactions/BatchExecuteButton/BatchExecuteHoverProvider.tsx
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,20 @@ | ||
import { createContext, ReactElement, ReactNode, useState } from 'react' | ||
|
||
export const BatchExecuteHoverContext = createContext<{ | ||
activeHover: string[] | ||
setActiveHover: (activeHover: string[]) => void | ||
}>({ | ||
activeHover: [], | ||
setActiveHover: () => {}, | ||
}) | ||
|
||
// Used for highlighting transactions that will be included when executing them as a batch | ||
export const BatchExecuteHoverProvider = ({ children }: { children: ReactNode }): ReactElement => { | ||
const [activeHover, setActiveHover] = useState<string[]>([]) | ||
|
||
return ( | ||
<BatchExecuteHoverContext.Provider value={{ activeHover, setActiveHover }}> | ||
{children} | ||
</BatchExecuteHoverContext.Provider> | ||
) | ||
} |
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,52 @@ | ||
import { useCallback, useContext } from 'react' | ||
import { Button } from '@mui/material' | ||
import css from './styles.module.css' | ||
import { BatchExecuteHoverContext } from '@/components/transactions/BatchExecuteButton/BatchExecuteHoverProvider' | ||
import { Transaction, TransactionListItem } from '@gnosis.pm/safe-react-gateway-sdk' | ||
import { useAppSelector } from '@/store' | ||
import { selectPendingTxs } from '@/store/pendingTxsSlice' | ||
import CustomTooltip from '@/components/common/CustomTooltip' | ||
import useBatchedTxs from '@/hooks/useBatchedTxs' | ||
|
||
const BatchExecuteButton = ({ items }: { items: (TransactionListItem | Transaction[])[] }) => { | ||
const pendingTxs = useAppSelector(selectPendingTxs) | ||
const hoverContext = useContext(BatchExecuteHoverContext) | ||
const batchableTransactions = useBatchedTxs(items) | ||
|
||
const isBatchable = batchableTransactions.length > 1 | ||
const hasPendingTx = batchableTransactions.some((tx) => pendingTxs[tx.transaction.id]) | ||
const isDisabled = !isBatchable || hasPendingTx | ||
|
||
const handleOnMouseEnter = useCallback(() => { | ||
hoverContext.setActiveHover(batchableTransactions.map((tx) => tx.transaction.id)) | ||
}, [batchableTransactions, hoverContext]) | ||
|
||
const handleOnMouseLeave = useCallback(() => { | ||
hoverContext.setActiveHover([]) | ||
}, [hoverContext]) | ||
|
||
return ( | ||
<CustomTooltip | ||
placement="top-start" | ||
arrow | ||
title={ | ||
isDisabled | ||
? 'Batch execution is only available for transactions that have been fully signed and are strictly sequential in Safe nonce.' | ||
: 'All transactions highlighted in light green will be included in the batch execution.' | ||
} | ||
> | ||
<Button | ||
onMouseEnter={handleOnMouseEnter} | ||
onMouseLeave={handleOnMouseLeave} | ||
className={css.button} | ||
variant="contained" | ||
size="small" | ||
disabled={isDisabled} | ||
> | ||
Execute Batch {isBatchable && ` (${batchableTransactions.length})`} | ||
</Button> | ||
</CustomTooltip> | ||
) | ||
} | ||
|
||
export default BatchExecuteButton |
5 changes: 5 additions & 0 deletions
5
src/components/transactions/BatchExecuteButton/styles.module.css
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,5 @@ | ||
.button { | ||
position: absolute; | ||
right: 0; | ||
top: -50px; | ||
} |
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,7 @@ | ||
.active { | ||
border-color: var(--color-primary-light); | ||
} | ||
|
||
.active :global .MuiAccordionSummary-root { | ||
background-color: var(--color-primary-background); | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only extracted this so it can be reused