From d2f80ead6131e4c6b9fc8b45f1c40ba265a6d63c Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Mon, 20 Apr 2020 18:27:26 +0400 Subject: [PATCH] Sync notifications and state: createTransaction WIP --- src/logic/safe/transactions/gasNew.js | 13 ++++++++- .../safe/store/actions/createTransaction.js | 29 +++++++++++++++++-- .../safe/store/actions/updateTransaction.js | 8 +++++ src/routes/safe/store/reducer/transactions.js | 21 ++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/routes/safe/store/actions/updateTransaction.js diff --git a/src/logic/safe/transactions/gasNew.js b/src/logic/safe/transactions/gasNew.js index 15c33c17..f04a5a32 100644 --- a/src/logic/safe/transactions/gasNew.js +++ b/src/logic/safe/transactions/gasNew.js @@ -54,7 +54,18 @@ export const estimateTxGasCosts = async ( '', )}000000000000000000000000000000000000000000000000000000000000000001` txData = await safeInstance.methods - .execTransaction(to, tx ? tx.value : 0, data, CALL, 0, 0, 0, ZERO_ADDRESS, ZERO_ADDRESS, signatures) + .execTransaction( + to, + tx ? tx.value : 0, + data, + CALL, + tx ? tx.safeTxGas : 0, + 0, + 0, + ZERO_ADDRESS, + ZERO_ADDRESS, + signatures, + ) .encodeABI() } else { const txHash = await safeInstance.methods diff --git a/src/routes/safe/store/actions/createTransaction.js b/src/routes/safe/store/actions/createTransaction.js index 105e3f07..29ff6a68 100644 --- a/src/routes/safe/store/actions/createTransaction.js +++ b/src/routes/safe/store/actions/createTransaction.js @@ -1,8 +1,13 @@ // @flow import { push } from 'connected-react-router' +import { List } from 'immutable' import type { GetState, Dispatch as ReduxDispatch } from 'redux' import semverSatisfies from 'semver/functions/satisfies' +import { makeConfirmation } from '../models/confirmation' + +import updateTransaction from './updateTransaction' + import { onboardUser } from '~/components/ConnectButton' import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import { type NotificationsQueue, getNotificationsFromTxType, showSnackbar } from '~/logic/notifications' @@ -105,7 +110,7 @@ const createTransaction = ({ // Couldn't find an issue for trezor but the error is almost the same const canTryOffchainSigning = !isExecution && !smartContractWallet && semverSatisfies(safeVersion, SAFE_VERSION_FOR_OFFCHAIN_SIGNATURES) - if (canTryOffchainSigning) { + if (false) { const signature = await tryOffchainSigning({ ...txArgs, safeAddress }, hardwareWallet) if (signature) { @@ -151,7 +156,7 @@ const createTransaction = ({ txHash, origin, }) - dispatch(fetchTransactions(safeAddress)) + await dispatch(fetchTransactions(safeAddress)) } catch (err) { console.error(err) } @@ -160,7 +165,27 @@ const createTransaction = ({ console.error('Tx error: ', error) }) .then((receipt) => { + console.log(receipt) closeSnackbar(pendingExecutionKey) + const safeTxHash = isExecution ? 'lol' : receipt.events.ApproveHash.returnValues[0] + + dispatch( + updateTransaction({ + safeAddress, + transaction: { + safeTxHash, + confirmations: List([ + makeConfirmation({ + type: 'confirmation', + hash: receipt.transactionHash, + signature: sigs, + owner: { address: '0x000', name: 'Test' }, + }), + ]), + }, + }), + ) + showSnackbar( isExecution ? notificationsQueue.afterExecution.noMoreConfirmationsNeeded diff --git a/src/routes/safe/store/actions/updateTransaction.js b/src/routes/safe/store/actions/updateTransaction.js new file mode 100644 index 00000000..9b2b050e --- /dev/null +++ b/src/routes/safe/store/actions/updateTransaction.js @@ -0,0 +1,8 @@ +// @flow +import { createAction } from 'redux-actions' + +export const UPDATE_TRANSACTION = 'UPDATE_TRANSACTION' + +const updateTransaction = createAction(UPDATE_TRANSACTION) + +export default updateTransaction diff --git a/src/routes/safe/store/reducer/transactions.js b/src/routes/safe/store/reducer/transactions.js index bc08a7bb..f52bdac6 100644 --- a/src/routes/safe/store/reducer/transactions.js +++ b/src/routes/safe/store/reducer/transactions.js @@ -3,6 +3,7 @@ import { List, Map } from 'immutable' import { type ActionType, handleActions } from 'redux-actions' import { ADD_TRANSACTIONS } from '~/routes/safe/store/actions/addTransactions' +import { UPDATE_TRANSACTION } from '~/routes/safe/store/actions/updateTransaction' import { type Transaction } from '~/routes/safe/store/models/transaction' export const TRANSACTIONS_REDUCER_ID = 'transactions' @@ -12,6 +13,26 @@ export type State = Map> export default handleActions( { [ADD_TRANSACTIONS]: (state: State, action: ActionType): State => action.payload, + [UPDATE_TRANSACTION]: (state: State, action: ActionType): State => { + const { safeAddress, transaction } = action.payload + + const transactionList = state.get(safeAddress) + + if (!transaction) { + return state + } + + const storedTransactionIndex = transactionList.findIndex((tx) => tx.safeTxHash === transaction.safeTxHash) + + if (!storedTransactionIndex < 0) { + return state + } + + return state.set( + safeAddress, + transactionList.update(storedTransactionIndex, (tx) => tx.merge(transaction)), + ) + }, }, Map(), )