diff options
author | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2019-08-07 05:53:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-07 05:53:50 +0800 |
commit | db08881d4527e8a037f401ef22b849e52152864f (patch) | |
tree | 6032d7a4ae67371889eece1d8490c26d5a119dd5 /ui/app/ducks | |
parent | 4139019d0f4dd83f56da400ca7e0e6d1976d1716 (diff) | |
parent | 86ad9564a064fd6158dab6a3c9e5b10614ef6e68 (diff) | |
download | tangerine-wallet-browser-7.0.0.tar.gz tangerine-wallet-browser-7.0.0.tar.zst tangerine-wallet-browser-7.0.0.zip |
Merge pull request #6969 from MetaMask/developv7.0.0
Master Version Bump
Diffstat (limited to 'ui/app/ducks')
-rw-r--r-- | ui/app/ducks/app/app.js | 33 | ||||
-rw-r--r-- | ui/app/ducks/gas/gas-duck.test.js | 261 | ||||
-rw-r--r-- | ui/app/ducks/gas/gas.duck.js | 253 | ||||
-rw-r--r-- | ui/app/ducks/index.js | 9 | ||||
-rw-r--r-- | ui/app/ducks/metamask/metamask.js | 43 |
5 files changed, 392 insertions, 207 deletions
diff --git a/ui/app/ducks/app/app.js b/ui/app/ducks/app/app.js index 04c8c7422..029c755cd 100644 --- a/ui/app/ducks/app/app.js +++ b/ui/app/ducks/app/app.js @@ -27,13 +27,6 @@ function reduceApp (state, action) { context: selectedAddress, } - // confirm seed words - var seedWords = state.metamask.seedWords - var seedConfView = { - name: 'createVaultComplete', - seedWords, - } - // default state var appState = extend({ shouldClose: false, @@ -58,7 +51,7 @@ function reduceApp (state, action) { alertMessage: null, qrCodeData: null, networkDropdownOpen: false, - currentView: seedWords ? seedConfView : defaultView, + currentView: defaultView, accountDetail: { subview: 'transactions', }, @@ -167,7 +160,7 @@ function reduceApp (state, action) { transForward: false, }) - // intialize + // intialize case actions.SHOW_CREATE_VAULT: return extend(appState, { @@ -269,7 +262,7 @@ function reduceApp (state, action) { transForward: true, }) - case actions.CREATE_NEW_VAULT_IN_PROGRESS: + case actions.CREATE_NEW_VAULT_IN_PROGRESS: return extend(appState, { currentView: { name: 'createVault', @@ -279,16 +272,6 @@ function reduceApp (state, action) { isLoading: true, }) - case actions.SHOW_NEW_VAULT_SEED: - return extend(appState, { - currentView: { - name: 'createVaultComplete', - seedWords: action.value, - }, - transForward: true, - isLoading: false, - }) - case actions.NEW_ACCOUNT_SCREEN: return extend(appState, { currentView: { @@ -327,7 +310,7 @@ function reduceApp (state, action) { transForward: true, }) - // unlock + // unlock case actions.UNLOCK_METAMASK: return extend(appState, { @@ -364,7 +347,7 @@ function reduceApp (state, action) { name: 'UnlockScreen', }, }) - // reveal seed words + // reveal seed words case actions.REVEAL_SEED_CONFIRMATION: return extend(appState, { @@ -375,7 +358,7 @@ function reduceApp (state, action) { warning: null, }) - // accounts + // accounts case actions.SET_SELECTED_ACCOUNT: return extend(appState, { @@ -428,8 +411,7 @@ function reduceApp (state, action) { case actions.SHOW_ACCOUNTS_PAGE: return extend(appState, { currentView: { - name: seedWords ? 'createVaultComplete' : 'accounts', - seedWords, + name: 'accounts', }, transForward: true, isLoading: false, @@ -774,7 +756,6 @@ function reduceApp (state, action) { loadingMethodData: false, }) - default: return appState } diff --git a/ui/app/ducks/gas/gas-duck.test.js b/ui/app/ducks/gas/gas-duck.test.js index b7e83a81c..82a91d5e7 100644 --- a/ui/app/ducks/gas/gas-duck.test.js +++ b/ui/app/ducks/gas/gas-duck.test.js @@ -2,12 +2,10 @@ import assert from 'assert' import sinon from 'sinon' import proxyquire from 'proxyquire' +const fakeLocalStorage = {} const GasDuck = proxyquire('./gas.duck.js', { - '../../../lib/local-storage-helpers': { - loadLocalStorageData: sinon.spy(), - saveLocalStorageData: sinon.spy(), - }, + '../../../lib/local-storage-helpers': fakeLocalStorage, }) const { @@ -68,24 +66,28 @@ describe('Gas Duck', () => { { expectedTime: 1.1, expectedWait: 0.6, gasprice: 19.9, somethingElse: 'foobar' }, { expectedTime: 1, expectedWait: 0.5, gasprice: 20, somethingElse: 'foobar' }, ] - const fetchStub = sinon.stub().callsFake((url) => new Promise(resolve => { + const fakeFetch = (url) => new Promise(resolve => { const dataToResolve = url.match(/ethgasAPI|gasexpress/) ? mockEthGasApiResponse : mockPredictTableResponse resolve({ json: () => new Promise(resolve => resolve(dataToResolve)), }) - })) + }) beforeEach(() => { tempFetch = global.fetch tempDateNow = global.Date.now - global.fetch = fetchStub + + fakeLocalStorage.loadLocalStorageData = sinon.stub() + fakeLocalStorage.saveLocalStorageData = sinon.spy() + global.fetch = sinon.stub().callsFake(fakeFetch) global.Date.now = () => 2000000 }) afterEach(() => { - fetchStub.resetHistory() + sinon.restore() + global.fetch = tempFetch global.Date.now = tempDateNow }) @@ -118,7 +120,6 @@ describe('Gas Duck', () => { gasEstimatesLoading: true, priceAndTimeEstimates: [], priceAndTimeEstimatesLastRetrieved: 0, - basicPriceAndTimeEstimates: [], basicPriceAndTimeEstimatesLastRetrieved: 0, basicPriceEstimatesLastRetrieved: 0, } @@ -305,8 +306,9 @@ describe('Gas Duck', () => { }) describe('fetchBasicGasEstimates', () => { - const mockDistpatch = sinon.spy() it('should call fetch with the expected params', async () => { + const mockDistpatch = sinon.spy() + await fetchBasicGasEstimates()(mockDistpatch, () => ({ gas: Object.assign( {}, initState, @@ -330,12 +332,109 @@ describe('Gas Duck', () => { }, ] ) - assert.deepEqual( mockDistpatch.getCall(1).args, [{ type: SET_BASIC_PRICE_ESTIMATES_LAST_RETRIEVED, value: 2000000 } ] ) + assert.deepEqual( + mockDistpatch.getCall(2).args, + [{ + type: SET_BASIC_GAS_ESTIMATE_DATA, + value: { + average: 20, + blockTime: 'mockBlock_time', + blockNum: 'mockBlockNum', + fast: 30, + fastest: 40, + safeLow: 10, + }, + }] + ) + assert.deepEqual( + mockDistpatch.getCall(3).args, + [{ type: BASIC_GAS_ESTIMATE_LOADING_FINISHED }] + ) + }) + + it('should fetch recently retrieved estimates from local storage', async () => { + const mockDistpatch = sinon.spy() + fakeLocalStorage.loadLocalStorageData + .withArgs('BASIC_PRICE_ESTIMATES_LAST_RETRIEVED') + .returns(2000000 - 1) // one second ago from "now" + fakeLocalStorage.loadLocalStorageData + .withArgs('BASIC_PRICE_ESTIMATES') + .returns({ + average: 25, + blockTime: 'mockBlock_time', + blockNum: 'mockBlockNum', + fast: 35, + fastest: 45, + safeLow: 15, + }) + + await fetchBasicGasEstimates()(mockDistpatch, () => ({ gas: Object.assign( + {}, + initState, + {} + ) })) + assert.deepEqual( + mockDistpatch.getCall(0).args, + [{ type: BASIC_GAS_ESTIMATE_LOADING_STARTED} ] + ) + assert.ok(global.fetch.notCalled) + assert.deepEqual( + mockDistpatch.getCall(1).args, + [{ + type: SET_BASIC_GAS_ESTIMATE_DATA, + value: { + average: 25, + blockTime: 'mockBlock_time', + blockNum: 'mockBlockNum', + fast: 35, + fastest: 45, + safeLow: 15, + }, + }] + ) + assert.deepEqual( + mockDistpatch.getCall(2).args, + [{ type: BASIC_GAS_ESTIMATE_LOADING_FINISHED }] + ) + }) + + it('should fallback to network if retrieving estimates from local storage fails', async () => { + const mockDistpatch = sinon.spy() + fakeLocalStorage.loadLocalStorageData + .withArgs('BASIC_PRICE_ESTIMATES_LAST_RETRIEVED') + .returns(2000000 - 1) // one second ago from "now" + await fetchBasicGasEstimates()(mockDistpatch, () => ({ gas: Object.assign( + {}, + initState, + {} + ) })) + assert.deepEqual( + mockDistpatch.getCall(0).args, + [{ type: BASIC_GAS_ESTIMATE_LOADING_STARTED} ] + ) + assert.deepEqual( + global.fetch.getCall(0).args, + [ + 'https://dev.blockscale.net/api/gasexpress.json', + { + 'headers': {}, + 'referrer': 'https://dev.blockscale.net/api/', + 'referrerPolicy': 'no-referrer-when-downgrade', + 'body': null, + 'method': 'GET', + 'mode': 'cors', + }, + ] + ) + assert.deepEqual( + mockDistpatch.getCall(1).args, + [{ type: SET_BASIC_PRICE_ESTIMATES_LAST_RETRIEVED, value: 2000000 } ] + ) assert.deepEqual( mockDistpatch.getCall(2).args, [{ @@ -358,14 +457,15 @@ describe('Gas Duck', () => { }) describe('fetchBasicGasAndTimeEstimates', () => { - const mockDistpatch = sinon.spy() it('should call fetch with the expected params', async () => { + const mockDistpatch = sinon.spy() + await fetchBasicGasAndTimeEstimates()(mockDistpatch, () => ({ gas: Object.assign( {}, initState, { basicPriceAndTimeEstimatesLastRetrieved: 1000000 } ), - metamask: { provider: { type: 'ropsten' } }, + metamask: { provider: { type: 'ropsten' } }, })) assert.deepEqual( mockDistpatch.getCall(0).args, @@ -415,23 +515,139 @@ describe('Gas Duck', () => { [{ type: BASIC_GAS_ESTIMATE_LOADING_FINISHED }] ) }) - }) - describe('fetchGasEstimates', () => { - const mockDistpatch = sinon.spy() + it('should fetch recently retrieved estimates from local storage', async () => { + const mockDistpatch = sinon.spy() + fakeLocalStorage.loadLocalStorageData + .withArgs('BASIC_GAS_AND_TIME_API_ESTIMATES_LAST_RETRIEVED') + .returns(2000000 - 1) // one second ago from "now" + fakeLocalStorage.loadLocalStorageData + .withArgs('BASIC_GAS_AND_TIME_API_ESTIMATES') + .returns({ + average: 5, + avgWait: 'mockAvgWait', + blockTime: 'mockBlock_time', + blockNum: 'mockBlockNum', + fast: 6, + fastest: 7, + fastestWait: 'mockFastestWait', + fastWait: 'mockFastWait', + safeLow: 1, + safeLowWait: 'mockSafeLowWait', + speed: 'mockSpeed', + }) + + await fetchBasicGasAndTimeEstimates()(mockDistpatch, () => ({ gas: Object.assign( + {}, + initState, + {} + ), + metamask: { provider: { type: 'ropsten' } }, + })) + assert.deepEqual( + mockDistpatch.getCall(0).args, + [{ type: BASIC_GAS_ESTIMATE_LOADING_STARTED} ] + ) + assert.ok(global.fetch.notCalled) + + assert.deepEqual( + mockDistpatch.getCall(1).args, + [{ + type: SET_BASIC_GAS_ESTIMATE_DATA, + value: { + average: 5, + avgWait: 'mockAvgWait', + blockTime: 'mockBlock_time', + blockNum: 'mockBlockNum', + fast: 6, + fastest: 7, + fastestWait: 'mockFastestWait', + fastWait: 'mockFastWait', + safeLow: 1, + safeLowWait: 'mockSafeLowWait', + speed: 'mockSpeed', + }, + }] + ) + assert.deepEqual( + mockDistpatch.getCall(2).args, + [{ type: BASIC_GAS_ESTIMATE_LOADING_FINISHED }] + ) + }) + + it('should fallback to network if retrieving estimates from local storage fails', async () => { + const mockDistpatch = sinon.spy() + fakeLocalStorage.loadLocalStorageData + .withArgs('BASIC_GAS_AND_TIME_API_ESTIMATES_LAST_RETRIEVED') + .returns(2000000 - 1) // one second ago from "now" + + await fetchBasicGasAndTimeEstimates()(mockDistpatch, () => ({ gas: Object.assign( + {}, + initState, + {} + ), + metamask: { provider: { type: 'ropsten' } }, + })) + assert.deepEqual( + mockDistpatch.getCall(0).args, + [{ type: BASIC_GAS_ESTIMATE_LOADING_STARTED} ] + ) + assert.deepEqual( + global.fetch.getCall(0).args, + [ + 'https://ethgasstation.info/json/ethgasAPI.json', + { + 'headers': {}, + 'referrer': 'http://ethgasstation.info/json/', + 'referrerPolicy': 'no-referrer-when-downgrade', + 'body': null, + 'method': 'GET', + 'mode': 'cors', + }, + ] + ) - beforeEach(() => { - mockDistpatch.resetHistory() + assert.deepEqual( + mockDistpatch.getCall(1).args, + [{ type: SET_BASIC_API_ESTIMATES_LAST_RETRIEVED, value: 2000000 } ] + ) + + assert.deepEqual( + mockDistpatch.getCall(2).args, + [{ + type: SET_BASIC_GAS_ESTIMATE_DATA, + value: { + average: 2, + avgWait: 'mockAvgWait', + blockTime: 'mockBlock_time', + blockNum: 'mockBlockNum', + fast: 3, + fastest: 4, + fastestWait: 'mockFastestWait', + fastWait: 'mockFastWait', + safeLow: 1, + safeLowWait: 'mockSafeLowWait', + speed: 'mockSpeed', + }, + }] + ) + assert.deepEqual( + mockDistpatch.getCall(3).args, + [{ type: BASIC_GAS_ESTIMATE_LOADING_FINISHED }] + ) }) + }) + describe('fetchGasEstimates', () => { it('should call fetch with the expected params', async () => { - global.fetch.resetHistory() + const mockDistpatch = sinon.spy() + await fetchGasEstimates(5)(mockDistpatch, () => ({ gas: Object.assign( {}, initState, { priceAndTimeEstimatesLastRetrieved: 1000000 } ), - metamask: { provider: { type: 'ropsten' } }, + metamask: { provider: { type: 'ropsten' } }, })) assert.deepEqual( mockDistpatch.getCall(0).args, @@ -471,7 +687,8 @@ describe('Gas Duck', () => { }) it('should not call fetch if the estimates were retrieved < 75000 ms ago', async () => { - global.fetch.resetHistory() + const mockDistpatch = sinon.spy() + await fetchGasEstimates(5)(mockDistpatch, () => ({ gas: Object.assign( {}, initState, @@ -484,7 +701,7 @@ describe('Gas Duck', () => { }], } ), - metamask: { provider: { type: 'ropsten' } }, + metamask: { provider: { type: 'ropsten' } }, })) assert.deepEqual( mockDistpatch.getCall(0).args, diff --git a/ui/app/ducks/gas/gas.duck.js b/ui/app/ducks/gas/gas.duck.js index 5a0a236e6..e272455fc 100644 --- a/ui/app/ducks/gas/gas.duck.js +++ b/ui/app/ducks/gas/gas.duck.js @@ -50,7 +50,6 @@ const initState = { basicEstimateIsLoading: true, gasEstimatesLoading: true, priceAndTimeEstimates: [], - basicPriceAndTimeEstimates: [], priceAndTimeEstimatesLastRetrieved: 0, basicPriceAndTimeEstimatesLastRetrieved: 0, basicPriceEstimatesLastRetrieved: 0, @@ -177,134 +176,132 @@ export function gasEstimatesLoadingFinished () { } export function fetchBasicGasEstimates () { - return (dispatch, getState) => { - const { - basicPriceEstimatesLastRetrieved, - basicPriceAndTimeEstimates, - } = getState().gas + return async (dispatch, getState) => { + const { basicPriceEstimatesLastRetrieved } = getState().gas const timeLastRetrieved = basicPriceEstimatesLastRetrieved || loadLocalStorageData('BASIC_PRICE_ESTIMATES_LAST_RETRIEVED') || 0 dispatch(basicGasEstimatesLoadingStarted()) - const promiseToFetch = Date.now() - timeLastRetrieved > 75000 - ? fetch('https://dev.blockscale.net/api/gasexpress.json', { - 'headers': {}, - 'referrer': 'https://dev.blockscale.net/api/', - 'referrerPolicy': 'no-referrer-when-downgrade', - 'body': null, - 'method': 'GET', - 'mode': 'cors'} - ) - .then(r => r.json()) - .then(({ - safeLow, - standard: average, - fast, - fastest, - block_time: blockTime, - blockNum, - }) => { - const basicEstimates = { - safeLow, - average, - fast, - fastest, - blockTime, - blockNum, - } - - const timeRetrieved = Date.now() - dispatch(setBasicPriceEstimatesLastRetrieved(timeRetrieved)) - saveLocalStorageData(timeRetrieved, 'BASIC_PRICE_ESTIMATES_LAST_RETRIEVED') - saveLocalStorageData(basicEstimates, 'BASIC_PRICE_ESTIMATES') - - return basicEstimates - }) - : Promise.resolve(basicPriceAndTimeEstimates.length - ? basicPriceAndTimeEstimates - : loadLocalStorageData('BASIC_PRICE_ESTIMATES') - ) + let basicEstimates + if (Date.now() - timeLastRetrieved > 75000) { + basicEstimates = await fetchExternalBasicGasEstimates(dispatch) + } else { + const cachedBasicEstimates = loadLocalStorageData('BASIC_PRICE_ESTIMATES') + basicEstimates = cachedBasicEstimates || await fetchExternalBasicGasEstimates(dispatch) + } - return promiseToFetch.then(basicEstimates => { - dispatch(setBasicGasEstimateData(basicEstimates)) - dispatch(basicGasEstimatesLoadingFinished()) - return basicEstimates - }) + dispatch(setBasicGasEstimateData(basicEstimates)) + dispatch(basicGasEstimatesLoadingFinished()) + + return basicEstimates } } +async function fetchExternalBasicGasEstimates (dispatch) { + const response = await fetch('https://dev.blockscale.net/api/gasexpress.json', { + 'headers': {}, + 'referrer': 'https://dev.blockscale.net/api/', + 'referrerPolicy': 'no-referrer-when-downgrade', + 'body': null, + 'method': 'GET', + 'mode': 'cors'} + ) + const { + safeLow, + standard: average, + fast, + fastest, + block_time: blockTime, + blockNum, + } = await response.json() + + const basicEstimates = { + safeLow, + average, + fast, + fastest, + blockTime, + blockNum, + } + + const timeRetrieved = Date.now() + saveLocalStorageData(basicEstimates, 'BASIC_PRICE_ESTIMATES') + saveLocalStorageData(timeRetrieved, 'BASIC_PRICE_ESTIMATES_LAST_RETRIEVED') + dispatch(setBasicPriceEstimatesLastRetrieved(timeRetrieved)) + + return basicEstimates +} + export function fetchBasicGasAndTimeEstimates () { - return (dispatch, getState) => { - const { - basicPriceAndTimeEstimatesLastRetrieved, - basicPriceAndTimeEstimates, - } = getState().gas + return async (dispatch, getState) => { + const { basicPriceAndTimeEstimatesLastRetrieved } = getState().gas const timeLastRetrieved = basicPriceAndTimeEstimatesLastRetrieved || loadLocalStorageData('BASIC_GAS_AND_TIME_API_ESTIMATES_LAST_RETRIEVED') || 0 dispatch(basicGasEstimatesLoadingStarted()) - const promiseToFetch = Date.now() - timeLastRetrieved > 75000 - ? fetch('https://ethgasstation.info/json/ethgasAPI.json', { - 'headers': {}, - 'referrer': 'http://ethgasstation.info/json/', - 'referrerPolicy': 'no-referrer-when-downgrade', - 'body': null, - 'method': 'GET', - 'mode': 'cors'} - ) - .then(r => r.json()) - .then(({ - average: averageTimes10, - avgWait, - block_time: blockTime, - blockNum, - fast: fastTimes10, - fastest: fastestTimes10, - fastestWait, - fastWait, - safeLow: safeLowTimes10, - safeLowWait, - speed, - }) => { - const [average, fast, fastest, safeLow] = [ - averageTimes10, - fastTimes10, - fastestTimes10, - safeLowTimes10, - ].map(price => (new BigNumber(price)).div(10).toNumber()) - - const basicEstimates = { - average, - avgWait, - blockTime, - blockNum, - fast, - fastest, - fastestWait, - fastWait, - safeLow, - safeLowWait, - speed, - } + let basicEstimates + if (Date.now() - timeLastRetrieved > 75000) { + basicEstimates = await fetchExternalBasicGasAndTimeEstimates(dispatch) + } else { + const cachedBasicEstimates = loadLocalStorageData('BASIC_GAS_AND_TIME_API_ESTIMATES') + basicEstimates = cachedBasicEstimates || await fetchExternalBasicGasAndTimeEstimates(dispatch) + } - const timeRetrieved = Date.now() - dispatch(setBasicApiEstimatesLastRetrieved(timeRetrieved)) - saveLocalStorageData(timeRetrieved, 'BASIC_GAS_AND_TIME_API_ESTIMATES_LAST_RETRIEVED') - saveLocalStorageData(basicEstimates, 'BASIC_GAS_AND_TIME_API_ESTIMATES') + dispatch(setBasicGasEstimateData(basicEstimates)) + dispatch(basicGasEstimatesLoadingFinished()) + return basicEstimates + } +} - return basicEstimates - }) - : Promise.resolve(basicPriceAndTimeEstimates.length - ? basicPriceAndTimeEstimates - : loadLocalStorageData('BASIC_GAS_AND_TIME_API_ESTIMATES') - ) - - return promiseToFetch.then(basicEstimates => { - dispatch(setBasicGasEstimateData(basicEstimates)) - dispatch(basicGasEstimatesLoadingFinished()) - return basicEstimates - }) +async function fetchExternalBasicGasAndTimeEstimates (dispatch) { + const response = await fetch('https://ethgasstation.info/json/ethgasAPI.json', { + 'headers': {}, + 'referrer': 'http://ethgasstation.info/json/', + 'referrerPolicy': 'no-referrer-when-downgrade', + 'body': null, + 'method': 'GET', + 'mode': 'cors'} + ) + const { + average: averageTimes10, + avgWait, + block_time: blockTime, + blockNum, + fast: fastTimes10, + fastest: fastestTimes10, + fastestWait, + fastWait, + safeLow: safeLowTimes10, + safeLowWait, + speed, + } = await response.json() + const [average, fast, fastest, safeLow] = [ + averageTimes10, + fastTimes10, + fastestTimes10, + safeLowTimes10, + ].map(price => (new BigNumber(price)).div(10).toNumber()) + + const basicEstimates = { + average, + avgWait, + blockTime, + blockNum, + fast, + fastest, + fastestWait, + fastWait, + safeLow, + safeLowWait, + speed, } + + const timeRetrieved = Date.now() + saveLocalStorageData(basicEstimates, 'BASIC_GAS_AND_TIME_API_ESTIMATES') + saveLocalStorageData(timeRetrieved, 'BASIC_GAS_AND_TIME_API_ESTIMATES_LAST_RETRIEVED') + dispatch(setBasicApiEstimatesLastRetrieved(timeRetrieved)) + + return basicEstimates } function extrapolateY ({ higherY, lowerY, higherX, lowerX, xForExtrapolation }) { @@ -375,13 +372,13 @@ export function fetchGasEstimates (blockTime) { const promiseToFetch = Date.now() - timeLastRetrieved > 75000 ? fetch('https://ethgasstation.info/json/predictTable.json', { - 'headers': {}, - 'referrer': 'http://ethgasstation.info/json/', - 'referrerPolicy': 'no-referrer-when-downgrade', - 'body': null, - 'method': 'GET', - 'mode': 'cors'} - ) + 'headers': {}, + 'referrer': 'http://ethgasstation.info/json/', + 'referrerPolicy': 'no-referrer-when-downgrade', + 'body': null, + 'method': 'GET', + 'mode': 'cors'} + ) .then(r => r.json()) .then(r => { const estimatedPricesAndTimes = r.map(({ expectedTime, expectedWait, gasprice }) => ({ expectedTime, expectedWait, gasprice })) @@ -432,14 +429,14 @@ export function fetchGasEstimates (blockTime) { return timeMappedToSeconds }) : Promise.resolve(priceAndTimeEstimates.length - ? priceAndTimeEstimates - : loadLocalStorageData('GAS_API_ESTIMATES') - ) - - return promiseToFetch.then(estimates => { - dispatch(setPricesAndTimeEstimates(estimates)) - dispatch(gasEstimatesLoadingFinished()) - }) + ? priceAndTimeEstimates + : loadLocalStorageData('GAS_API_ESTIMATES') + ) + + return promiseToFetch.then(estimates => { + dispatch(setPricesAndTimeEstimates(estimates)) + dispatch(gasEstimatesLoadingFinished()) + }) } } diff --git a/ui/app/ducks/index.js b/ui/app/ducks/index.js index 2d33edcfa..18470c441 100644 --- a/ui/app/ducks/index.js +++ b/ui/app/ducks/index.js @@ -61,9 +61,6 @@ window.getCleanAppState = function () { // append additional information state.version = global.platform.getVersion() state.browser = window.navigator.userAgent - // ensure seedWords are not included - if (state.metamask) delete state.metamask.seedWords - if (state.appState.currentView) delete state.appState.currentView.seedWords return state } @@ -72,7 +69,7 @@ window.logStateString = function (cb) { global.platform.getPlatformInfo((err, platform) => { if (err) return cb(err) state.platform = platform - const stateString = JSON.stringify(state, removeSeedWords, 2) + const stateString = JSON.stringify(state, null, 2) cb(null, stateString) }) } @@ -89,7 +86,3 @@ window.logState = function (toClipboard) { } }) } - -function removeSeedWords (key, value) { - return key === 'seedWords' ? undefined : value -} diff --git a/ui/app/ducks/metamask/metamask.js b/ui/app/ducks/metamask/metamask.js index 3ca487c1f..35de947b4 100644 --- a/ui/app/ducks/metamask/metamask.js +++ b/ui/app/ducks/metamask/metamask.js @@ -39,12 +39,13 @@ function reduceMetamask (state, action) { editingTransactionId: null, forceGasMin: null, toNickname: '', + ensResolution: null, + ensResolutionError: '', }, coinOptions: {}, useBlockie: false, featureFlags: {}, networkEndpointType: OLD_UI_NETWORK_TYPE, - isRevealingSeedWords: false, welcomeScreenSeen: false, currentLocale: '', preferences: { @@ -60,13 +61,6 @@ function reduceMetamask (state, action) { switch (action.type) { - case actions.SHOW_ACCOUNTS_PAGE: - newState = extend(metamaskState, { - isRevealingSeedWords: false, - }) - delete newState.seedWords - return newState - case actions.UPDATE_METAMASK_STATE: return extend(metamaskState, action.value) @@ -128,20 +122,12 @@ function reduceMetamask (state, action) { }, }) - - case actions.SHOW_NEW_VAULT_SEED: - return extend(metamaskState, { - isRevealingSeedWords: true, - seedWords: action.value, - }) - case actions.CLEAR_SEED_WORD_CACHE: newState = extend(metamaskState, { isUnlocked: true, isInitialized: true, selectedAddress: action.value, }) - delete newState.seedWords return newState case actions.SHOW_ACCOUNT_DETAIL: @@ -150,7 +136,6 @@ function reduceMetamask (state, action) { isInitialized: true, selectedAddress: action.value, }) - delete newState.seedWords return newState case actions.SET_SELECTED_TOKEN: @@ -290,6 +275,24 @@ function reduceMetamask (state, action) { }, }) + case actions.UPDATE_SEND_ENS_RESOLUTION: + return extend(metamaskState, { + send: { + ...metamaskState.send, + ensResolution: action.payload, + ensResolutionError: '', + }, + }) + + case actions.UPDATE_SEND_ENS_RESOLUTION_ERROR: + return extend(metamaskState, { + send: { + ...metamaskState.send, + ensResolution: null, + ensResolutionError: action.payload, + }, + }) + case actions.CLEAR_SEND: return extend(metamaskState, { send: { @@ -403,12 +406,6 @@ function reduceMetamask (state, action) { }) } - case actions.COMPLETE_UI_MIGRATION: { - return extend(metamaskState, { - completedUiMigration: true, - }) - } - case actions.SET_FIRST_TIME_FLOW_TYPE: { return extend(metamaskState, { firstTimeFlowType: action.value, |