From 4d7fba217c8a5285ba4ab2db99f5cd03f5f715ba Mon Sep 17 00:00:00 2001 From: Kirill Ageychenko Date: Mon, 11 Nov 2024 19:25:13 +0700 Subject: [PATCH] fix: fix browser dynamic link query params --- src/event-actions/on-deep-link.ts | 17 ++++++++++++++++- src/event-actions/on-dynamic-link.ts | 19 +++++++++++++++++-- src/helpers/web3-browser-utils.ts | 4 +++- src/widgets/tokens-widget/index.tsx | 2 -- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/event-actions/on-deep-link.ts b/src/event-actions/on-deep-link.ts index 5e076eb14..d5610a4af 100644 --- a/src/event-actions/on-deep-link.ts +++ b/src/event-actions/on-deep-link.ts @@ -13,8 +13,11 @@ import {sendNotification} from '@app/services/toast'; import {DeeplinkProtocol, DeeplinkUrlKey, ModalType} from '@app/types'; import {openInAppBrowser, openWeb3Browser} from '@app/utils'; +import {onDynamicLink} from './on-dynamic-link'; + export type ParsedQuery = { uri?: string; + [key: string]: string | undefined; }; const BROWSERS_FN = { @@ -66,6 +69,12 @@ export async function onDeepLink( return false; } + if (link.startsWith('https://haqq.page.link/')) { + return onDynamicLink({ + url: new Url<{link: string}>(link, true).query.link as string, + }); + } + if (AddressUtils.isHaqqAddress(link)) { await handleAddress(AddressUtils.toEth(link), withoutFromAddress); return true; @@ -125,7 +134,13 @@ export async function onDeepLink( case DeeplinkUrlKey.web3browser: if (await Whitelist.checkUrl(url.query.uri)) { const openBrowserFn = BROWSERS_FN[key]; - openBrowserFn(url.query.uri!); + let uri = url.query.uri!; + for (let qkey in url.query) { + if (qkey !== 'uri') { + uri += `&${qkey}=${url.query[qkey]}`; + } + } + openBrowserFn(uri as string); } else { showModal(ModalType.domainBlocked, { domain: url.query.uri!, diff --git a/src/event-actions/on-dynamic-link.ts b/src/event-actions/on-dynamic-link.ts index 62194bf83..b59df77d5 100644 --- a/src/event-actions/on-dynamic-link.ts +++ b/src/event-actions/on-dynamic-link.ts @@ -11,8 +11,10 @@ import {DynamicLink, MarketingEvents, ModalType} from '@app/types'; import {openInAppBrowser, openWeb3Browser} from '@app/utils'; export async function onDynamicLink(link: Partial | null) { + Logger.log('onDynamicLink', JSON.stringify(link, null, 2)); if (link && 'url' in link) { const parsedUrl = url.parse(link.url!, true); + Logger.log('onDynamicLink parsedUrl', JSON.stringify(parsedUrl, null, 2)); if (typeof parsedUrl?.query?.distinct_id === 'string') { await EventTracker.instance.awaitForInitialization(); @@ -25,7 +27,13 @@ export async function onDynamicLink(link: Partial | null) { if (typeof parsedUrl?.query?.browser === 'string') { if (await Whitelist.checkUrl(parsedUrl?.query?.browser)) { - openInAppBrowser(parsedUrl?.query?.browser); + let uri = parsedUrl?.query?.browser!; + for (const key in parsedUrl.query) { + if (key !== 'browser') { + uri += `&${key}=${parsedUrl.query[key]}`; + } + } + openInAppBrowser(uri as string); } else { showModal(ModalType.domainBlocked, { domain: parsedUrl.query.browser!, @@ -35,7 +43,14 @@ export async function onDynamicLink(link: Partial | null) { if (typeof parsedUrl?.query?.web3_browser === 'string') { if (await Whitelist.checkUrl(parsedUrl?.query?.web3_browser)) { - openWeb3Browser(parsedUrl?.query?.web3_browser); + let uri = parsedUrl?.query?.web3_browser!; + for (const key in parsedUrl.query) { + if (key !== 'web3_browser') { + uri += `&${key}=${parsedUrl.query[key]}`; + } + } + + openWeb3Browser(uri); } else { showModal(ModalType.domainBlocked, { domain: parsedUrl.query.web3_browser!, diff --git a/src/helpers/web3-browser-utils.ts b/src/helpers/web3-browser-utils.ts index a8c6d72d5..dc5780108 100644 --- a/src/helpers/web3-browser-utils.ts +++ b/src/helpers/web3-browser-utils.ts @@ -231,10 +231,12 @@ export const prefixUrlWithProtocol = ( * @returns - String corresponding to sanitized input depending if it's a search or url */ export const onUrlSubmit = ( - input: string, + _input: string, searchEngine = 'Google', defaultProtocol = 'https://', ) => { + // Remove paired quotes from the beginning and end of the input + const input = decodeURIComponent(_input).replace(/^(["'`])(.*)\1$/, '$2'); //Check if it's a url or a keyword const regEx = new RegExp( /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!&',;=.+]+$/g, diff --git a/src/widgets/tokens-widget/index.tsx b/src/widgets/tokens-widget/index.tsx index 725d0e819..7e5e5a974 100644 --- a/src/widgets/tokens-widget/index.tsx +++ b/src/widgets/tokens-widget/index.tsx @@ -44,8 +44,6 @@ export const TokensWidgetWrapper = observer(() => { return Object.values(cache); }, [tokens]); - Logger.log('tokens', JSON.stringify(tokens, null, 2)); - if (tokens.length === 0) { return null; }