From b240c0878353ce6dca19585a26b9b3e60e4b3f8d Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Fri, 14 Jun 2019 13:57:28 +0400 Subject: [PATCH] submitting tx to history service wip --- src/logic/safe/api/index.js | 1 - src/logic/safe/api/saveTxViaService.js | 18 ------------------ src/logic/safe/transactions/index.js | 1 + src/logic/safe/transactions/send.js | 12 ++++++++++++ .../txHistory.js} | 15 ++++----------- 5 files changed, 17 insertions(+), 30 deletions(-) delete mode 100644 src/logic/safe/api/saveTxViaService.js rename src/logic/safe/{safeTxHistory.js => transactions/txHistory.js} (85%) diff --git a/src/logic/safe/api/index.js b/src/logic/safe/api/index.js index 5d04edda..84217f7b 100644 --- a/src/logic/safe/api/index.js +++ b/src/logic/safe/api/index.js @@ -1,4 +1,3 @@ // @flow export * from './estimateTxGas' -export * from './saveTxViaService' \ No newline at end of file diff --git a/src/logic/safe/api/saveTxViaService.js b/src/logic/safe/api/saveTxViaService.js deleted file mode 100644 index 1ed2b845..00000000 --- a/src/logic/safe/api/saveTxViaService.js +++ /dev/null @@ -1,18 +0,0 @@ -// @flow -import axios from 'axios' -import { getTxServiceUriFrom, getTxServiceHost } from '~/config/index' - -export const saveTxViaService = (safeAddress: string, to: string, value: string, data, operation = 0) => { - const txServiceHost = getTxServiceHost() - const txServiceUri = getTxServiceUriFrom(safeAddress) - const url = `${txServiceHost}${txServiceUri}` - // const estimationValue = isTokenTransfer(tx.data) ? '0' : value.toString(10) - - return axios.post(url, { - safe: safeAddress, - to, - data: '0x', - value, - operation, - }) -} diff --git a/src/logic/safe/transactions/index.js b/src/logic/safe/transactions/index.js index 21061b39..1910887b 100644 --- a/src/logic/safe/transactions/index.js +++ b/src/logic/safe/transactions/index.js @@ -3,3 +3,4 @@ export * from './gas' export * from './send' export * from './safeBlockchainOperations' export * from './safeTxSignerEIP712' +export * from './saveTxViaService' diff --git a/src/logic/safe/transactions/send.js b/src/logic/safe/transactions/send.js index 9252e274..cef3f64a 100644 --- a/src/logic/safe/transactions/send.js +++ b/src/logic/safe/transactions/send.js @@ -5,6 +5,7 @@ import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import { isEther } from '~/logic/tokens/utils/tokenHelpers' import { type Token } from '~/logic/tokens/store/model/token' import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' +import { saveTxViaService } from '~/logic/safe/transactions' export const CALL = 0 const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' @@ -38,6 +39,17 @@ export const executeTransaction = async ( sigs, { from: sender }, ) + await saveTxViaService( + safeInstance.address, + to, + valueInWei, + data, + nonce, + 0, + tx.tx, // tx hash, + sender, + ) + console.log(tx.tx) return tx } catch (error) { diff --git a/src/logic/safe/safeTxHistory.js b/src/logic/safe/transactions/txHistory.js similarity index 85% rename from src/logic/safe/safeTxHistory.js rename to src/logic/safe/transactions/txHistory.js index 7dd6ae84..e896c3da 100644 --- a/src/logic/safe/safeTxHistory.js +++ b/src/logic/safe/transactions/txHistory.js @@ -1,4 +1,5 @@ // @flow +import axios from 'axios' import { getWeb3 } from '~/logic/wallets/getWeb3' import { getTxServiceUriFrom, getTxServiceHost } from '~/config' import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' @@ -49,7 +50,7 @@ const calculateBodyFrom = async ( }) } -export const buildTxServiceUrlFrom = (safeAddress: string) => { +export const buildTxServiceUrl = (safeAddress: string) => { const host = getTxServiceHost() const address = getWeb3().toChecksumAddress(safeAddress) const base = getTxServiceUriFrom(address) @@ -67,18 +68,10 @@ export const submitOperation = async ( sender: string, type: TxServiceType, ) => { - const url = buildTxServiceUrlFrom(safeAddress) - const headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - } + const url = buildTxServiceUrl(safeAddress) const body = await calculateBodyFrom(safeAddress, to, valueInWei, data, operation, nonce, txHash, sender, type) - const response = await fetch(url, { - method: 'POST', - headers, - body, - }) + const response = await axios.post(url, { body }) if (response.status !== 202) { return Promise.reject(new Error('Error submitting the transaction'))