Sync notifications and state: createTransaction WIP

This commit is contained in:
Mikhail Mikheev 2020-04-20 18:27:26 +04:00
parent 9d95198a20
commit d2f80ead61
4 changed files with 68 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,8 @@
// @flow
import { createAction } from 'redux-actions'
export const UPDATE_TRANSACTION = 'UPDATE_TRANSACTION'
const updateTransaction = createAction<string, *>(UPDATE_TRANSACTION)
export default updateTransaction

View File

@ -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<string, List<Transaction>>
export default handleActions<State, *>(
{
[ADD_TRANSACTIONS]: (state: State, action: ActionType<Function>): State => action.payload,
[UPDATE_TRANSACTION]: (state: State, action: ActionType<Function>): 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(),
)