From 275c31855da73299f4e0838d9ecbcc4278b8431c Mon Sep 17 00:00:00 2001 From: Jenny Pollack Date: Wed, 6 Jun 2018 18:10:05 -0700 Subject: [PATCH 1/7] first language - add check for brave browser on getAcceptLanguages --- app/scripts/lib/get-first-preferred-lang-code.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 1e6a83ba6..5e524f9eb 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -1,8 +1,14 @@ const extension = require('extensionizer') const promisify = require('pify') const allLocales = require('../../_locales/index.json') +const log = require('loglevel') +// as far as i can tell, this is truthy in the case of Brave browser +// where extension.i18n.getAcceptLanguages throws due to not being implemented +// Unchecked runtime.lastError while running i18n.getAcceptLanguages: Access to extension API denied. +// https://stackoverflow.com/questions/28431505/unchecked-runtime-lasterror-when-using-chrome-api const isSupported = extension.i18n && extension.i18n.getAcceptLanguages + const getPreferredLocales = isSupported ? promisify( extension.i18n.getAcceptLanguages, { errorFirst: false } @@ -18,7 +24,11 @@ const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().r * */ async function getFirstPreferredLangCode () { - const userPreferredLocaleCodes = await getPreferredLocales() + let userPreferredLocaleCodes = await getPreferredLocales() + if(!userPreferredLocaleCodes){ + userPreferredLocaleCodes = [] + } + log.debug(`user preferredLocaleCodes: ${userPreferredLocaleCodes}`) const firstPreferredLangCode = userPreferredLocaleCodes .map(code => code.toLowerCase()) .find(code => existingLocaleCodes.includes(code)) From 7edde61c1231b1df6023ac458559b8a008bf300d Mon Sep 17 00:00:00 2001 From: Jenny Pollack Date: Wed, 6 Jun 2018 18:24:45 -0700 Subject: [PATCH 2/7] preferred first languauge - check for Brave --- app/scripts/lib/get-first-preferred-lang-code.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 5e524f9eb..89239a013 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -3,13 +3,7 @@ const promisify = require('pify') const allLocales = require('../../_locales/index.json') const log = require('loglevel') -// as far as i can tell, this is truthy in the case of Brave browser -// where extension.i18n.getAcceptLanguages throws due to not being implemented -// Unchecked runtime.lastError while running i18n.getAcceptLanguages: Access to extension API denied. -// https://stackoverflow.com/questions/28431505/unchecked-runtime-lasterror-when-using-chrome-api -const isSupported = extension.i18n && extension.i18n.getAcceptLanguages - -const getPreferredLocales = isSupported ? promisify( +const getPreferredLocales = extension.i18n ? promisify( extension.i18n.getAcceptLanguages, { errorFirst: false } ) : async () => [] @@ -25,10 +19,13 @@ const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().r */ async function getFirstPreferredLangCode () { let userPreferredLocaleCodes = await getPreferredLocales() + + // safeguard for Brave Browser until they implement chrome.i18n.getAcceptLanguages + // https://github.com/MetaMask/metamask-extension/issues/4270 if(!userPreferredLocaleCodes){ userPreferredLocaleCodes = [] } - log.debug(`user preferredLocaleCodes: ${userPreferredLocaleCodes}`) + const firstPreferredLangCode = userPreferredLocaleCodes .map(code => code.toLowerCase()) .find(code => existingLocaleCodes.includes(code)) From 01a1eff8a82167217b4d805e8c09f49ad0109aae Mon Sep 17 00:00:00 2001 From: Jenny Pollack Date: Wed, 6 Jun 2018 18:35:41 -0700 Subject: [PATCH 3/7] remove loglevel --- app/scripts/lib/get-first-preferred-lang-code.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 89239a013..4d4d9df9a 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -1,7 +1,6 @@ const extension = require('extensionizer') const promisify = require('pify') const allLocales = require('../../_locales/index.json') -const log = require('loglevel') const getPreferredLocales = extension.i18n ? promisify( extension.i18n.getAcceptLanguages, @@ -25,7 +24,7 @@ async function getFirstPreferredLangCode () { if(!userPreferredLocaleCodes){ userPreferredLocaleCodes = [] } - + const firstPreferredLangCode = userPreferredLocaleCodes .map(code => code.toLowerCase()) .find(code => existingLocaleCodes.includes(code)) From fd8bcc9cb1b9f9c1cc5ef48eda4952182b23e499 Mon Sep 17 00:00:00 2001 From: Jenny Pollack Date: Wed, 6 Jun 2018 22:08:32 -0700 Subject: [PATCH 4/7] lint --- app/scripts/lib/get-first-preferred-lang-code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 4d4d9df9a..2384e655e 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -21,7 +21,7 @@ async function getFirstPreferredLangCode () { // safeguard for Brave Browser until they implement chrome.i18n.getAcceptLanguages // https://github.com/MetaMask/metamask-extension/issues/4270 - if(!userPreferredLocaleCodes){ + if (!userPreferredLocaleCodes){ userPreferredLocaleCodes = [] } From 93bdfc0bba9d03b3d14f85df1612c5f3475744e9 Mon Sep 17 00:00:00 2001 From: Jenny Pollack Date: Thu, 7 Jun 2018 14:15:02 -0700 Subject: [PATCH 5/7] changelog 4270 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fef15109..7211d88e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ - Fix bug where account reset did not work with custom RPC providers. +## 4.7.5 Thu Jun 07 2018 +- Fix for Brave i18n getAcceptLanguages [#4270](https://github.com/MetaMask/metamask-extension/issues/4270) + ## 4.7.4 Tue Jun 05 2018 - Add diagnostic reporting for users with multiple HD keyrings From 368fe229c245a13ad59ed374b4b7f10d1f0e0488 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 8 Jun 2018 21:04:20 -0700 Subject: [PATCH 6/7] changelog - version fix --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7211d88e6..32d9f5695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,6 @@ ## Current Master - Fix bug where account reset did not work with custom RPC providers. - -## 4.7.5 Thu Jun 07 2018 - Fix for Brave i18n getAcceptLanguages [#4270](https://github.com/MetaMask/metamask-extension/issues/4270) ## 4.7.4 Tue Jun 05 2018 From 11bfdf444dca3917479cff82f807cc0d4c217191 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 14 Jun 2018 10:09:45 -0700 Subject: [PATCH 7/7] Handle brave throws --- app/scripts/lib/get-first-preferred-lang-code.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 2384e655e..41a886d74 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -17,12 +17,19 @@ const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().r * */ async function getFirstPreferredLangCode () { - let userPreferredLocaleCodes = await getPreferredLocales() - + let userPreferredLocaleCodes + + try { + userPreferredLocaleCodes = await getPreferredLocales() + } catch (e) { + // Brave currently throws when calling getAcceptLanguages, so this handles that. + userPreferredLocaleCodes = [] + } + // safeguard for Brave Browser until they implement chrome.i18n.getAcceptLanguages // https://github.com/MetaMask/metamask-extension/issues/4270 if (!userPreferredLocaleCodes){ - userPreferredLocaleCodes = [] + userPreferredLocaleCodes = [] } const firstPreferredLangCode = userPreferredLocaleCodes @@ -32,3 +39,4 @@ async function getFirstPreferredLangCode () { } module.exports = getFirstPreferredLangCode +