diff --git a/src/routes/safe/store/actions/fetchTransactions.js b/src/routes/safe/store/actions/fetchTransactions.js index c03b460f..c4850c3d 100644 --- a/src/routes/safe/store/actions/fetchTransactions.js +++ b/src/routes/safe/store/actions/fetchTransactions.js @@ -44,33 +44,23 @@ const buildTransactionFrom = (tx: TxServiceModel, safeSubjects: Map { - const safes = load(TX_KEY) || {} - const safeAddresses: string[] = Object.keys(safes) - const transactions: TxServiceModel[][] = await Promise.all(safeAddresses.map(async (safeAddress: string) => { - const url = buildTxServiceUrlFrom(safeAddress) +export const loadSafeTransactions = async (safeAddress: string) => { + const url = buildTxServiceUrlFrom(safeAddress) + const response = await enhancedFetch(url, 'Error fetching txs information') + const transactions: TxServiceModel[] = response.results + const safeSubjects = loadSafeSubjects(safeAddress) + const txsRecord = transactions.map((tx: TxServiceModel) => buildTransactionFrom(tx, safeSubjects)) - return enhancedFetch(url, 'Error fetching txs information') - })) - - return Map().withMutations((map: Map>) => { - transactions.map((safeTxs: TxServiceModel[], index) => { - const safeAddress = safeAddresses[index] - const safeSubjects = loadSafeSubjects(safeAddress) - const txsRecord = safeTxs.map((tx: TxServiceModel) => buildTransactionFrom(tx, safeSubjects)) - - return map.set(safeAddress, List(txsRecord)) - }) - }) + return Map().set(safeAddress, List(txsRecord)) } -export default () => async (dispatch: ReduxDispatch) => { - const transactions: Map> = await loadSafeTransactions() +export default (safeAddress: string) => async (dispatch: ReduxDispatch) => { + const transactions: Map> = await loadSafeTransactions(safeAddress) return dispatch(addTransactions(transactions)) }