mirror of
https://github.com/status-im/safe-react.git
synced 2025-01-27 09:54:51 +00:00
createTransaction action wip
This commit is contained in:
parent
7a8a69b528
commit
ad183dfabb
@ -6,7 +6,7 @@ import { isEther } from '~/logic/tokens/utils/tokenHelpers'
|
||||
import { type Token } from '~/logic/tokens/store/model/token'
|
||||
import { getSafeEthereumInstance } from '../safeFrontendOperations'
|
||||
|
||||
const CALL = 0
|
||||
export const CALL = 0
|
||||
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
||||
|
||||
export const executeTransaction = async (
|
||||
|
@ -31,7 +31,7 @@ const saveSafe = (
|
||||
threshold: number,
|
||||
ownersName: string[],
|
||||
ownersAddress: string[],
|
||||
) => async (dispatch: ReduxDispatch<GlobalState>) => {
|
||||
) => (dispatch: ReduxDispatch<GlobalState>) => {
|
||||
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)
|
||||
|
||||
const safe: Safe = SafeRecord({
|
||||
|
@ -1,6 +0,0 @@
|
||||
// @flow
|
||||
import { createAction } from 'redux-actions'
|
||||
|
||||
export const ADD_TRANSACTIONS = 'ADD_TRANSACTIONS'
|
||||
|
||||
export default createAction<string, *>(ADD_TRANSACTIONS)
|
44
src/routes/safe/store/actions/createTransaction.js
Normal file
44
src/routes/safe/store/actions/createTransaction.js
Normal 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
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
// @flow
|
||||
import { List, Map } from 'immutable'
|
||||
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'
|
||||
|
||||
export const TRANSACTIONS_REDUCER_ID = 'transactions'
|
||||
@ -10,7 +10,7 @@ export type State = Map<string, List<Transaction>>
|
||||
|
||||
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(),
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user