From aeda278e478b9cfba6f339054afcf4e74e5aa8be Mon Sep 17 00:00:00 2001 From: mucahit Date: Mon, 23 May 2022 14:13:41 +0300 Subject: [PATCH] fix: WC Deeplink generator --- package.json | 2 +- src/util/device/deviceUtils.ts | 6 +++++- src/util/peraWalletUtils.ts | 17 ++++++++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 6643b3b..8766003 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/util/device/deviceUtils.ts b/src/util/device/deviceUtils.ts index 145f417..5f78720 100644 --- a/src/util/device/deviceUtils.ts +++ b/src/util/device/deviceUtils.ts @@ -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); } @@ -38,4 +42,4 @@ function detectBrowser() { return browserName; } -export {isAndroid, isMobile, detectBrowser}; +export {isAndroid, isIOS, isMobile, detectBrowser}; diff --git a/src/util/peraWalletUtils.ts b/src/util/peraWalletUtils.ts index 1c83821..b6f6a3d 100644 --- a/src/util/peraWalletUtils.ts +++ b/src/util/peraWalletUtils.ts @@ -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"; @@ -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 {