fetching transactions wip

This commit is contained in:
mmv 2019-06-18 18:09:28 +04:00
parent eb1cc5a345
commit eb3708a623
4 changed files with 72 additions and 70 deletions

View File

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

View File

@ -11,9 +11,6 @@ import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
import { executeTransaction, CALL } from '~/logic/safe/transactions' import { executeTransaction, CALL } from '~/logic/safe/transactions'
import { getStandardTokenContract } from '~/logic/tokens/store/actions/fetchTokens' import { getStandardTokenContract } from '~/logic/tokens/store/actions/fetchTokens'
export const ADD_TRANSACTIONS = 'ADD_TRANSACTIONS'
export const addTransactions = createAction<string, *>(ADD_TRANSACTIONS)
const createTransaction = ( const createTransaction = (
safeAddress: string, safeAddress: string,
to: string, to: string,

View File

@ -1,74 +1,74 @@
// // @flow // @flow
// import { List, Map } from 'immutable' import { List, Map } from 'immutable'
// import axios from 'axios' import axios from 'axios'
// import type { Dispatch as ReduxDispatch } from 'redux' import type { Dispatch as ReduxDispatch } from 'redux'
// import { type GlobalState } from '~/store/index' import { type GlobalState } from '~/store/index'
// import { makeOwner } from '~/routes/safe/store/models/owner' import { makeOwner } from '~/routes/safe/store/models/owner'
// import { makeTransaction, type Transaction } from '~/routes/safe/store/models/transaction' import { makeTransaction, type Transaction } from '~/routes/safe/store/models/transaction'
// import { makeConfirmation } from '~/routes/safe/store/models/confirmation' import { makeConfirmation } from '~/routes/safe/store/models/confirmation'
// import { loadSafeSubjects } from '~/utils/storage/transactions' import { loadSafeSubjects } from '~/utils/storage/transactions'
// import { buildTxServiceUrlFrom, type TxServiceType } from '~/logic/safe/safeTxHistory' import { buildTxServiceUrl, type TxServiceType } from '~/logic/safe/transactions/txHistory'
// import { getOwners } from '~/logic/safe/utils' import { getOwners } from '~/logic/safe/utils'
// import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import { EMPTY_DATA } from '~/logic/wallets/ethTransactions'
// import addTransactions from './addTransactions' import addTransactions from './addTransactions'
// type ConfirmationServiceModel = { type ConfirmationServiceModel = {
// owner: string, owner: string,
// submissionDate: Date, submissionDate: Date,
// type: string, type: string,
// transactionHash: string, transactionHash: string,
// } }
// type TxServiceModel = { type TxServiceModel = {
// to: string, to: string,
// value: number, value: number,
// data: string, data: string,
// operation: number, operation: number,
// nonce: number, nonce: number,
// submissionDate: Date, submissionDate: Date,
// executionDate: Date, executionDate: Date,
// confirmations: ConfirmationServiceModel[], confirmations: ConfirmationServiceModel[],
// isExecuted: boolean, isExecuted: boolean,
// } }
// const buildTransactionFrom = (safeAddress: string, tx: TxServiceModel, safeSubjects: Map<string, string>) => { const buildTransactionFrom = (safeAddress: string, tx: TxServiceModel, safeSubjects: Map<string, string>) => {
// const name = safeSubjects.get(String(tx.nonce)) || 'Unknown' const name = safeSubjects.get(String(tx.nonce)) || 'Unknown'
// const storedOwners = getOwners(safeAddress) const storedOwners = getOwners(safeAddress)
// const confirmations = List( const confirmations = List(
// tx.confirmations.map((conf: ConfirmationServiceModel) => { tx.confirmations.map((conf: ConfirmationServiceModel) => {
// const ownerName = storedOwners.get(conf.owner.toLowerCase()) || 'UNKNOWN' const ownerName = storedOwners.get(conf.owner.toLowerCase()) || 'UNKNOWN'
// return makeConfirmation({ return makeConfirmation({
// owner: makeOwner({ address: conf.owner, name: ownerName }), owner: makeOwner({ address: conf.owner, name: ownerName }),
// type: ((conf.type.toLowerCase(): any): TxServiceType), type: ((conf.type.toLowerCase(): any): TxServiceType),
// hash: conf.transactionHash, hash: conf.transactionHash,
// }) })
// }), }),
// ) )
// return makeTransaction({ return makeTransaction({
// name, name,
// nonce: tx.nonce, nonce: tx.nonce,
// value: Number(tx.value), value: Number(tx.value),
// confirmations, confirmations,
// destination: tx.to, recipient: tx.to,
// data: tx.data ? tx.data : EMPTY_DATA, data: tx.data ? tx.data : EMPTY_DATA,
// isExecuted: tx.isExecuted, isExecuted: tx.isExecuted,
// }) })
// } }
// export const loadSafeTransactions = async (safeAddress: string) => { export const loadSafeTransactions = async (safeAddress: string) => {
// const url = buildTxServiceUrlFrom(safeAddress) const url = buildTxServiceUrl(safeAddress)
// const response = await axios.get(url) const response = await axios.get(url)
// const transactions: TxServiceModel[] = response.data.results const transactions: TxServiceModel[] = response.data.results
// const safeSubjects = loadSafeSubjects(safeAddress) const safeSubjects = loadSafeSubjects(safeAddress)
// const txsRecord = transactions.map((tx: TxServiceModel) => buildTransactionFrom(safeAddress, tx, safeSubjects)) const txsRecord = transactions.map((tx: TxServiceModel) => buildTransactionFrom(safeAddress, tx, safeSubjects))
// return Map().set(safeAddress, List(txsRecord)) return Map().set(safeAddress, List(txsRecord))
// } }
// export default (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>) => { export default (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>) => {
// const transactions: Map<string, List<Transaction>> = await loadSafeTransactions(safeAddress) const transactions: Map<string, List<Transaction>> = await loadSafeTransactions(safeAddress)
// return dispatch(addTransactions(transactions)) return dispatch(addTransactions(transactions))
// } }

View File

@ -8,7 +8,7 @@ export type TransactionProps = {
nonce: number, nonce: number,
value: number, value: number,
confirmations: List<Confirmation>, confirmations: List<Confirmation>,
destination: string, recipient: string,
data: string, data: string,
isExecuted: boolean, isExecuted: boolean,
} }
@ -18,7 +18,7 @@ export const makeTransaction: RecordFactory<TransactionProps> = Record({
nonce: 0, nonce: 0,
value: 0, value: 0,
confirmations: List([]), confirmations: List([]),
destination: '', recipient: '',
data: '', data: '',
isExecuted: false, isExecuted: false,
}) })