WA-521 Include owners name when fetching transactions

This commit is contained in:
apanizo 2018-08-17 11:43:12 +02:00
parent 0f563a2b56
commit b868dcd6f3
1 changed files with 11 additions and 6 deletions

View File

@ -8,6 +8,7 @@ import { makeConfirmation } from '~/routes/safe/store/model/confirmation'
import { loadSafeSubjects } from '~/utils/localStorage/transactions' import { loadSafeSubjects } from '~/utils/localStorage/transactions'
import { buildTxServiceUrlFrom, type TxServiceType } from '~/logic/safe/safeTxHistory' import { buildTxServiceUrlFrom, type TxServiceType } from '~/logic/safe/safeTxHistory'
import { enhancedFetch } from '~/utils/fetch' import { enhancedFetch } from '~/utils/fetch'
import { getOwners } from '~/utils/localStorage'
import addTransactions from './addTransactions' import addTransactions from './addTransactions'
type ConfirmationServiceModel = { type ConfirmationServiceModel = {
@ -29,14 +30,18 @@ type TxServiceModel = {
isExecuted: boolean, isExecuted: boolean,
} }
const buildTransactionFrom = (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 confirmations = List(tx.confirmations.map((conf: ConfirmationServiceModel) => const storedOwners = getOwners(safeAddress)
makeConfirmation({ const confirmations = List(tx.confirmations.map((conf: ConfirmationServiceModel) => {
owner: makeOwner({ address: conf.owner }), const ownerName = storedOwners.get(conf.owner.toLowerCase()) || 'UNKNOWN'
return makeConfirmation({
owner: makeOwner({ address: conf.owner, name: ownerName }),
type: conf.type, type: conf.type,
hash: conf.transactionHash, hash: conf.transactionHash,
}))) })
}))
return makeTransaction({ return makeTransaction({
name, name,
@ -54,7 +59,7 @@ export const loadSafeTransactions = async (safeAddress: string) => {
const response = await enhancedFetch(url, 'Error fetching txs information') const response = await enhancedFetch(url, 'Error fetching txs information')
const transactions: TxServiceModel[] = response.results const transactions: TxServiceModel[] = response.results
const safeSubjects = loadSafeSubjects(safeAddress) const safeSubjects = loadSafeSubjects(safeAddress)
const txsRecord = transactions.map((tx: TxServiceModel) => buildTransactionFrom(tx, safeSubjects)) const txsRecord = transactions.map((tx: TxServiceModel) => buildTransactionFrom(safeAddress, tx, safeSubjects))
return Map().set(safeAddress, List(txsRecord)) return Map().set(safeAddress, List(txsRecord))
} }