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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add tx simulation * refactor: Add function return types * style: Format simulation message * change: pass manualGasLimit to tx simulation * simulateTx accepts an optional gasLimit parameter * extends .env.example by simulation variables * check that simulation env variables are set when displaying simulate button * change: improve simulation for signed txs - Signed transactions won't overwrite the threshold on tenderly - This leads to a precise simulation * feat: tx simulation for BatchExecute extended useSimulation: - dynamic to address as parameter - return resetSimulation function new design: - Simulate button as secondary button next to submit - SimulationResult styled and below buttons - SimulationResult closable / resetable on gas paramter changes * change: TxSimulation as reusable component / simulation is wrapped in accordion * change: tracking for simulation * change: refactor all specific hooks out of useSimulation Goal of this refactor is to be able to reuse useSimulation in the web-core project. Therefore all safe-react specific hooks were moved into the TxSimulation component. Adds unit test for useSimulation hook * fix: simulation during tx creation * change: show spinner when simulation is loading and disable button other changes: - renamed some variables / simplified some boolean conditions * fix: review issues - Use MUI Alert component for SimulationResult - Comments - remove functions which already existed in safe-react project * Remove unused functions * chore: add simulation .env to deploy script * fix: remove unused type * fix: typo in error message Co-authored-by: Mikhail <[email protected]> * change: Add Simulation to list of chain features - new feature TX_SIMULATION - TxSimulation checks if TX_SIMULATION is available and doesn't display simulation otherwise - typo * fix: disable simulate when submit is disabled * chore: renamed variable * refactor: hasFeature instead of looking through the list manually * fix: upgrade CGW to 3.1.3 * Fix && -> || * Check the simulation toggle in txmodalwrapper Co-authored-by: schmanu <[email protected]> Co-authored-by: Manuel Gellfart <[email protected]> Co-authored-by: Mikhail <[email protected]> Co-authored-by: katspaugh <[email protected]>
- Loading branch information
1 parent
9165bd4
commit 4dc0bd9
Showing
14 changed files
with
1,193 additions
and
69 deletions.
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
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
90 changes: 90 additions & 0 deletions
90
src/routes/safe/components/Transactions/helpers/Simulation/SimulationResult.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,90 @@ | ||
import { Icon, Link, Text } from '@gnosis.pm/safe-react-components' | ||
import { Alert, AlertTitle } from '@material-ui/lab' | ||
import { FETCH_STATUS } from 'src/utils/requests' | ||
import styled from 'styled-components' | ||
import { TenderlySimulation } from './types' | ||
|
||
const StyledAlert = styled(Alert)` | ||
align-items: flex-start; | ||
width: 100%; | ||
&.MuiAlert-standardError { | ||
background-color: #fff3f5; | ||
} | ||
&.MuiAlert-standardSuccess { | ||
background-color: #effaf8; | ||
} | ||
& .MuiIconButton-root { | ||
padding: 3px !important; | ||
} | ||
` | ||
|
||
type SimulationResultProps = { | ||
simulationRequestStatus: string | ||
simulation?: TenderlySimulation | ||
simulationLink?: string | ||
requestError?: string | ||
onClose: () => void | ||
} | ||
|
||
export const SimulationResult = ({ | ||
simulationRequestStatus, | ||
simulation, | ||
simulationLink, | ||
requestError, | ||
onClose, | ||
}: SimulationResultProps): React.ReactElement => { | ||
const isErroneous = !!requestError || !simulation?.simulation.status | ||
const isSimulationFinished = | ||
simulationRequestStatus === FETCH_STATUS.SUCCESS || simulationRequestStatus === FETCH_STATUS.ERROR | ||
|
||
return ( | ||
<> | ||
{isSimulationFinished && ( | ||
<> | ||
{isErroneous ? ( | ||
<StyledAlert severity="error" onClose={onClose} icon={<Icon type="alert" color="error" size="sm" />}> | ||
<AlertTitle> | ||
<Text color={'error'} size="lg"> | ||
<b>Failed</b> | ||
</Text> | ||
</AlertTitle> | ||
{requestError ? ( | ||
<Text color="error" size="lg"> | ||
An unexpected error occurred during simulation: <b>{requestError}</b> | ||
</Text> | ||
) : ( | ||
<Text color="inputFilled" size="lg"> | ||
The batch failed during the simulation throwing error <b>{simulation?.transaction.error_message}</b>{' '} | ||
in the contract at <b>{simulation?.transaction.error_info?.address}</b>. Full simulation report is | ||
available{' '} | ||
<Link href={simulationLink} target="_blank" rel="noreferrer" size="lg"> | ||
<b>on Tenderly</b> | ||
</Link> | ||
. | ||
</Text> | ||
)} | ||
</StyledAlert> | ||
) : ( | ||
<StyledAlert severity="success" icon={<Icon type="check" color="primary" size="sm" />} onClose={onClose}> | ||
<AlertTitle> | ||
<Text color={'primary'} size="lg"> | ||
<b>Success</b> | ||
</Text> | ||
</AlertTitle> | ||
<Text color="inputFilled" size="lg"> | ||
The batch was successfully simulated. Full simulation report is available{' '} | ||
<Link href={simulationLink} target="_blank" rel="noreferrer" size="lg"> | ||
<b>on Tenderly</b> | ||
</Link> | ||
. | ||
</Text> | ||
</StyledAlert> | ||
)} | ||
</> | ||
)} | ||
</> | ||
) | ||
} |
Oops, something went wrong.