import { createSelector } from 'reselect' import txHelper from '../../lib/tx-helper' const unapprovedTxsSelector = state => state.metamask.unapprovedTxs const unapprovedMsgsSelector = state => state.metamask.unapprovedMsgs const unapprovedPersonalMsgsSelector = state => state.metamask.unapprovedPersonalMsgs const unapprovedTypedMessagesSelector = state => state.metamask.unapprovedTypedMessages const networkSelector = state => state.metamask.network export const unconfirmedTransactionsListSelector = createSelector( unapprovedTxsSelector, unapprovedMsgsSelector, unapprovedPersonalMsgsSelector, unapprovedTypedMessagesSelector, networkSelector, ( unapprovedTxs = {}, unapprovedMsgs = {}, unapprovedPersonalMsgs = {}, unapprovedTypedMessages = {}, network ) => txHelper( unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, unapprovedTypedMessages, network ) || [] ) export const unconfirmedTransactionsHashSelector = createSelector( unapprovedTxsSelector, unapprovedMsgsSelector, unapprovedPersonalMsgsSelector, unapprovedTypedMessagesSelector, networkSelector, ( unapprovedTxs = {}, unapprovedMsgs = {}, unapprovedPersonalMsgs = {}, unapprovedTypedMessages = {}, network ) => { const filteredUnapprovedTxs = Object.keys(unapprovedTxs).reduce((acc, address) => { const { metamaskNetworkId } = unapprovedTxs[address] const transactions = { ...acc } if (metamaskNetworkId === network) { transactions[address] = unapprovedTxs[address] } return transactions }, {}) return { ...filteredUnapprovedTxs, ...unapprovedMsgs, ...unapprovedPersonalMsgs, ...unapprovedTypedMessages, } } ) export const currentCurrencySelector = state => state.metamask.currentCurrency export const conversionRateSelector = state => state.metamask.conversionRate