createTransaction action wip

This commit is contained in:
Mikhail Mikheev 2019-05-24 18:10:47 +04:00
parent 7a8a69b528
commit ad183dfabb
5 changed files with 48 additions and 10 deletions

View File

@ -6,7 +6,7 @@ import { isEther } from '~/logic/tokens/utils/tokenHelpers'
import { type Token } from '~/logic/tokens/store/model/token' import { type Token } from '~/logic/tokens/store/model/token'
import { getSafeEthereumInstance } from '../safeFrontendOperations' import { getSafeEthereumInstance } from '../safeFrontendOperations'
const CALL = 0 export const CALL = 0
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
export const executeTransaction = async ( export const executeTransaction = async (

View File

@ -31,7 +31,7 @@ const saveSafe = (
threshold: number, threshold: number,
ownersName: string[], ownersName: string[],
ownersAddress: string[], ownersAddress: string[],
) => async (dispatch: ReduxDispatch<GlobalState>) => { ) => (dispatch: ReduxDispatch<GlobalState>) => {
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress) const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)
const safe: Safe = SafeRecord({ const safe: Safe = SafeRecord({

View File

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

View File

@ -0,0 +1,44 @@
// @flow
import type { Dispatch as ReduxDispatch } from 'redux'
import { createAction } from 'redux-actions'
import { getWeb3 } from '~/logic/wallets/getWeb3'
import { EMPTY_DATA } from '~/logic/wallets/ethTransactions'
import { type Token } from '~/logic/tokens/store/model/token'
import { type GlobalState } from '~/store'
import { isEther } from '~/logic/tokens/utils/tokenHelpers'
import { getSafeEthereumInstance } from '~/logic/safe/safeFrontendOperations'
import { executeTransaction, CALL } from '~/logic/safe/transactions'
import { getStandardTokenContract } from '~/logic/tokens/store/actions/fetchTokens'
export const ADD_TRANSACTIONS = 'ADD_TRANSACTIONS'
export const addTransactions = createAction<string, *>(ADD_TRANSACTIONS)
export const createTransaction = async (safeAddress: string, to: string, valueInEth: string, token: Token) => async (
dispatch: ReduxDispatch<GlobalState>,
) => {
const safeInstance = await getSafeEthereumInstance(safeAddress)
const web3 = getWeb3()
const from = web3.currentProvider.selectedAddress
const threshold = await safeInstance.getThreshold()
const nonce = await safeInstance.nonce()
const valueInWei = web3.utils.toWei(valueInEth, 'ether')
const isExecution = threshold.toNumber() === 1
let txData = EMPTY_DATA
if (!isEther(token.symbol)) {
const StandardToken = await getStandardTokenContract()
const sendToken = await StandardToken.at(token.address)
txData = sendToken.contract.transfer(to, valueInWei).encodeABI()
}
let txHash
if (isExecution) {
txHash = await executeTransaction(safeInstance, to, valueInWei, txData, CALL, nonce, from)
} else {
// txHash = await approveTransaction(safeAddress, to, valueInWei, txData, CALL, nonce)
}
// dispatch(addTransactions(txHash))
return txHash
}

View File

@ -1,7 +1,7 @@
// @flow // @flow
import { List, Map } from 'immutable' import { List, Map } from 'immutable'
import { handleActions, type ActionType } from 'redux-actions' import { handleActions, type ActionType } from 'redux-actions'
import addTransactions, { ADD_TRANSACTIONS } from '~/routes/safe/store/actions/addTransactions' import { ADD_TRANSACTIONS } from '~/routes/safe/store/actions/createTransaction'
import { type Transaction } from '~/routes/safe/store/models/transaction' import { type Transaction } from '~/routes/safe/store/models/transaction'
export const TRANSACTIONS_REDUCER_ID = 'transactions' export const TRANSACTIONS_REDUCER_ID = 'transactions'
@ -10,7 +10,7 @@ export type State = Map<string, List<Transaction>>
export default handleActions<State, *>( export default handleActions<State, *>(
{ {
[ADD_TRANSACTIONS]: (state: State, action: ActionType<typeof addTransactions>): State => action.payload, [ADD_TRANSACTIONS]: (state: State, action: ActionType<Function>): State => action.payload,
}, },
Map(), Map(),
) )