Skip to content

Commit

Permalink
fix: WC Deeplink generator
Browse files Browse the repository at this point in the history
  • Loading branch information
mucahit committed May 23, 2022
1 parent 47bc6d5 commit aeda278
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@perawallet/connect",
"version": "0.0.10",
"version": "0.0.11",
"description": "JavaScript SDK for integrating Pera Wallet to web applications.",
"main": "dist/index.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion src/util/device/deviceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ function isAndroid() {
return /Android/i.test(navigator.userAgent);
}

function isIOS() {
return /iPhone|iPad|iPod/i.test(navigator.userAgent);
}

function isMobile() {
return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
}
Expand Down Expand Up @@ -38,4 +42,4 @@ function detectBrowser() {
return browserName;
}

export {isAndroid, isMobile, detectBrowser};
export {isAndroid, isIOS, isMobile, detectBrowser};
17 changes: 12 additions & 5 deletions src/util/peraWalletUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PeraWalletLogo from "../asset/icon/PeraWallet.svg";

import {detectBrowser, isAndroid} from "./device/deviceUtils";
import {detectBrowser, isAndroid, isIOS} from "./device/deviceUtils";
import {PERA_WALLET_APP_DEEP_LINK} from "./peraWalletConstants";
import {AppMeta} from "./peraWalletTypes";
import {PERA_WALLET_LOCAL_STORAGE_KEYS} from "./storage/storageConstants";
Expand Down Expand Up @@ -31,18 +31,25 @@ function getPeraWalletAppMeta(): AppMeta {
* @returns {string} Pera Wallet deeplink
*/
function generatePeraWalletConnectDeepLink(uri: string): string {
let deeplink = `${generatePeraWalletAppDeepLink()}wc?uri=${encodeURIComponent(uri)}`;
let appDeepLink = generatePeraWalletAppDeepLink();

// Add `wc` suffix to the deeplink if it doesn't exist
if (isIOS() && !appDeepLink.includes("-wc")) {
appDeepLink = appDeepLink.replace("://", "-wc://");
}

let deepLink = `${appDeepLink}wc?uri=${encodeURIComponent(uri)}`;
const browserName = detectBrowser();

if (isAndroid()) {
deeplink = uri;
deepLink = uri;
}

if (browserName) {
deeplink = `${deeplink}&browser=${browserName}`;
deepLink = `${deepLink}&browser=${browserName}`;
}

return deeplink;
return deepLink;
}

export {
Expand Down

0 comments on commit aeda278

Please sign in to comment.