mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 17:33:23 +01:00
Consolidate and dedupe send selectors (#8506)
* consolidate & dedupe send selectors
This commit is contained in:
parent
eacdb5d920
commit
e8fa0b7b5d
@ -1,10 +1,6 @@
|
|||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import * as selectors from '../../../../ui/app/selectors'
|
import * as selectors from '../../../../ui/app/selectors'
|
||||||
import mockState from '../../../data/mock-state.json'
|
import mockState from '../../../data/mock-state.json'
|
||||||
import Eth from 'ethjs'
|
|
||||||
import { createTestProviderTools } from '../../../stub/provider'
|
|
||||||
|
|
||||||
const provider = createTestProviderTools({ scaffold: {} }).provider
|
|
||||||
|
|
||||||
describe('Selectors', function () {
|
describe('Selectors', function () {
|
||||||
|
|
||||||
@ -21,9 +17,13 @@ describe('Selectors', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('returns selected identity', function () {
|
it('returns selected identity', function () {
|
||||||
const identity = selectors.getSelectedIdentity(mockState)
|
assert.deepEqual(
|
||||||
assert.equal(identity.address, '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc')
|
selectors.getSelectedIdentity(mockState),
|
||||||
assert.equal(identity.name, 'Test Account')
|
{
|
||||||
|
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||||||
|
name: 'Test Account',
|
||||||
|
}
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns selected account', function () {
|
it('returns selected account', function () {
|
||||||
@ -76,22 +76,11 @@ describe('Selectors', function () {
|
|||||||
assert.equal(gasIsLoading, false)
|
assert.equal(gasIsLoading, false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getSendAmount', function () {
|
|
||||||
const sendAmount = selectors.getSendAmount(mockState)
|
|
||||||
assert.equal(sendAmount, '1bc16d674ec80000')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('#getCurrentCurrency', function () {
|
it('#getCurrentCurrency', function () {
|
||||||
const currentCurrency = selectors.getCurrentCurrency(mockState)
|
const currentCurrency = selectors.getCurrentCurrency(mockState)
|
||||||
assert.equal(currentCurrency, 'usd')
|
assert.equal(currentCurrency, 'usd')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getSelectedTokenContract', function () {
|
|
||||||
global.eth = new Eth(provider)
|
|
||||||
const selectedTokenContract = selectors.getSelectedTokenContract(mockState)
|
|
||||||
assert(selectedTokenContract.abi)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('#getTotalUnapprovedCount', function () {
|
it('#getTotalUnapprovedCount', function () {
|
||||||
const totalUnapprovedCount = selectors.getTotalUnapprovedCount(mockState)
|
const totalUnapprovedCount = selectors.getTotalUnapprovedCount(mockState)
|
||||||
assert.equal(totalUnapprovedCount, 1)
|
assert.equal(totalUnapprovedCount, 1)
|
||||||
|
@ -3,8 +3,11 @@ import { withRouter } from 'react-router-dom'
|
|||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import AccountDetailsDropdown from './account-details-dropdown.component'
|
import AccountDetailsDropdown from './account-details-dropdown.component'
|
||||||
import * as actions from '../../../../store/actions'
|
import * as actions from '../../../../store/actions'
|
||||||
import { getSelectedIdentity, getRpcPrefsForCurrentProvider } from '../../../../selectors'
|
import {
|
||||||
import genAccountLink from '../../../../../lib/account-link.js'
|
getSelectedIdentity,
|
||||||
|
getRpcPrefsForCurrentProvider,
|
||||||
|
} from '../../../../selectors'
|
||||||
|
import genAccountLink from '../../../../../lib/account-link'
|
||||||
|
|
||||||
function mapStateToProps (state) {
|
function mapStateToProps (state) {
|
||||||
return {
|
return {
|
||||||
|
@ -42,11 +42,10 @@ import {
|
|||||||
getBasicGasEstimateBlockTime,
|
getBasicGasEstimateBlockTime,
|
||||||
getTxParams,
|
getTxParams,
|
||||||
isCustomPriceSafe,
|
isCustomPriceSafe,
|
||||||
} from '../../../../selectors'
|
|
||||||
import {
|
|
||||||
getTokenBalance,
|
getTokenBalance,
|
||||||
getSendMaxModeState,
|
getSendMaxModeState,
|
||||||
} from '../../../../selectors/send'
|
} from '../../../../selectors'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
formatCurrency,
|
formatCurrency,
|
||||||
} from '../../../../helpers/utils/confirm-tx.util'
|
} from '../../../../helpers/utils/confirm-tx.util'
|
||||||
|
@ -35,20 +35,18 @@ proxyquire('../gas-modal-page-container.container.js', {
|
|||||||
return () => ({})
|
return () => ({})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'../../../../selectors/': {
|
'../../../../selectors': {
|
||||||
getBasicGasEstimateLoadingStatus: (s) => `mockBasicGasEstimateLoadingStatus:${Object.keys(s).length}`,
|
getBasicGasEstimateLoadingStatus: (s) => `mockBasicGasEstimateLoadingStatus:${Object.keys(s).length}`,
|
||||||
getRenderableBasicEstimateData: (s) => `mockRenderableBasicEstimateData:${Object.keys(s).length}`,
|
getRenderableBasicEstimateData: (s) => `mockRenderableBasicEstimateData:${Object.keys(s).length}`,
|
||||||
getDefaultActiveButtonIndex: (a, b) => a + b,
|
getDefaultActiveButtonIndex: (a, b) => a + b,
|
||||||
getCurrentEthBalance: (state) => state.metamask.balance || '0x0',
|
getCurrentEthBalance: (state) => state.metamask.balance || '0x0',
|
||||||
getSelectedToken: () => null,
|
getSelectedToken: () => null,
|
||||||
|
getTokenBalance: (state) => state.metamask.send.tokenBalance || '0x0',
|
||||||
},
|
},
|
||||||
'../../../../store/actions': actionSpies,
|
'../../../../store/actions': actionSpies,
|
||||||
'../../../../ducks/gas/gas.duck': gasActionSpies,
|
'../../../../ducks/gas/gas.duck': gasActionSpies,
|
||||||
'../../../../ducks/confirm-transaction/confirm-transaction.duck': confirmTransactionActionSpies,
|
'../../../../ducks/confirm-transaction/confirm-transaction.duck': confirmTransactionActionSpies,
|
||||||
'../../../../ducks/send/send.duck': sendActionSpies,
|
'../../../../ducks/send/send.duck': sendActionSpies,
|
||||||
'../../../../selectors/send': {
|
|
||||||
getTokenBalance: (state) => state.metamask.send.tokenBalance || '0x0',
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('gas-modal-page-container container', function () {
|
describe('gas-modal-page-container container', function () {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { showModal, setAccountLabel } from '../../../../store/actions'
|
import { showModal, setAccountLabel } from '../../../../store/actions'
|
||||||
import { getSelectedIdentity, getRpcPrefsForCurrentProvider } from '../../../../selectors'
|
import {
|
||||||
|
getSelectedIdentity,
|
||||||
|
getRpcPrefsForCurrentProvider,
|
||||||
|
} from '../../../../selectors'
|
||||||
import AccountDetailsModal from './account-details-modal.component'
|
import AccountDetailsModal from './account-details-modal.component'
|
||||||
|
|
||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import CurrencyInput from './currency-input.component'
|
import CurrencyInput from './currency-input.component'
|
||||||
import { ETH } from '../../../helpers/constants/common'
|
import { ETH } from '../../../helpers/constants/common'
|
||||||
import { getSendMaxModeState } from '../../../selectors/send'
|
import {
|
||||||
import { getIsMainnet, preferencesSelector } from '../../../selectors'
|
getSendMaxModeState,
|
||||||
|
getIsMainnet,
|
||||||
|
preferencesSelector,
|
||||||
|
} from '../../../selectors'
|
||||||
|
|
||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
const { metamask: { nativeCurrency, currentCurrency, conversionRate } } = state
|
const { metamask: { nativeCurrency, currentCurrency, conversionRate } } = state
|
||||||
|
@ -3,7 +3,10 @@ import { captureException } from '@sentry/browser'
|
|||||||
|
|
||||||
import actionConstants from '../../store/actionConstants'
|
import actionConstants from '../../store/actionConstants'
|
||||||
import { addPermittedAccount } from '../../store/actions'
|
import { addPermittedAccount } from '../../store/actions'
|
||||||
import { getOriginOfCurrentTab, getSelectedAddress } from '../../selectors'
|
import {
|
||||||
|
getOriginOfCurrentTab,
|
||||||
|
getSelectedAddress,
|
||||||
|
} from '../../selectors'
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ import {
|
|||||||
getAccountType,
|
getAccountType,
|
||||||
getNumberOfAccounts,
|
getNumberOfAccounts,
|
||||||
getNumberOfTokens,
|
getNumberOfTokens,
|
||||||
|
|
||||||
txDataSelector,
|
txDataSelector,
|
||||||
} from '../../../selectors'
|
} from '../../../selectors'
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import {
|
|||||||
getAccountsWithLabels,
|
getAccountsWithLabels,
|
||||||
getLastConnectedInfo,
|
getLastConnectedInfo,
|
||||||
getTargetDomainMetadata,
|
getTargetDomainMetadata,
|
||||||
|
|
||||||
getPermissionDomains,
|
getPermissionDomains,
|
||||||
} from '../../selectors'
|
} from '../../selectors'
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import {
|
import {
|
||||||
getNativeCurrency,
|
getNativeCurrency,
|
||||||
} from '../../../selectors/send'
|
|
||||||
import {
|
|
||||||
getIsMainnet,
|
getIsMainnet,
|
||||||
isBalanceCached,
|
isBalanceCached,
|
||||||
preferencesSelector,
|
preferencesSelector,
|
||||||
|
@ -10,12 +10,10 @@ proxyquire('../account-list-item.container.js', {
|
|||||||
return () => ({})
|
return () => ({})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'../../../selectors/send': {
|
'../../../selectors': {
|
||||||
getConversionRate: () => `mockConversionRate`,
|
getConversionRate: () => `mockConversionRate`,
|
||||||
getCurrentCurrency: () => `mockCurrentCurrency`,
|
getCurrentCurrency: () => `mockCurrentCurrency`,
|
||||||
getNativeCurrency: () => `mockNativeCurrency`,
|
getNativeCurrency: () => `mockNativeCurrency`,
|
||||||
},
|
|
||||||
'../../../selectors/': {
|
|
||||||
isBalanceCached: () => `mockBalanceIsCached`,
|
isBalanceCached: () => `mockBalanceIsCached`,
|
||||||
preferencesSelector: ({ showFiatInTestnets }) => ({
|
preferencesSelector: ({ showFiatInTestnets }) => ({
|
||||||
showFiatInTestnets,
|
showFiatInTestnets,
|
||||||
|
@ -2,12 +2,11 @@ import { connect } from 'react-redux'
|
|||||||
import {
|
import {
|
||||||
getSendEnsResolution,
|
getSendEnsResolution,
|
||||||
getSendEnsResolutionError,
|
getSendEnsResolutionError,
|
||||||
} from '../../../../selectors/send'
|
|
||||||
import {
|
|
||||||
accountsWithSendEtherInfoSelector,
|
accountsWithSendEtherInfoSelector,
|
||||||
getAddressBook,
|
getAddressBook,
|
||||||
getAddressBookEntry,
|
getAddressBookEntry,
|
||||||
} from '../../../../selectors'
|
} from '../../../../selectors'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
updateSendTo,
|
updateSendTo,
|
||||||
} from '../../../../store/actions'
|
} from '../../../../store/actions'
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
|
import { connect } from 'react-redux'
|
||||||
import EnsInput from './ens-input.component'
|
import EnsInput from './ens-input.component'
|
||||||
import {
|
import {
|
||||||
getCurrentNetwork,
|
getCurrentNetwork,
|
||||||
getSendTo,
|
getSendTo,
|
||||||
getSendToNickname,
|
getSendToNickname,
|
||||||
} from '../../../../selectors/send'
|
|
||||||
import {
|
|
||||||
getAddressBookEntry,
|
getAddressBookEntry,
|
||||||
} from '../../../../selectors'
|
} from '../../../../selectors'
|
||||||
import { connect } from 'react-redux'
|
|
||||||
|
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
(state) => {
|
(state) => {
|
||||||
|
@ -17,11 +17,9 @@ proxyquire('../add-recipient.container.js', {
|
|||||||
return () => ({})
|
return () => ({})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'../../../../selectors/send': {
|
'../../../../selectors': {
|
||||||
getSendEnsResolution: (s) => `mockSendEnsResolution:${s}`,
|
getSendEnsResolution: (s) => `mockSendEnsResolution:${s}`,
|
||||||
getSendEnsResolutionError: (s) => `mockSendEnsResolutionError:${s}`,
|
getSendEnsResolutionError: (s) => `mockSendEnsResolutionError:${s}`,
|
||||||
},
|
|
||||||
'../../../../selectors/': {
|
|
||||||
getAddressBook: (s) => [{ name: `mockAddressBook:${s}` }],
|
getAddressBook: (s) => [{ name: `mockAddressBook:${s}` }],
|
||||||
getAddressBookEntry: (s) => `mockAddressBookEntry:${s}`,
|
getAddressBookEntry: (s) => `mockAddressBookEntry:${s}`,
|
||||||
accountsWithSendEtherInfoSelector: (s) => `mockAccountsWithSendEtherInfoSelector:${s}`,
|
accountsWithSendEtherInfoSelector: (s) => `mockAccountsWithSendEtherInfoSelector:${s}`,
|
||||||
|
@ -5,8 +5,8 @@ import {
|
|||||||
getSendFromBalance,
|
getSendFromBalance,
|
||||||
getTokenBalance,
|
getTokenBalance,
|
||||||
getSendMaxModeState,
|
getSendMaxModeState,
|
||||||
} from '../../../../../selectors/send'
|
getBasicGasEstimateLoadingStatus,
|
||||||
import { getBasicGasEstimateLoadingStatus } from '../../../../../selectors'
|
} from '../../../../../selectors'
|
||||||
import { calcMaxAmount } from './amount-max-button.utils.js'
|
import { calcMaxAmount } from './amount-max-button.utils.js'
|
||||||
import {
|
import {
|
||||||
updateSendAmount,
|
updateSendAmount,
|
||||||
|
@ -21,15 +21,15 @@ proxyquire('../amount-max-button.container.js', {
|
|||||||
return () => ({})
|
return () => ({})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'../../../../../selectors/send': {
|
'../../../../../selectors': {
|
||||||
getGasTotal: (s) => `mockGasTotal:${s}`,
|
getGasTotal: (s) => `mockGasTotal:${s}`,
|
||||||
getSelectedToken: (s) => `mockSelectedToken:${s}`,
|
getSelectedToken: (s) => `mockSelectedToken:${s}`,
|
||||||
getSendFromBalance: (s) => `mockBalance:${s}`,
|
getSendFromBalance: (s) => `mockBalance:${s}`,
|
||||||
getTokenBalance: (s) => `mockTokenBalance:${s}`,
|
getTokenBalance: (s) => `mockTokenBalance:${s}`,
|
||||||
getSendMaxModeState: (s) => `mockMaxModeOn:${s}`,
|
getSendMaxModeState: (s) => `mockMaxModeOn:${s}`,
|
||||||
|
getBasicGasEstimateLoadingStatus: (s) => `mockButtonDataLoading:${s}`,
|
||||||
},
|
},
|
||||||
'./amount-max-button.utils.js': { calcMaxAmount: (mockObj) => mockObj.val + 1 },
|
'./amount-max-button.utils.js': { calcMaxAmount: (mockObj) => mockObj.val + 1 },
|
||||||
'../../../../../selectors/': { getBasicGasEstimateLoadingStatus: (s) => `mockButtonDataLoading:${s}` },
|
|
||||||
'../../../../../store/actions': actionSpies,
|
'../../../../../store/actions': actionSpies,
|
||||||
'../../../../../ducks/send/send.duck': duckActionSpies,
|
'../../../../../ducks/send/send.duck': duckActionSpies,
|
||||||
})
|
})
|
||||||
|
@ -9,7 +9,7 @@ import {
|
|||||||
getTokenBalance,
|
getTokenBalance,
|
||||||
getSendMaxModeState,
|
getSendMaxModeState,
|
||||||
sendAmountIsInError,
|
sendAmountIsInError,
|
||||||
} from '../../../../selectors/send'
|
} from '../../../../selectors'
|
||||||
import { getAmountErrorObject, getGasFeeErrorObject } from '../../send.utils'
|
import { getAmountErrorObject, getGasFeeErrorObject } from '../../send.utils'
|
||||||
import {
|
import {
|
||||||
setMaxModeTo,
|
setMaxModeTo,
|
||||||
|
@ -19,7 +19,7 @@ proxyquire('../send-amount-row.container.js', {
|
|||||||
return () => ({})
|
return () => ({})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'../../../../selectors/send': { sendAmountIsInError: (s) => `mockInError:${s}` },
|
'../../../../selectors': { sendAmountIsInError: (s) => `mockInError:${s}` },
|
||||||
'../../send.utils': {
|
'../../send.utils': {
|
||||||
getAmountErrorObject: (mockDataObject) => ({ ...mockDataObject, mockChange: true }),
|
getAmountErrorObject: (mockDataObject) => ({ ...mockDataObject, mockChange: true }),
|
||||||
getGasFeeErrorObject: (mockDataObject) => ({ ...mockDataObject, mockGasFeeErrorChange: true }),
|
getGasFeeErrorObject: (mockDataObject) => ({ ...mockDataObject, mockGasFeeErrorChange: true }),
|
||||||
|
@ -2,11 +2,10 @@ import { connect } from 'react-redux'
|
|||||||
import SendContent from './send-content.component'
|
import SendContent from './send-content.component'
|
||||||
import {
|
import {
|
||||||
getSendTo,
|
getSendTo,
|
||||||
} from '../../../selectors/send'
|
|
||||||
import {
|
|
||||||
accountsWithSendEtherInfoSelector,
|
accountsWithSendEtherInfoSelector,
|
||||||
getAddressBookEntry,
|
getAddressBookEntry,
|
||||||
} from '../../../selectors'
|
} from '../../../selectors'
|
||||||
|
|
||||||
import * as actions from '../../../store/actions'
|
import * as actions from '../../../store/actions'
|
||||||
|
|
||||||
function mapStateToProps (state) {
|
function mapStateToProps (state) {
|
||||||
|
@ -11,8 +11,6 @@ import {
|
|||||||
getGasLoadingError,
|
getGasLoadingError,
|
||||||
gasFeeIsInError,
|
gasFeeIsInError,
|
||||||
getGasButtonGroupShown,
|
getGasButtonGroupShown,
|
||||||
} from '../../../../selectors/send'
|
|
||||||
import {
|
|
||||||
getAdvancedInlineGasShown,
|
getAdvancedInlineGasShown,
|
||||||
getCurrentEthBalance,
|
getCurrentEthBalance,
|
||||||
getSelectedToken,
|
getSelectedToken,
|
||||||
|
@ -30,7 +30,7 @@ proxyquire('../send-gas-row.container.js', {
|
|||||||
return () => ({})
|
return () => ({})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'../../../../selectors/send': {
|
'../../../../selectors': {
|
||||||
getSendMaxModeState: (s) => `mockMaxModeOn:${s}`,
|
getSendMaxModeState: (s) => `mockMaxModeOn:${s}`,
|
||||||
},
|
},
|
||||||
'../../send.utils.js': {
|
'../../send.utils.js': {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { getSendErrors } from '../../../../../selectors/send'
|
import { getSendErrors } from '../../../../../selectors'
|
||||||
import SendRowErrorMessage from './send-row-error-message.component'
|
import SendRowErrorMessage from './send-row-error-message.component'
|
||||||
|
|
||||||
export default connect(mapStateToProps)(SendRowErrorMessage)
|
export default connect(mapStateToProps)(SendRowErrorMessage)
|
||||||
|
@ -10,7 +10,7 @@ proxyquire('../send-row-error-message.container.js', {
|
|||||||
return () => ({})
|
return () => ({})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'../../../../../selectors/send': { getSendErrors: (s) => `mockErrors:${s}` },
|
'../../../../../selectors': { getSendErrors: (s) => `mockErrors:${s}` },
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('send-row-error-message container', function () {
|
describe('send-row-error-message container', function () {
|
||||||
|
@ -7,7 +7,6 @@ import {
|
|||||||
signTx,
|
signTx,
|
||||||
updateTransaction,
|
updateTransaction,
|
||||||
} from '../../../store/actions'
|
} from '../../../store/actions'
|
||||||
import SendFooter from './send-footer.component'
|
|
||||||
import {
|
import {
|
||||||
getGasLimit,
|
getGasLimit,
|
||||||
getGasPrice,
|
getGasPrice,
|
||||||
@ -23,12 +22,11 @@ import {
|
|||||||
getUnapprovedTxs,
|
getUnapprovedTxs,
|
||||||
getSendErrors,
|
getSendErrors,
|
||||||
isSendFormInError,
|
isSendFormInError,
|
||||||
} from '../../../selectors/send'
|
|
||||||
import {
|
|
||||||
getGasIsLoading,
|
getGasIsLoading,
|
||||||
getRenderableEstimateDataForSmallButtonsFromGWEI,
|
getRenderableEstimateDataForSmallButtonsFromGWEI,
|
||||||
getDefaultActiveButtonIndex,
|
getDefaultActiveButtonIndex,
|
||||||
} from '../../../selectors'
|
} from '../../../selectors'
|
||||||
|
import SendFooter from './send-footer.component'
|
||||||
import {
|
import {
|
||||||
addressIsNew,
|
addressIsNew,
|
||||||
constructTxParams,
|
constructTxParams,
|
||||||
|
@ -27,7 +27,7 @@ proxyquire('../send-footer.container.js', {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
'../../../store/actions': actionSpies,
|
'../../../store/actions': actionSpies,
|
||||||
'../../../selectors/send': {
|
'../../../selectors': {
|
||||||
getGasLimit: (s) => `mockGasLimit:${s}`,
|
getGasLimit: (s) => `mockGasLimit:${s}`,
|
||||||
getGasPrice: (s) => `mockGasPrice:${s}`,
|
getGasPrice: (s) => `mockGasPrice:${s}`,
|
||||||
getGasTotal: (s) => `mockGasTotal:${s}`,
|
getGasTotal: (s) => `mockGasTotal:${s}`,
|
||||||
@ -43,12 +43,10 @@ proxyquire('../send-footer.container.js', {
|
|||||||
getUnapprovedTxs: (s) => `mockUnapprovedTxs:${s}`,
|
getUnapprovedTxs: (s) => `mockUnapprovedTxs:${s}`,
|
||||||
getSendErrors: (s) => `mockSendErrors:${s}`,
|
getSendErrors: (s) => `mockSendErrors:${s}`,
|
||||||
isSendFormInError: (s) => `mockInError:${s}`,
|
isSendFormInError: (s) => `mockInError:${s}`,
|
||||||
},
|
|
||||||
'./send-footer.utils': utilsStubs,
|
|
||||||
'../../../selectors/': {
|
|
||||||
getRenderableEstimateDataForSmallButtonsFromGWEI: (s) => ([{ gasEstimateType: `mockGasEstimateType:${s}` }]),
|
getRenderableEstimateDataForSmallButtonsFromGWEI: (s) => ([{ gasEstimateType: `mockGasEstimateType:${s}` }]),
|
||||||
getDefaultActiveButtonIndex: () => 0,
|
getDefaultActiveButtonIndex: () => 0,
|
||||||
},
|
},
|
||||||
|
'./send-footer.utils': utilsStubs,
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('send-footer container', function () {
|
describe('send-footer container', function () {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { clearSend } from '../../../store/actions'
|
import { clearSend } from '../../../store/actions'
|
||||||
import SendHeader from './send-header.component'
|
import SendHeader from './send-header.component'
|
||||||
import { getTitleKey } from '../../../selectors/send'
|
import { getTitleKey } from '../../../selectors'
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(SendHeader)
|
export default connect(mapStateToProps, mapDispatchToProps)(SendHeader)
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ proxyquire('../send-header.container.js', {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
'../../../store/actions': actionSpies,
|
'../../../store/actions': actionSpies,
|
||||||
'../../../selectors/send': {
|
'../../../selectors': {
|
||||||
getTitleKey: (s) => `mockTitleKey:${s}`,
|
getTitleKey: (s) => `mockTitleKey:${s}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -23,11 +23,10 @@ import {
|
|||||||
getTokenBalance,
|
getTokenBalance,
|
||||||
getQrCodeData,
|
getQrCodeData,
|
||||||
getTokens,
|
getTokens,
|
||||||
} from '../../selectors/send'
|
|
||||||
import {
|
|
||||||
getSelectedAddress,
|
getSelectedAddress,
|
||||||
getAddressBook,
|
getAddressBook,
|
||||||
} from '../../selectors'
|
} from '../../selectors'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
updateSendTo,
|
updateSendTo,
|
||||||
updateSendTokenBalance,
|
updateSendTokenBalance,
|
||||||
|
@ -5,7 +5,7 @@ import { withRouter } from 'react-router-dom'
|
|||||||
import { addToAddressBook, showQrScanner, qrCodeDetected } from '../../../../store/actions'
|
import { addToAddressBook, showQrScanner, qrCodeDetected } from '../../../../store/actions'
|
||||||
import {
|
import {
|
||||||
getQrCodeData,
|
getQrCodeData,
|
||||||
} from '../../../../selectors/send'
|
} from '../../../../selectors'
|
||||||
|
|
||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
return {
|
return {
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
sumHexes,
|
sumHexes,
|
||||||
} from '../helpers/utils/transactions.util'
|
} from '../helpers/utils/transactions.util'
|
||||||
|
import { getNativeCurrency } from '.'
|
||||||
|
|
||||||
const unapprovedTxsSelector = (state) => state.metamask.unapprovedTxs
|
const unapprovedTxsSelector = (state) => state.metamask.unapprovedTxs
|
||||||
const unapprovedMsgsSelector = (state) => state.metamask.unapprovedMsgs
|
const unapprovedMsgsSelector = (state) => state.metamask.unapprovedMsgs
|
||||||
@ -123,7 +124,6 @@ export const unconfirmedTransactionsCountSelector = createSelector(
|
|||||||
|
|
||||||
export const currentCurrencySelector = (state) => state.metamask.currentCurrency
|
export const currentCurrencySelector = (state) => state.metamask.currentCurrency
|
||||||
export const conversionRateSelector = (state) => state.metamask.conversionRate
|
export const conversionRateSelector = (state) => state.metamask.conversionRate
|
||||||
export const getNativeCurrency = (state) => state.metamask.nativeCurrency
|
|
||||||
|
|
||||||
export const txDataSelector = (state) => state.confirmTransaction.txData
|
export const txDataSelector = (state) => state.confirmTransaction.txData
|
||||||
const tokenDataSelector = (state) => state.confirmTransaction.tokenData
|
const tokenDataSelector = (state) => state.confirmTransaction.tokenData
|
||||||
|
@ -3,5 +3,6 @@ export * from './custom-gas'
|
|||||||
export * from './first-time-flow'
|
export * from './first-time-flow'
|
||||||
export * from './permissions'
|
export * from './permissions'
|
||||||
export * from './selectors'
|
export * from './selectors'
|
||||||
|
export * from './send'
|
||||||
export * from './tokens'
|
export * from './tokens'
|
||||||
export * from './transactions'
|
export * from './transactions'
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
import { NETWORK_TYPES } from '../helpers/constants/common'
|
import { NETWORK_TYPES } from '../helpers/constants/common'
|
||||||
import { stripHexPrefix, addHexPrefix } from 'ethereumjs-util'
|
import { stripHexPrefix, addHexPrefix } from 'ethereumjs-util'
|
||||||
import { createSelector } from 'reselect'
|
import { createSelector } from 'reselect'
|
||||||
|
|
||||||
import abi from 'human-standard-token-abi'
|
|
||||||
import {
|
import {
|
||||||
shortenAddress,
|
shortenAddress,
|
||||||
checksumAddress,
|
checksumAddress,
|
||||||
getOriginFromUrl,
|
getOriginFromUrl,
|
||||||
getAccountByAddress,
|
getAccountByAddress,
|
||||||
} from '../helpers/utils/util'
|
} from '../helpers/utils/util'
|
||||||
|
import {
|
||||||
|
getSelectedToken,
|
||||||
|
} from '.'
|
||||||
|
|
||||||
export function getNetworkIdentifier (state) {
|
export function getNetworkIdentifier (state) {
|
||||||
const { metamask: { provider: { type, nickname, rpcTarget } } } = state
|
const { metamask: { provider: { type, nickname, rpcTarget } } } = state
|
||||||
@ -156,15 +157,6 @@ export function getTargetAccount (state, targetAddress) {
|
|||||||
return accounts[targetAddress]
|
return accounts[targetAddress]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSelectedToken (state) {
|
|
||||||
const tokens = state.metamask.tokens || []
|
|
||||||
const selectedTokenAddress = state.metamask.selectedTokenAddress
|
|
||||||
const selectedToken = tokens.filter(({ address }) => address === selectedTokenAddress)[0]
|
|
||||||
const sendToken = state.metamask.send && state.metamask.send.token
|
|
||||||
|
|
||||||
return selectedToken || sendToken || null
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getSelectedTokenExchangeRate (state) {
|
export function getSelectedTokenExchangeRate (state) {
|
||||||
const contractExchangeRates = state.metamask.contractExchangeRates
|
const contractExchangeRates = state.metamask.contractExchangeRates
|
||||||
const selectedToken = getSelectedToken(state) || {}
|
const selectedToken = getSelectedToken(state) || {}
|
||||||
@ -243,21 +235,10 @@ export function getGasIsLoading (state) {
|
|||||||
return state.appState.gasIsLoading
|
return state.appState.gasIsLoading
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSendAmount (state) {
|
|
||||||
return state.metamask.send.amount
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getCurrentCurrency (state) {
|
export function getCurrentCurrency (state) {
|
||||||
return state.metamask.currentCurrency
|
return state.metamask.currentCurrency
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSelectedTokenContract (state) {
|
|
||||||
const selectedToken = getSelectedToken(state)
|
|
||||||
return selectedToken
|
|
||||||
? global.eth.contract(abi).at(selectedToken.address)
|
|
||||||
: null
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getTotalUnapprovedCount (state) {
|
export function getTotalUnapprovedCount (state) {
|
||||||
const {
|
const {
|
||||||
unapprovedMsgCount = 0,
|
unapprovedMsgCount = 0,
|
||||||
|
@ -4,7 +4,6 @@ import {
|
|||||||
getAddressBook,
|
getAddressBook,
|
||||||
getSelectedAccount,
|
getSelectedAccount,
|
||||||
getTargetAccount,
|
getTargetAccount,
|
||||||
getSelectedAddress,
|
|
||||||
getAveragePriceEstimateInHexWEI,
|
getAveragePriceEstimateInHexWEI,
|
||||||
} from '.'
|
} from '.'
|
||||||
import { estimateGasPriceFromRecentBlocks, calcGasTotal } from '../pages/send/send.utils'
|
import { estimateGasPriceFromRecentBlocks, calcGasTotal } from '../pages/send/send.utils'
|
||||||
@ -17,10 +16,6 @@ export function getConversionRate (state) {
|
|||||||
return state.metamask.conversionRate
|
return state.metamask.conversionRate
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCurrentCurrency (state) {
|
|
||||||
return state.metamask.currentCurrency
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getNativeCurrency (state) {
|
export function getNativeCurrency (state) {
|
||||||
return state.metamask.nativeCurrency
|
return state.metamask.nativeCurrency
|
||||||
}
|
}
|
||||||
@ -54,25 +49,17 @@ export function getRecentBlocks (state) {
|
|||||||
return state.metamask.recentBlocks
|
return state.metamask.recentBlocks
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSelectedIdentity (state) {
|
|
||||||
const selectedAddress = getSelectedAddress(state)
|
|
||||||
const identities = state.metamask.identities
|
|
||||||
|
|
||||||
return identities[selectedAddress]
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getSelectedToken (state) {
|
export function getSelectedToken (state) {
|
||||||
const tokens = state.metamask.tokens || []
|
const tokens = state.metamask.tokens || []
|
||||||
const selectedTokenAddress = state.metamask.selectedTokenAddress
|
const selectedTokenAddress = state.metamask.selectedTokenAddress
|
||||||
const selectedToken = tokens.filter(({ address }) => address === selectedTokenAddress)[0]
|
const selectedToken = tokens.filter(({ address }) => address === selectedTokenAddress)[0]
|
||||||
const sendToken = state.metamask.send.token
|
const sendToken = state.metamask?.send.token
|
||||||
|
|
||||||
return selectedToken || sendToken || null
|
return selectedToken || sendToken || null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSelectedTokenContract (state) {
|
export function getSelectedTokenContract (state) {
|
||||||
const selectedToken = getSelectedToken(state)
|
const selectedToken = getSelectedToken(state)
|
||||||
|
|
||||||
return selectedToken
|
return selectedToken
|
||||||
? global.eth.contract(abi).at(selectedToken.address)
|
? global.eth.contract(abi).at(selectedToken.address)
|
||||||
: null
|
: null
|
||||||
|
@ -7,7 +7,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
getBlockGasLimit,
|
getBlockGasLimit,
|
||||||
getConversionRate,
|
getConversionRate,
|
||||||
getCurrentCurrency,
|
|
||||||
getCurrentNetwork,
|
getCurrentNetwork,
|
||||||
getNativeCurrency,
|
getNativeCurrency,
|
||||||
getGasLimit,
|
getGasLimit,
|
||||||
@ -15,7 +14,6 @@ import {
|
|||||||
getGasTotal,
|
getGasTotal,
|
||||||
getPrimaryCurrency,
|
getPrimaryCurrency,
|
||||||
getRecentBlocks,
|
getRecentBlocks,
|
||||||
getSelectedIdentity,
|
|
||||||
getSelectedToken,
|
getSelectedToken,
|
||||||
getSelectedTokenContract,
|
getSelectedTokenContract,
|
||||||
getSendAmount,
|
getSendAmount,
|
||||||
@ -125,15 +123,6 @@ describe('send selectors', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getCurrentCurrency()', function () {
|
|
||||||
it('should return the currently selected currency', function () {
|
|
||||||
assert.equal(
|
|
||||||
getCurrentCurrency(mockState),
|
|
||||||
'USD'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('getNativeCurrency()', function () {
|
describe('getNativeCurrency()', function () {
|
||||||
it('should return the ticker symbol of the selected network', function () {
|
it('should return the ticker symbol of the selected network', function () {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
@ -197,18 +186,6 @@ describe('send selectors', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getSelectedIdentity()', function () {
|
|
||||||
it('should return the identity object of the currently selected address', function () {
|
|
||||||
assert.deepEqual(
|
|
||||||
getSelectedIdentity(mockState),
|
|
||||||
{
|
|
||||||
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
|
||||||
name: 'Send Account 4',
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('getSelectedToken()', function () {
|
describe('getSelectedToken()', function () {
|
||||||
it('should return the currently selected token if selected', function () {
|
it('should return the currently selected token if selected', function () {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
|
Loading…
Reference in New Issue
Block a user