Skip to content

Commit

Permalink
fix: handle desktop and mobile differently
Browse files Browse the repository at this point in the history
  • Loading branch information
aramalipoor committed Nov 8, 2022
1 parent 143aef9 commit 28f1033
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
8 changes: 5 additions & 3 deletions packages/react/src/common/utils/dark-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ export const isDarkMode = () => {
? window?.localStorage?.getItem?.('mode') === 'dark'
: undefined;

return explicitDarkMode !== undefined
? explicitDarkMode
: darkByUrl || darkByMedia || darkByLocalStorage;
return Boolean(
explicitDarkMode !== undefined
? explicitDarkMode
: darkByUrl || darkByMedia || darkByLocalStorage,
);
};

export const setDarkMode = (
Expand Down
6 changes: 6 additions & 0 deletions packages/react/src/core/utils/browsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function isSafari(): boolean {
return (
typeof navigator !== 'undefined' &&
/Version\/([0-9._]+).*Safari/.test(navigator.userAgent) // Source: https://github.com/DamonOehlman/detect-browser/blob/master/src/index.ts
);
}
1 change: 1 addition & 0 deletions packages/react/src/core/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './browsers';
export * from './mobile';
export * from './openWalletConnectDeepLink';
export * from './useMergeQueryStates';
21 changes: 13 additions & 8 deletions packages/react/src/core/utils/openWalletConnectDeepLink.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { connect, Connector } from '@wagmi/core';
import { WalletConnectConnector } from '@wagmi/core/connectors/walletConnect';

import { isAndroid } from './mobile';
import { isSafari } from './browsers';
import { isAndroid, isMobile } from './mobile';

export const openWalletConnectDeepLink = async (
wcUriPrefix: string,
Expand Down Expand Up @@ -31,14 +32,18 @@ export const openWalletConnectDeepLink = async (
? uri
: `${wcUriPrefix}${encodeURIComponent(uri)}`;

if (finalLink.startsWith('http')) {
const link = document.createElement('a');
link.href = finalLink;
link.target = '_blank';
link.rel = 'noreferrer noopener';
link.click();
if (isMobile()) {
if (finalLink.startsWith('http')) {
const link = document.createElement('a');
link.href = finalLink;
link.target = '_blank';
link.rel = 'noreferrer noopener';
link.click();
} else {
window.location.href = finalLink;
}
} else {
window.location.href = finalLink;
window.open(finalLink, isSafari() ? '_blank' : '_self');
}
});
} catch (e) {
Expand Down

0 comments on commit 28f1033

Please sign in to comment.