Refactored safeTxHistory function to integrate service url

This commit is contained in:
apanizo 2018-08-08 17:24:47 +02:00
parent b26ad98237
commit 78511b4757

View File

@ -1,5 +1,7 @@
// @flow // @flow
import { getSafeEthereumInstance } from '~/wallets/createTransactions' import { getSafeEthereumInstance } from '~/wallets/createTransactions'
import { getWeb3 } from '~/wallets/getWeb3'
import { getTxServiceUriFrom, getTxServiceHost } from '~/config'
type Type = 'confirmation' | 'execution' type Type = 'confirmation' | 'execution'
export type Operation = 0 | 1 | 2 export type Operation = 0 | 1 | 2
@ -16,20 +18,26 @@ const calculateBodyFrom = async (
type: Type, type: Type,
) => { ) => {
const gnosisSafe = await getSafeEthereumInstance(safeAddress) const gnosisSafe = await getSafeEthereumInstance(safeAddress)
const contractTransactionHash = await gnosisSafe.getTransactionHash(safeAddress, valueInWei, data, operation, nonce) const contractTransactionHash = await gnosisSafe.getTransactionHash(to, valueInWei, data, operation, nonce)
return JSON.stringify({ return JSON.stringify({
to, to: getWeb3().toChecksumAddress(to),
value: Number(valueInWei), value: valueInWei,
data, data,
operation, operation,
nonce, nonce,
contractTransactionHash, contractTransactionHash,
transactionHash, transactionHash,
sender, sender: getWeb3().toChecksumAddress(sender),
type, type,
}) })
} }
const buildTxServiceUrlFrom = (safeAddress: string) => {
const host = getTxServiceHost()
const address = getWeb3().toChecksumAddress(safeAddress)
const base = getTxServiceUriFrom(address)
return `${host}${base}`
}
export const submitOperation = async ( export const submitOperation = async (
safeAddress: string, safeAddress: string,
@ -42,13 +50,12 @@ export const submitOperation = async (
sender: string, sender: string,
type: Type, type: Type,
) => { ) => {
const base = `safes/${safeAddress}/transaction/` const url = buildTxServiceUrlFrom(safeAddress)
const url = `https://safe-transaction-history.dev.gnosisdev.com/api/v1/${base}`
const headers = { const headers = {
Accept: 'application/json', Accept: 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
} }
const body = await calculateBodyFrom(safeAddress, to, valueInWei, data, operation, nonce, txHash, sender, type) const body = await calculateBodyFrom(safeAddress, to, valueInWei, data, operation, nonce, txHash, sender, type)
const response = await fetch(url, { const response = await fetch(url, {