Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle browser support #96

Merged
merged 6 commits into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/components/Features/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import {Menu, WalletLogin} from '../../UI';
import {useHideModal, useProgressModal} from '../ModalProvider/ModalProvider.hooks';
import {AUTO_CONNECT_TIMEOUT_DURATION, MODAL_TIMEOUT_DURATION} from './Login.constants';
import styles from './Login.module.scss';
import {DOWNLOAD_TEXT, MODAL_TXT, SUBTITLE_TXT, TITLE_TXT} from './Login.strings';
import {
DOWNLOAD_TEXT,
MODAL_TXT,
SUBTITLE_TXT,
TITLE_TXT,
UNSUPPORTED_BROWSER_TXT
} from './Login.strings';

export const Login = () => {
const {autoConnect} = useConfig();
Expand All @@ -25,6 +31,10 @@ export const Login = () => {

useEffect(() => {
let timeoutId;
if (!utils.browser.isChrome()) {
setErrorMsg(UNSUPPORTED_BROWSER_TXT);
return;
}
if (autoConnect) {
const handlers = getWalletHandlers(walletType);
if (handlers.length > 0) {
Expand Down Expand Up @@ -116,6 +126,7 @@ export const Login = () => {
<WalletLogin
key={id}
description={description}
isDisabled={!utils.browser.isChrome()}
logoPath={logoPath}
name={name}
onClick={() => onWalletConnect(walletHandler)}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Features/Login/Login.strings.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import utils from '../../../utils';

const {title_txt, subtitle_txt, download_txt, modal_txt} = utils.getTranslation('menus.login');
const {title_txt, subtitle_txt, download_txt, modal_txt, unsupported_browser_txt} =
utils.getTranslation('menus.login');

export const TITLE_TXT = title_txt;
export const DOWNLOAD_TEXT = download_txt;
export const UNSUPPORTED_BROWSER_TXT = unsupported_browser_txt;
export const SUBTITLE_TXT = networkName => utils.object.evaluate(subtitle_txt, {networkName});
export const MODAL_TXT = walletName => utils.object.evaluate(modal_txt, {walletName});
9 changes: 7 additions & 2 deletions src/components/UI/WalletLogin/WalletLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import React from 'react';

import {ReactComponent as ForwardIcon} from '../../../assets/svg/icons/forward.svg';
import utils from '../../../utils';
import {toClasses} from '../../../utils/object';
import {DynamicIcon} from '../index';
import styles from './WalletLogin.module.scss';

export const WalletLogin = ({name, description, logoPath, onClick}) => (
export const WalletLogin = ({name, description, logoPath, isDisabled, onClick}) => (
<>
<div className={styles.walletLogin} onClick={onClick}>
<div
className={toClasses(styles.walletLogin, isDisabled && styles.isDisabled)}
onClick={onClick}
>
<div className={styles.left}>
<DynamicIcon path={logoPath} size={41} />
<div className={styles.text}>
Expand All @@ -26,5 +30,6 @@ WalletLogin.propTypes = {
name: PropTypes.string,
description: PropTypes.string,
logoPath: PropTypes.string,
isDisabled: PropTypes.bool,
onClick: PropTypes.func
};
5 changes: 5 additions & 0 deletions src/components/UI/WalletLogin/WalletLogin.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ $background-color-hover: $--color-alpha-1;
align-items: center;
justify-content: space-between;

&.isDisabled {
pointer-events: none;
opacity: 0.2;
}

.left {
display: flex;

Expand Down
3 changes: 2 additions & 1 deletion src/config/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const strings = {
title_txt: 'Login',
subtitle_txt: 'Please select {{networkName}} wallet to connect with this dApp:',
download_txt: ['Don’t have a wallet?', 'Download Here'],
modal_txt: 'Waiting for confirmation from {{walletName}}'
modal_txt: 'Waiting for confirmation from {{walletName}}',
unsupported_browser_txt: `Note - The current version of StarkGate (Alpha) doesn't support your browser. Use Chrome to connect.`
},
account: {
title_txt: '{{network}} Account',
Expand Down
4 changes: 4 additions & 0 deletions src/utils/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ export const getUrlParameter = name => {
const results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};

export const isChrome = () => {
return /(?=.*(chrome)).*/i.test(navigator.userAgent);
};