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

fix: browser dynamic link query params #2195

Merged
merged 1 commit into from
Nov 13, 2024
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
17 changes: 16 additions & 1 deletion src/event-actions/on-deep-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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!,
Expand Down
19 changes: 17 additions & 2 deletions src/event-actions/on-dynamic-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {DynamicLink, MarketingEvents, ModalType} from '@app/types';
import {openInAppBrowser, openWeb3Browser} from '@app/utils';

export async function onDynamicLink(link: Partial<DynamicLink> | 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();
Expand All @@ -25,7 +27,13 @@ export async function onDynamicLink(link: Partial<DynamicLink> | 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!,
Expand All @@ -35,7 +43,14 @@ export async function onDynamicLink(link: Partial<DynamicLink> | 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!,
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/web3-browser-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/widgets/tokens-widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down