This repository has been archived by the owner on Oct 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Browser): improve chekcs and display browser error message in form
Moved browser detection to a directive. The message no longer disappears after a few seconds. It's displayed right inside the login / signup / recovery form. You can test this by using an old browser or by increasing the required version.
- Loading branch information
Showing
12 changed files
with
287 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
|
||
angular | ||
.module('walletApp') | ||
.directive('browserDetection', directive); | ||
|
||
// Browser compatibility warnings: | ||
// * Secure random number generator: https://developer.mozilla.org/en-US/docs/Web/API/RandomSource/getRandomValues | ||
// * AngularJS support (?) | ||
// * No support before Safari 6 and equivalents based on experience | ||
|
||
const browsers = { | ||
'ie': { | ||
name: 'Internet Explorer', | ||
requiredVersion: 11 | ||
}, | ||
'chrome': { | ||
name: 'Chrome', | ||
requiredVersion: 30 // Roughly the same as Webkit 537.85.17 | ||
}, | ||
'firefox': { | ||
name: 'Firefox', | ||
requiredVersion: 21 | ||
}, | ||
'opera': { | ||
name: 'Opera', | ||
requiredVersion: 20 // First Chromium (33) based release | ||
} | ||
}; | ||
|
||
directive.$inject = ['$q', '$translate', 'MyWallet']; | ||
|
||
function directive ($q, $translate, MyWallet) { | ||
const directive = { | ||
restrict: 'E', | ||
replace: true, | ||
scope: { | ||
result: '=' // Should initially be {disabled: true} | ||
}, | ||
template: ` | ||
<div class="browser-detection"> | ||
<p class="text-warning" ng-show="result.warn">{{ result.msg }}</p> | ||
<p class="text-danger" ng-show="result.disabled">{{ result.msg }}</p> | ||
</div> | ||
`, | ||
link: link | ||
}; | ||
return directive; | ||
|
||
function link (scope, elem, attrs) { | ||
// Unknown browser, check if it can handle the math required: | ||
const checkUnknownBrowser = (defer) => { | ||
if (!MyWallet.browserCheckFast()) { | ||
$translate('UNSUITABLE_BROWSER').then((translation) => { | ||
defer.reject({msg: translation}); | ||
}); | ||
} else { | ||
$translate('UNKNOWN_BROWSER').then((translation) => { | ||
defer.resolve({warn: true, msg: translation}); | ||
}); | ||
} | ||
}; | ||
|
||
scope.getUserAgent = () => navigator.userAgent; | ||
|
||
const checkBrowserVersion = () => { | ||
let defer = $q.defer(); | ||
|
||
let info = browserDetection(); | ||
let matchingBrowser = browsers[info.browser.toLowerCase()]; | ||
if (matchingBrowser) { // One of the known browsers listed above | ||
let requiredVersion = matchingBrowser.requiredVersion; | ||
if (info.version < requiredVersion) { | ||
$translate('MINIMUM_BROWSER', {browser: matchingBrowser.name, userVersion: info.version, requiredVersion: requiredVersion}).then((translation) => { | ||
defer.reject({msg: translation}); | ||
}); | ||
} else if (info.browser === 'ie') { | ||
$translate('WARN_AGAINST_IE').then((translation) => { | ||
defer.resolve({warn: true, msg: translation}); | ||
}); | ||
} else { | ||
defer.resolve({}); | ||
} | ||
} else if (info.webkit) { | ||
// 537.36 is the version referenced by modern Chrome, slightly lower | ||
// might still be acceptable. | ||
let minimumWebkitVersion = '537.36'; | ||
// Patch field may be undefined: | ||
let userVersion = [ | ||
info.webkit.major, | ||
info.webkit.minor, | ||
info.webkit.patch | ||
].filter((x) => typeof (x) === 'number').join('.'); | ||
if (compareVersions(userVersion, minimumWebkitVersion) === -1) { | ||
// Webkit version too old. | ||
if (info.browser === 'safari') { | ||
let safariVersion = 'version'; | ||
const safari = scope.getUserAgent().match(/version\/(\d+\.\d+)/i); | ||
if (safari && safari.length === 2) { | ||
safariVersion = safari[1]; | ||
} | ||
|
||
// The last patch version of Safari 5 (5.1.4 - webkit 534.54.16) did | ||
// work when last checked, but 5.1.2. does not. We increased the | ||
// minimum Safari 6.1 to be on the safe side. | ||
$translate('MINIMUM_BROWSER', {browser: 'Safari', userVersion: safariVersion, requiredVersion: '6.1'}).then((translation) => { | ||
defer.reject({msg: translation}); | ||
}); | ||
} else { | ||
$translate('MINIMUM_BROWSER', {browser: 'Webkit', userVersion: userVersion, requiredVersion: minimumWebkitVersion}).then((translation) => { | ||
defer.reject({msg: translation}); | ||
}); | ||
} | ||
} else { | ||
if (info.browser === 'safari') { | ||
defer.resolve({}); | ||
} else { | ||
// Unknown webkit browser: | ||
checkUnknownBrowser(defer); | ||
} | ||
} | ||
} else { | ||
// Unknown non-webkit browser: | ||
checkUnknownBrowser(defer); | ||
} | ||
return defer.promise; | ||
}; | ||
|
||
scope.performCheck = () => { | ||
checkBrowserVersion().then((res) => { | ||
scope.result.disabled = false; | ||
scope.result.warn = res.warn; | ||
scope.result.msg = res.msg; | ||
}).catch((res) => { | ||
scope.result.disabled = true; | ||
scope.result.msg = res.msg; | ||
}); | ||
}; | ||
|
||
scope.performCheck(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.