Pass notifications to createTransaction/executeTransaction to allow custom messages WIP

This commit is contained in:
Mikhail Mikheev 2019-09-04 19:27:19 +04:00
parent 753e46a243
commit 590147682a
5 changed files with 67 additions and 49 deletions

View File

@ -20,11 +20,7 @@ export const SharedSnackbar = () => (
autoHideDuration={4000}
onClose={closeSnackbar}
>
<SnackbarContent
onClose={closeSnackbar}
message={message}
variant={variant}
/>
<SnackbarContent onClose={closeSnackbar} message={message} variant={variant} />
</Snackbar>
)
}}
@ -60,11 +56,15 @@ type State = {
}
export class SharedSnackbarProvider extends React.Component<Props, State> {
state = {
constructor(props: Props) {
super(props)
this.state = {
isOpen: false,
message: '',
variant: 'info',
}
}
openSnackbar = (message: string, variant: Variant) => {
this.setState({

View File

@ -108,11 +108,9 @@ export const executeTransaction = async (
.execTransaction(to, valueInWei, data, operation, 0, 0, 0, ZERO_ADDRESS, ZERO_ADDRESS, sigs)
.encodeABI()
const errMsg = await getErrorMessage(safeInstance.address, 0, executeDataUsedSignatures, sender)
console.log(`Error executing the TX: ${error}`)
console.log(`Error executing the TX: ${errMsg}`)
/* eslint-enable */
return 0
throw error;
}
}

View File

@ -46,7 +46,9 @@ export const sendRemoveOwner = async (
) => {
const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress)
const safeOwners = await gnosisSafe.getOwners()
const index = safeOwners.findIndex(ownerAddress => ownerAddress.toLowerCase() === ownerAddressToRemove.toLowerCase())
const index = safeOwners.findIndex(
(ownerAddress) => ownerAddress.toLowerCase() === ownerAddressToRemove.toLowerCase(),
)
const prevAddress = index === 0 ? SENTINEL_ADDRESS : safeOwners[index - 1]
const txData = gnosisSafe.contract.methods
.removeOwner(prevAddress, ownerAddressToRemove, values.threshold)
@ -103,12 +105,11 @@ const RemoveOwner = ({
}
return (
<React.Fragment>
<>
<SharedSnackbarConsumer>
{({ openSnackbar }) => {
const onRemoveOwner = () => {
onClose()
try {
sendRemoveOwner(
values,
safeAddress,
@ -119,10 +120,6 @@ const RemoveOwner = ({
createTransaction,
removeSafeOwner,
)
} catch (error) {
// eslint-disable-next-line
console.log('Error while removing an owner ' + error)
}
}
return (
@ -133,7 +130,7 @@ const RemoveOwner = ({
open={isOpen}
paperClassName={classes.biggerModalWindow}
>
<React.Fragment>
<>
{activeScreen === 'checkOwner' && (
<CheckOwner
onClose={onClose}
@ -165,12 +162,12 @@ const RemoveOwner = ({
onSubmit={onRemoveOwner}
/>
)}
</React.Fragment>
</>
</Modal>
)
}}
</SharedSnackbarConsumer>
</React.Fragment>
</>
)
}

View File

@ -56,7 +56,7 @@ const ReviewRemoveOwner = ({
}
return (
<React.Fragment>
<>
<Row align="center" grow className={classes.heading}>
<Paragraph weight="bolder" className={classes.manage} noMargin>
Remove owner
@ -91,11 +91,10 @@ const ReviewRemoveOwner = ({
<Paragraph size="lg" color="primary" noMargin weight="bolder" className={classes.name}>
{values.threshold}
{' '}
out of
{' '}
out of
{owners.size - 1}
{' '}
owner(s)
owner(s)
</Paragraph>
</Block>
</Block>
@ -105,12 +104,12 @@ const ReviewRemoveOwner = ({
<Paragraph size="lg" color="primary" noMargin>
{owners.size - 1}
{' '}
Safe owner(s)
Safe owner(s)
</Paragraph>
</Row>
<Hairline />
{owners.map(
owner => owner.address !== ownerAddress && (
(owner) => owner.address !== ownerAddress && (
<React.Fragment key={owner.address}>
<Row className={classes.owner}>
<Col xs={1} align="center">
@ -159,7 +158,11 @@ const ReviewRemoveOwner = ({
<Paragraph size="md" color="disabled" noMargin>
{ownerAddress}
</Paragraph>
<Link className={classes.open} to={getEtherScanLink('address', ownerAddress, network)} target="_blank">
<Link
className={classes.open}
to={getEtherScanLink('address', ownerAddress, network)}
target="_blank"
>
<OpenInNew style={openIconStyle} />
</Link>
</Block>
@ -187,7 +190,7 @@ const ReviewRemoveOwner = ({
Submit
</Button>
</Row>
</React.Fragment>
</>
)
}

View File

@ -7,6 +7,20 @@ import { type GlobalState } from '~/store'
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
import { approveTransaction, executeTransaction, CALL } from '~/logic/safe/transactions'
export type Notifications = {
BEFORE_EXECUTION_OR_CREATION: string,
AFTER_EXECUTION: string,
CREATED_MORE_CONFIRMATIONS_NEEDED: string,
ERROR: string,
}
const DEFAULT_NOTIFICATIONS: Notifications = {
BEFORE_EXECUTION_OR_CREATION: 'Transaction in progress',
AFTER_EXECUTION: 'Transaction successfully executed',
CREATED_MORE_CONFIRMATIONS_NEEDED: 'Transaction in progress: More confirmations required to execute',
ERROR: 'Transaction failed',
}
const createTransaction = (
safeAddress: string,
to: string,
@ -14,6 +28,7 @@ const createTransaction = (
txData: string = EMPTY_DATA,
openSnackbar: Function,
shouldExecute?: boolean,
notifications?: Notifications = DEFAULT_NOTIFICATIONS,
) => async (dispatch: ReduxDispatch<GlobalState>, getState: GetState<GlobalState>) => {
const state: GlobalState = getState()
@ -24,14 +39,19 @@ const createTransaction = (
const isExecution = threshold.toNumber() === 1 || shouldExecute
let txHash
try {
if (isExecution) {
openSnackbar('Transaction has been submitted', 'success')
openSnackbar(notifications.BEFORE_EXECUTION_OR_CREATION, 'success')
txHash = await executeTransaction(safeInstance, to, valueInWei, txData, CALL, nonce, from)
openSnackbar('Transaction has been confirmed', 'success')
openSnackbar(notifications.AFTER_EXECUTION, 'success')
} else {
openSnackbar('Approval transaction has been submitted', 'success')
openSnackbar(notifications.BEFORE_EXECUTION_OR_CREATION, 'success')
txHash = await approveTransaction(safeInstance, to, valueInWei, txData, CALL, nonce, from)
openSnackbar('Approval transaction has been confirmed', 'success')
openSnackbar(notifications.CREATED_MORE_CONFIRMATIONS_NEEDED, 'success')
}
} catch (err) {
openSnackbar(notifications.ERROR, '')
console.error(`Error while creating transaction: ${err}`)
}
dispatch(fetchTransactions(safeAddress))