mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Hide gas price chart and prevent api call when not on ethereum networks. (#6300)
Add missing translations in gas customization modal
This commit is contained in:
parent
31175625b4
commit
468bc96bdf
@ -11,6 +11,9 @@
|
|||||||
"exposeDescription": {
|
"exposeDescription": {
|
||||||
"message": "Expose accounts to the current website. Useful for legacy dapps."
|
"message": "Expose accounts to the current website. Useful for legacy dapps."
|
||||||
},
|
},
|
||||||
|
"chartOnlyAvailableEth": {
|
||||||
|
"message": "Chart only available on Ethereum networks."
|
||||||
|
},
|
||||||
"confirmExpose": {
|
"confirmExpose": {
|
||||||
"message": "Are you sure you want to expose your accounts to the current website?"
|
"message": "Are you sure you want to expose your accounts to the current website?"
|
||||||
},
|
},
|
||||||
|
@ -23,6 +23,7 @@ export default class AdvancedTabContent extends Component {
|
|||||||
insufficientBalance: PropTypes.bool,
|
insufficientBalance: PropTypes.bool,
|
||||||
customPriceIsSafe: PropTypes.bool,
|
customPriceIsSafe: PropTypes.bool,
|
||||||
isSpeedUp: PropTypes.bool,
|
isSpeedUp: PropTypes.bool,
|
||||||
|
isEthereumNetwork: PropTypes.bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
@ -188,6 +189,7 @@ export default class AdvancedTabContent extends Component {
|
|||||||
customPriceIsSafe,
|
customPriceIsSafe,
|
||||||
isSpeedUp,
|
isSpeedUp,
|
||||||
transactionFee,
|
transactionFee,
|
||||||
|
isEthereumNetwork,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -203,6 +205,8 @@ export default class AdvancedTabContent extends Component {
|
|||||||
customPriceIsSafe,
|
customPriceIsSafe,
|
||||||
isSpeedUp,
|
isSpeedUp,
|
||||||
}) }
|
}) }
|
||||||
|
{ isEthereumNetwork
|
||||||
|
? <div>
|
||||||
<div className="advanced-tab__fee-chart__title">{ t('liveGasPricePredictions') }</div>
|
<div className="advanced-tab__fee-chart__title">{ t('liveGasPricePredictions') }</div>
|
||||||
{!gasEstimatesLoading
|
{!gasEstimatesLoading
|
||||||
? <GasPriceChart {...gasChartProps} updateCustomGasPrice={updateCustomGasPrice} />
|
? <GasPriceChart {...gasChartProps} updateCustomGasPrice={updateCustomGasPrice} />
|
||||||
@ -213,6 +217,9 @@ export default class AdvancedTabContent extends Component {
|
|||||||
<span>{ t('faster') }</span>
|
<span>{ t('faster') }</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
: <div className="advanced-tab__fee-chart__title">{ t('chartOnlyAvailableEth') }</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ describe('AdvancedTabContent Component', function () {
|
|||||||
insufficientBalance={false}
|
insufficientBalance={false}
|
||||||
customPriceIsSafe={true}
|
customPriceIsSafe={true}
|
||||||
isSpeedUp={false}
|
isSpeedUp={false}
|
||||||
|
isEthereumNetwork={true}
|
||||||
/>, { context: { t: (str1, str2) => str2 ? str1 + str2 : str1 } })
|
/>, { context: { t: (str1, str2) => str2 ? str1 + str2 : str1 } })
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -59,9 +60,9 @@ describe('AdvancedTabContent Component', function () {
|
|||||||
const feeChartDiv = advancedTabChildren.at(1)
|
const feeChartDiv = advancedTabChildren.at(1)
|
||||||
|
|
||||||
assert(feeChartDiv.childAt(0).hasClass('advanced-tab__gas-edit-rows'))
|
assert(feeChartDiv.childAt(0).hasClass('advanced-tab__gas-edit-rows'))
|
||||||
assert(feeChartDiv.childAt(1).hasClass('advanced-tab__fee-chart__title'))
|
assert(feeChartDiv.childAt(1).childAt(0).hasClass('advanced-tab__fee-chart__title'))
|
||||||
assert(feeChartDiv.childAt(2).is(GasPriceChart))
|
assert(feeChartDiv.childAt(1).childAt(1).is(GasPriceChart))
|
||||||
assert(feeChartDiv.childAt(3).hasClass('advanced-tab__fee-chart__speed-buttons'))
|
assert(feeChartDiv.childAt(1).childAt(2).hasClass('advanced-tab__fee-chart__speed-buttons'))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should render a loading component instead of the chart if gasEstimatesLoading is true', () => {
|
it('should render a loading component instead of the chart if gasEstimatesLoading is true', () => {
|
||||||
@ -75,9 +76,9 @@ describe('AdvancedTabContent Component', function () {
|
|||||||
const feeChartDiv = advancedTabChildren.at(1)
|
const feeChartDiv = advancedTabChildren.at(1)
|
||||||
|
|
||||||
assert(feeChartDiv.childAt(0).hasClass('advanced-tab__gas-edit-rows'))
|
assert(feeChartDiv.childAt(0).hasClass('advanced-tab__gas-edit-rows'))
|
||||||
assert(feeChartDiv.childAt(1).hasClass('advanced-tab__fee-chart__title'))
|
assert(feeChartDiv.childAt(1).childAt(0).hasClass('advanced-tab__fee-chart__title'))
|
||||||
assert(feeChartDiv.childAt(2).is(Loading))
|
assert(feeChartDiv.childAt(1).childAt(1).is(Loading))
|
||||||
assert(feeChartDiv.childAt(3).hasClass('advanced-tab__fee-chart__speed-buttons'))
|
assert(feeChartDiv.childAt(1).childAt(2).hasClass('advanced-tab__fee-chart__speed-buttons'))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should call renderDataSummary with the expected params', () => {
|
it('should call renderDataSummary with the expected params', () => {
|
||||||
|
@ -177,7 +177,7 @@ export default class GasModalPageContainer extends Component {
|
|||||||
onSubmit(customModalGasLimitInHex, customModalGasPriceInHex)
|
onSubmit(customModalGasLimitInHex, customModalGasPriceInHex)
|
||||||
}}
|
}}
|
||||||
submitText={this.context.t('save')}
|
submitText={this.context.t('save')}
|
||||||
headerCloseText={'Close'}
|
headerCloseText={this.context.t('close')}
|
||||||
hideCancel={true}
|
hideCancel={true}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -23,10 +23,13 @@ import {
|
|||||||
updateGasAndCalculate,
|
updateGasAndCalculate,
|
||||||
} from '../../../../ducks/confirm-transaction/confirm-transaction.duck'
|
} from '../../../../ducks/confirm-transaction/confirm-transaction.duck'
|
||||||
import {
|
import {
|
||||||
getCurrentCurrency,
|
|
||||||
conversionRateSelector as getConversionRate,
|
conversionRateSelector as getConversionRate,
|
||||||
getSelectedToken,
|
getCurrentCurrency,
|
||||||
getCurrentEthBalance,
|
getCurrentEthBalance,
|
||||||
|
getIsMainnet,
|
||||||
|
getSelectedToken,
|
||||||
|
isEthereumNetwork,
|
||||||
|
preferencesSelector,
|
||||||
} from '../../../../selectors/selectors.js'
|
} from '../../../../selectors/selectors.js'
|
||||||
import {
|
import {
|
||||||
formatTimeEstimate,
|
formatTimeEstimate,
|
||||||
@ -63,7 +66,6 @@ import {
|
|||||||
} from '../../send/send.utils'
|
} from '../../send/send.utils'
|
||||||
import { addHexPrefix } from 'ethereumjs-util'
|
import { addHexPrefix } from 'ethereumjs-util'
|
||||||
import { getAdjacentGasPrices, extrapolateY } from '../gas-price-chart/gas-price-chart.utils'
|
import { getAdjacentGasPrices, extrapolateY } from '../gas-price-chart/gas-price-chart.utils'
|
||||||
import {getIsMainnet, preferencesSelector} from '../../../../selectors/selectors'
|
|
||||||
|
|
||||||
const mapStateToProps = (state, ownProps) => {
|
const mapStateToProps = (state, ownProps) => {
|
||||||
const { transaction = {} } = ownProps
|
const { transaction = {} } = ownProps
|
||||||
@ -138,6 +140,8 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
txId: transaction.id,
|
txId: transaction.id,
|
||||||
insufficientBalance,
|
insufficientBalance,
|
||||||
gasEstimatesLoading,
|
gasEstimatesLoading,
|
||||||
|
isMainnet,
|
||||||
|
isEthereumNetwork: isEthereumNetwork(state),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ describe('gas-modal-page-container container', () => {
|
|||||||
gasChartProps: {
|
gasChartProps: {
|
||||||
'currentPrice': 4.294967295,
|
'currentPrice': 4.294967295,
|
||||||
estimatedTimes: [31, 62, 93, 124],
|
estimatedTimes: [31, 62, 93, 124],
|
||||||
estimatedTimesMax: '31',
|
estimatedTimesMax: 31,
|
||||||
gasPrices: [3, 4, 5, 6],
|
gasPrices: [3, 4, 5, 6],
|
||||||
gasPricesMax: 6,
|
gasPricesMax: 6,
|
||||||
},
|
},
|
||||||
@ -140,6 +140,8 @@ describe('gas-modal-page-container container', () => {
|
|||||||
insufficientBalance: true,
|
insufficientBalance: true,
|
||||||
isSpeedUp: false,
|
isSpeedUp: false,
|
||||||
txId: 34,
|
txId: 34,
|
||||||
|
isEthereumNetwork: false,
|
||||||
|
isMainnet: true,
|
||||||
}
|
}
|
||||||
const baseMockOwnProps = { transaction: { id: 34 } }
|
const baseMockOwnProps = { transaction: { id: 34 } }
|
||||||
const tests = [
|
const tests = [
|
||||||
@ -179,6 +181,7 @@ describe('gas-modal-page-container container', () => {
|
|||||||
...baseExpectedResult.infoRowProps,
|
...baseExpectedResult.infoRowProps,
|
||||||
newTotalFiat: '',
|
newTotalFiat: '',
|
||||||
},
|
},
|
||||||
|
isMainnet: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -196,7 +199,10 @@ describe('gas-modal-page-container container', () => {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
mockOwnProps: baseMockOwnProps,
|
mockOwnProps: baseMockOwnProps,
|
||||||
expectedResult: baseExpectedResult,
|
expectedResult: {
|
||||||
|
...baseExpectedResult,
|
||||||
|
isMainnet: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mockState: Object.assign({}, baseMockState, {
|
mockState: Object.assign({}, baseMockState, {
|
||||||
|
@ -364,7 +364,9 @@ describe('Gas Duck', () => {
|
|||||||
{},
|
{},
|
||||||
initState,
|
initState,
|
||||||
{ basicPriceAndTimeEstimatesLastRetrieved: 1000000 }
|
{ basicPriceAndTimeEstimatesLastRetrieved: 1000000 }
|
||||||
) }))
|
),
|
||||||
|
metamask: { provider: { type: 'ropsten' } },
|
||||||
|
}))
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
mockDistpatch.getCall(0).args,
|
mockDistpatch.getCall(0).args,
|
||||||
[{ type: BASIC_GAS_ESTIMATE_LOADING_STARTED} ]
|
[{ type: BASIC_GAS_ESTIMATE_LOADING_STARTED} ]
|
||||||
@ -428,7 +430,9 @@ describe('Gas Duck', () => {
|
|||||||
{},
|
{},
|
||||||
initState,
|
initState,
|
||||||
{ priceAndTimeEstimatesLastRetrieved: 1000000 }
|
{ priceAndTimeEstimatesLastRetrieved: 1000000 }
|
||||||
) }))
|
),
|
||||||
|
metamask: { provider: { type: 'ropsten' } },
|
||||||
|
}))
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
mockDistpatch.getCall(0).args,
|
mockDistpatch.getCall(0).args,
|
||||||
[{ type: GAS_ESTIMATE_LOADING_STARTED} ]
|
[{ type: GAS_ESTIMATE_LOADING_STARTED} ]
|
||||||
@ -479,7 +483,9 @@ describe('Gas Duck', () => {
|
|||||||
gasprice: 50,
|
gasprice: 50,
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
) }))
|
),
|
||||||
|
metamask: { provider: { type: 'ropsten' } },
|
||||||
|
}))
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
mockDistpatch.getCall(0).args,
|
mockDistpatch.getCall(0).args,
|
||||||
[{ type: GAS_ESTIMATE_LOADING_STARTED} ]
|
[{ type: GAS_ESTIMATE_LOADING_STARTED} ]
|
||||||
|
@ -7,6 +7,9 @@ import {
|
|||||||
import {
|
import {
|
||||||
decGWEIToHexWEI,
|
decGWEIToHexWEI,
|
||||||
} from '../../helpers/utils/conversions.util'
|
} from '../../helpers/utils/conversions.util'
|
||||||
|
import {
|
||||||
|
isEthereumNetwork,
|
||||||
|
} from '../../selectors/selectors'
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
const BASIC_GAS_ESTIMATE_LOADING_FINISHED = 'metamask/gas/BASIC_GAS_ESTIMATE_LOADING_FINISHED'
|
const BASIC_GAS_ESTIMATE_LOADING_FINISHED = 'metamask/gas/BASIC_GAS_ESTIMATE_LOADING_FINISHED'
|
||||||
@ -356,10 +359,16 @@ function inliersByIQR (data, prop) {
|
|||||||
|
|
||||||
export function fetchGasEstimates (blockTime) {
|
export function fetchGasEstimates (blockTime) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
|
const state = getState()
|
||||||
|
|
||||||
|
if (isEthereumNetwork(state)) {
|
||||||
|
return Promise.resolve(null)
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
priceAndTimeEstimatesLastRetrieved,
|
priceAndTimeEstimatesLastRetrieved,
|
||||||
priceAndTimeEstimates,
|
priceAndTimeEstimates,
|
||||||
} = getState().gas
|
} = state.gas
|
||||||
const timeLastRetrieved = priceAndTimeEstimatesLastRetrieved || loadLocalStorageData('GAS_API_ESTIMATES_LAST_RETRIEVED') || 0
|
const timeLastRetrieved = priceAndTimeEstimatesLastRetrieved || loadLocalStorageData('GAS_API_ESTIMATES_LAST_RETRIEVED') || 0
|
||||||
|
|
||||||
dispatch(gasEstimatesLoadingStarted())
|
dispatch(gasEstimatesLoadingStarted())
|
||||||
|
@ -6,5 +6,8 @@ export const PRIMARY = 'PRIMARY'
|
|||||||
export const SECONDARY = 'SECONDARY'
|
export const SECONDARY = 'SECONDARY'
|
||||||
|
|
||||||
export const NETWORK_TYPES = {
|
export const NETWORK_TYPES = {
|
||||||
|
KOVAN: 'kovan',
|
||||||
MAINNET: 'mainnet',
|
MAINNET: 'mainnet',
|
||||||
|
RINKEBY: 'rinkeby',
|
||||||
|
ROPSTEN: 'ropsten',
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {NETWORK_TYPES} from '../helpers/constants/common'
|
import { NETWORK_TYPES } from '../helpers/constants/common'
|
||||||
import { stripHexPrefix } from 'ethereumjs-util'
|
import { stripHexPrefix } from 'ethereumjs-util'
|
||||||
|
|
||||||
const abi = require('human-standard-token-abi')
|
const abi = require('human-standard-token-abi')
|
||||||
@ -47,6 +47,7 @@ const selectors = {
|
|||||||
getAccountType,
|
getAccountType,
|
||||||
getNumberOfAccounts,
|
getNumberOfAccounts,
|
||||||
getNumberOfTokens,
|
getNumberOfTokens,
|
||||||
|
isEthereumNetwork,
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = selectors
|
module.exports = selectors
|
||||||
@ -292,6 +293,17 @@ function getIsMainnet (state) {
|
|||||||
return networkType === NETWORK_TYPES.MAINNET
|
return networkType === NETWORK_TYPES.MAINNET
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isEthereumNetwork (state) {
|
||||||
|
const networkType = getNetworkIdentifier(state)
|
||||||
|
const {
|
||||||
|
KOVAN,
|
||||||
|
MAINNET,
|
||||||
|
RINKEBY,
|
||||||
|
ROPSTEN,
|
||||||
|
} = NETWORK_TYPES
|
||||||
|
return [ KOVAN, MAINNET, RINKEBY, ROPSTEN].includes(type => type === networkType)
|
||||||
|
}
|
||||||
|
|
||||||
function preferencesSelector ({ metamask }) {
|
function preferencesSelector ({ metamask }) {
|
||||||
return metamask.preferences
|
return metamask.preferences
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user