From eb3708a62303b82368b40b0087059fa5e5f4ba88 Mon Sep 17 00:00:00 2001 From: mmv Date: Tue, 18 Jun 2019 18:09:28 +0400 Subject: [PATCH] fetching transactions wip --- .../safe/store/actions/addTransactions.js | 5 + .../safe/store/actions/createTransaction.js | 3 - .../safe/store/actions/fetchTransactions.js | 130 +++++++++--------- src/routes/safe/store/models/transaction.js | 4 +- 4 files changed, 72 insertions(+), 70 deletions(-) create mode 100644 src/routes/safe/store/actions/addTransactions.js diff --git a/src/routes/safe/store/actions/addTransactions.js b/src/routes/safe/store/actions/addTransactions.js new file mode 100644 index 00000000..50086b5a --- /dev/null +++ b/src/routes/safe/store/actions/addTransactions.js @@ -0,0 +1,5 @@ +// @flow +import { createAction } from 'redux-actions' + +export const ADD_TRANSACTIONS = 'ADD_TRANSACTIONS' +export const addTransactions = createAction(ADD_TRANSACTIONS) diff --git a/src/routes/safe/store/actions/createTransaction.js b/src/routes/safe/store/actions/createTransaction.js index 662b060d..c512f46d 100644 --- a/src/routes/safe/store/actions/createTransaction.js +++ b/src/routes/safe/store/actions/createTransaction.js @@ -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(ADD_TRANSACTIONS) - const createTransaction = ( safeAddress: string, to: string, diff --git a/src/routes/safe/store/actions/fetchTransactions.js b/src/routes/safe/store/actions/fetchTransactions.js index fce22749..2de83c9c 100644 --- a/src/routes/safe/store/actions/fetchTransactions.js +++ b/src/routes/safe/store/actions/fetchTransactions.js @@ -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) => { -// 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) => { + 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) => { -// const transactions: Map> = await loadSafeTransactions(safeAddress) +export default (safeAddress: string) => async (dispatch: ReduxDispatch) => { + const transactions: Map> = await loadSafeTransactions(safeAddress) -// return dispatch(addTransactions(transactions)) -// } + return dispatch(addTransactions(transactions)) +} diff --git a/src/routes/safe/store/models/transaction.js b/src/routes/safe/store/models/transaction.js index e2e4e096..76e54419 100644 --- a/src/routes/safe/store/models/transaction.js +++ b/src/routes/safe/store/models/transaction.js @@ -8,7 +8,7 @@ export type TransactionProps = { nonce: number, value: number, confirmations: List, - destination: string, + recipient: string, data: string, isExecuted: boolean, } @@ -18,7 +18,7 @@ export const makeTransaction: RecordFactory = Record({ nonce: 0, value: 0, confirmations: List([]), - destination: '', + recipient: '', data: '', isExecuted: false, })