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 { getStandardTokenContract } from '~/logic/tokens/store/actions/fetchTokens'
export const ADD_TRANSACTIONS = 'ADD_TRANSACTIONS'
export const addTransactions = createAction<string, *>(ADD_TRANSACTIONS)
const createTransaction = (
safeAddress: string,
to: string,

View File

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