From 1a5beb16a441d3c395e01ac5f419b0d61834d76f Mon Sep 17 00:00:00 2001 From: mmv Date: Tue, 18 Jun 2019 18:37:02 +0400 Subject: [PATCH] fetching transactions wip --- src/logic/safe/utils/safeStorage.js | 2 +- src/routes/safe/components/Layout.jsx | 13 +++++++++++-- .../safe/components/TransactionsNew/index.jsx | 17 +++++++++++------ src/routes/safe/container/actions.js | 3 +++ src/routes/safe/container/index.jsx | 11 ++++++++++- .../safe/store/actions/fetchTransactions.js | 10 ++++++---- src/routes/safe/store/reducer/transactions.js | 2 +- 7 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/logic/safe/utils/safeStorage.js b/src/logic/safe/utils/safeStorage.js index 2301a5e1..14a885c3 100644 --- a/src/logic/safe/utils/safeStorage.js +++ b/src/logic/safe/utils/safeStorage.js @@ -38,6 +38,6 @@ export const setOwners = async (safeAddress: string, owners: List) => { export const getOwners = async (safeAddress: string): Map => { const data: Object = await loadFromStorage(`${OWNERS_KEY}-${safeAddress}`) - + console.log(data) return data ? Map(data) : Map() } diff --git a/src/routes/safe/components/Layout.jsx b/src/routes/safe/components/Layout.jsx index 055b03be..0970285d 100644 --- a/src/routes/safe/components/Layout.jsx +++ b/src/routes/safe/components/Layout.jsx @@ -25,6 +25,7 @@ type Props = SelectorProps & { classes: Object, granted: boolean, createTransaction: Function, + fetchTransactions: Function, } type State = { @@ -90,7 +91,15 @@ class Layout extends React.Component { render() { const { - safe, provider, network, classes, granted, tokens, activeTokens, createTransaction, + safe, + provider, + network, + classes, + granted, + tokens, + activeTokens, + createTransaction, + fetchTransactions, } = this.props const { tabIndex } = this.state @@ -142,7 +151,7 @@ class Layout extends React.Component { createTransaction={createTransaction} /> )} - {tabIndex === 1 && } + {tabIndex === 1 && } ) } diff --git a/src/routes/safe/components/TransactionsNew/index.jsx b/src/routes/safe/components/TransactionsNew/index.jsx index 1e979ebc..bb5b1bc9 100644 --- a/src/routes/safe/components/TransactionsNew/index.jsx +++ b/src/routes/safe/components/TransactionsNew/index.jsx @@ -3,13 +3,18 @@ import * as React from 'react' import { List } from 'immutable' import NoTransactions from '~/routes/safe/components/Transactions/NoTransactions' -type Props = SelectorProps & - Actions & { - safeName: string, - safeAddress: string, - threshold: number, - } +type Props = { + safeAddress: string, + threshold: number, +} + class Transactions extends React.Component { + componentDidMount() { + const { safeAddress, fetchTransactions } = this.props + + fetchTransactions(safeAddress) + } + render() { const { transactions = List(), safeName, threshold } = this.props const hasTransactions = false diff --git a/src/routes/safe/container/actions.js b/src/routes/safe/container/actions.js index 41636c2a..113ef20f 100644 --- a/src/routes/safe/container/actions.js +++ b/src/routes/safe/container/actions.js @@ -2,15 +2,18 @@ import fetchSafe from '~/routes/safe/store/actions/fetchSafe' import fetchTokenBalances from '~/routes/safe/store/actions/fetchTokenBalances' import createTransaction from '~/routes/safe/store/actions/createTransaction' +import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions' export type Actions = { fetchSafe: typeof fetchSafe, fetchTokenBalances: typeof fetchTokenBalances, createTransaction: typeof createTransaction, + fetchTransactions: typeof fetchTransactions, } export default { fetchSafe, fetchTokenBalances, createTransaction, + fetchTransactions, } diff --git a/src/routes/safe/container/index.jsx b/src/routes/safe/container/index.jsx index bd0a7b68..2c3df22b 100644 --- a/src/routes/safe/container/index.jsx +++ b/src/routes/safe/container/index.jsx @@ -52,7 +52,15 @@ class SafeView extends React.Component { render() { const { - safe, provider, activeTokens, granted, userAddress, network, tokens, createTransaction, + safe, + provider, + activeTokens, + granted, + userAddress, + network, + tokens, + createTransaction, + fetchTransactions, } = this.props return ( @@ -66,6 +74,7 @@ class SafeView extends React.Component { network={network} granted={granted} createTransaction={createTransaction} + fetchTransactions={fetchTransactions} /> ) diff --git a/src/routes/safe/store/actions/fetchTransactions.js b/src/routes/safe/store/actions/fetchTransactions.js index 2de83c9c..d50f31ef 100644 --- a/src/routes/safe/store/actions/fetchTransactions.js +++ b/src/routes/safe/store/actions/fetchTransactions.js @@ -10,7 +10,7 @@ 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' +import { addTransactions } from './addTransactions' type ConfirmationServiceModel = { owner: string, @@ -31,9 +31,9 @@ type TxServiceModel = { isExecuted: boolean, } -const buildTransactionFrom = (safeAddress: string, tx: TxServiceModel, safeSubjects: Map) => { +const buildTransactionFrom = async (safeAddress: string, tx: TxServiceModel, safeSubjects: Map) => { const name = safeSubjects.get(String(tx.nonce)) || 'Unknown' - const storedOwners = getOwners(safeAddress) + const storedOwners = await getOwners(safeAddress) const confirmations = List( tx.confirmations.map((conf: ConfirmationServiceModel) => { const ownerName = storedOwners.get(conf.owner.toLowerCase()) || 'UNKNOWN' @@ -62,7 +62,9 @@ export const loadSafeTransactions = async (safeAddress: string) => { 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)) + const txsRecord = transactions.map( + async (tx: TxServiceModel) => await buildTransactionFrom(safeAddress, tx, safeSubjects), + ) return Map().set(safeAddress, List(txsRecord)) } diff --git a/src/routes/safe/store/reducer/transactions.js b/src/routes/safe/store/reducer/transactions.js index 68e8be77..ae2fb909 100644 --- a/src/routes/safe/store/reducer/transactions.js +++ b/src/routes/safe/store/reducer/transactions.js @@ -1,7 +1,7 @@ // @flow import { List, Map } from 'immutable' import { handleActions, type ActionType } from 'redux-actions' -import { ADD_TRANSACTIONS } from '~/routes/safe/store/actions/createTransaction' +import { ADD_TRANSACTIONS } from '~/routes/safe/store/actions/addTransactions' import { type Transaction } from '~/routes/safe/store/models/transaction' export const TRANSACTIONS_REDUCER_ID = 'transactions'