This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 363
Merged
Developer tools #3306
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d0dafbf
build: Basic DevTool structure
iamacook cfa131d
style: Adjust layout for dev tools infos
usame-algan 7060696
build: Add nextTransaction selector
usame-algan 236f2c7
chore: Lazy import DevTools
iamacook 59a02cf
Merge branches 'dev-tool' and 'dev-tool' of github.com:gnosis/safe-re…
iamacook 2aff346
fix: Add suspense
iamacook f6015e0
chore: Lazy load based on flag
iamacook fbc7942
fix: Disable buttons when insufficient funds
iamacook 837656f
chore: Lazy import CGW toggle
iamacook 8bbcf81
fix: Extract Safe address from URL
iamacook 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,126 @@ | ||
import { ReactElement } from 'react' | ||
import { useSelector } from 'react-redux' | ||
import { useHistory } from 'react-router-dom' | ||
import styled from 'styled-components' | ||
import { fireEvent, screen, waitForElementToBeRemoved } from '@testing-library/react' | ||
import { Button } from '@gnosis.pm/safe-react-components' | ||
import List from '@material-ui/core/List' | ||
import ListItem from '@material-ui/core/ListItem' | ||
import ListItemText from '@material-ui/core/ListItemText' | ||
|
||
import { getShortName } from 'src/config' | ||
import { currentSafe } from 'src/logic/safe/store/selectors' | ||
import { generatePrefixedAddressRoutes } from 'src/routes/routes' | ||
import { ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses' | ||
import { nextTransaction } from 'src/logic/safe/store/selectors/gatewayTransactions' | ||
import { grantedSelector } from 'src/routes/safe/container/selector' | ||
|
||
const prepareTx = async (address: string): Promise<void> => { | ||
const newTxBtn = screen.getByText('New transaction') | ||
fireEvent.click(newTxBtn) | ||
|
||
const sendBtn = await screen.findByText('Send funds') | ||
fireEvent.click(sendBtn) | ||
|
||
const recipientInput = await screen.findByTestId('address-book-input') | ||
fireEvent.change(recipientInput, { target: { value: address } }) | ||
|
||
const tokenInput = await screen.findByTestId('token-input') | ||
fireEvent.change(tokenInput, { target: { value: ZERO_ADDRESS } }) | ||
|
||
const amountInput = await screen.findByPlaceholderText('Amount*') | ||
// @TODO: Check that amount is possible | ||
fireEvent.change(amountInput, { target: { value: '0.0001' } }) | ||
|
||
const reviewBtn = await screen.findByText('Review') | ||
fireEvent.click(reviewBtn) | ||
|
||
await waitForElementToBeRemoved(await screen.findByText('Estimating'), { timeout: 10000 }) | ||
} | ||
|
||
const submitTx = async (): Promise<void> => { | ||
const submitBtn = await screen.findByText('Submit') | ||
fireEvent.click(submitBtn) | ||
} | ||
|
||
const stopExecution = async (): Promise<void> => { | ||
const executionCheckbox = await screen.findByTestId('execute-checkbox') | ||
fireEvent.click(executionCheckbox) | ||
} | ||
|
||
const createQueuedTx = async (address: string): Promise<void> => { | ||
await prepareTx(address) | ||
await stopExecution() | ||
await submitTx() | ||
} | ||
|
||
const createExecutedTx = async (address: string): Promise<void> => { | ||
await prepareTx(address) | ||
await submitTx() | ||
} | ||
|
||
const getStatusUrl = (address: string): string => { | ||
return `https://rimeissner.dev/safe-status-check/#/${getShortName()}:${address}` | ||
} | ||
|
||
const DevTools = (): ReactElement => { | ||
const history = useHistory() | ||
const { owners, threshold = 1, address } = useSelector(currentSafe) ?? {} | ||
const nextTx = useSelector(nextTransaction) | ||
const isGranted = useSelector(grantedSelector) | ||
|
||
const { TRANSACTIONS_QUEUE, TRANSACTIONS_HISTORY } = generatePrefixedAddressRoutes({ | ||
shortName: getShortName(), | ||
safeAddress: address, | ||
}) | ||
|
||
return ( | ||
<> | ||
<List dense> | ||
<ListItem> | ||
<ListItemText primary="Developer Tools" secondary={`Threshold: ${threshold} / ${owners?.length || 0}`} /> | ||
</ListItem> | ||
<ListItem button> | ||
<ListItemText onClick={() => history.push(TRANSACTIONS_QUEUE)}>Queue</ListItemText> | ||
</ListItem> | ||
<ListItem button> | ||
<ListItemText onClick={() => history.push(TRANSACTIONS_HISTORY)}>History</ListItemText> | ||
</ListItem> | ||
<ListItem button> | ||
<ListItemText onClick={() => window.open(getStatusUrl(address), '_blank')}>Safe Status</ListItemText> | ||
</ListItem> | ||
</List> | ||
<ButtonWrapper> | ||
<StyledButton onClick={() => createQueuedTx(address)} size="md" variant="bordered" disabled={!isGranted}> | ||
Queue Transaction | ||
</StyledButton> | ||
<StyledButton | ||
onClick={() => createExecutedTx(address)} | ||
size="md" | ||
variant="bordered" | ||
disabled={!!nextTx || !isGranted} | ||
> | ||
Execute Transaction | ||
</StyledButton> | ||
</ButtonWrapper> | ||
</> | ||
) | ||
} | ||
|
||
export default DevTools | ||
|
||
const StyledButton = styled(Button)` | ||
&.MuiButton-root { | ||
padding: 0 12px !important; | ||
margin-top: 6px; | ||
width: 100%; | ||
} | ||
|
||
& .MuiButton-label { | ||
font-size: 14px !important; | ||
} | ||
` | ||
|
||
const ButtonWrapper = styled.div` | ||
margin: 0 12px; | ||
` |
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
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
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.
I would also lazy import it if possible, so that it's not imported on prod.