Skip to content

Commit

Permalink
feat(ui): enhance return strategies for ipad
Browse files Browse the repository at this point in the history
  • Loading branch information
thekiba committed Mar 25, 2024
1 parent 17a9dbe commit a7ab8e4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/ui/src/app/styles/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function isDevice(device: keyof typeof maxWidth | 'desktop'): boolean {
return width > maxWidth.mobile;
default:
case 'mobile':
return width <= maxWidth.mobile || isOS('ios', 'android');
return width <= maxWidth.mobile || isOS('ios', 'android', 'ipad');
}
}

Expand Down
49 changes: 49 additions & 0 deletions packages/ui/src/app/utils/url-strategy-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,36 @@ export function redirectToTelegram(
options.returnStrategy
);

openLinkBlank(linkWithStrategy);
}
} else if (isOS('ipad')) {
// Use the `back` strategy, the user will transition to the other app
// and return to the browser when the action is completed.

// TODO: use back for all browsers
if (options.returnStrategy === 'back') {
options.returnStrategy = 'back';
}

// In case if the browser is Chrome or Firefox, use the deep link with fallback to the direct link.
const isChrome = isBrowser('chrome');
const isFirefox = isBrowser('firefox');
const useDeepLink = (isChrome || isFirefox) && !options.forceRedirect;

if (useDeepLink) {
const linkWithStrategy = addReturnStrategy(
directLinkUrl.toString(),
options.returnStrategy
);
const deepLink = convertToTGDeepLink(linkWithStrategy);

openDeeplinkWithFallback(deepLink, () => openLinkBlank(linkWithStrategy));
} else {
const linkWithStrategy = addReturnStrategy(
directLinkUrl.toString(),
options.returnStrategy
);

openLinkBlank(linkWithStrategy);
}
} else if (isOS('macos', 'windows', 'linux')) {
Expand Down Expand Up @@ -389,6 +419,25 @@ export function redirectToWallet(
setOpenMethod('universal-link');

openLinkBlank(addReturnStrategy(universalLink, options.returnStrategy));
} else if (isOS('ipad')) {
// Use the `back` strategy, the user will transition to the other app
// and return to the browser when the action is completed.

// return back to the browser
if (options.returnStrategy === 'back') {
options.returnStrategy = 'back';
}

if (isBrowser('chrome')) {
setOpenMethod('universal-link');

// TODO: in case when the wallet does not exist, the location.href will be rewritten
openLink(addReturnStrategy(universalLink, options.returnStrategy), '_self');
} else {
setOpenMethod('universal-link');

openLinkBlank(addReturnStrategy(universalLink, options.returnStrategy));
}
} else if (isOS('macos', 'windows', 'linux')) {
// Use the `back` strategy, the user will transition to the other app
// and return to the browser when the action is completed.
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/src/app/utils/web-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ export function isMobileUserAgent(): boolean {
export function getUserAgent(): UserAgent {
const results = new UAParser().getResult();
const osName = results.os.name?.toLowerCase();
const deviceModel = results.device.model?.toLowerCase();
let os: UserAgent['os'];
switch (true) {
case deviceModel === 'ipad':
os = 'ipad';
break;
case osName === 'ios':
os = 'ios';
break;
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/models/user-agent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface UserAgent {
os: 'ios' | 'android' | 'macos' | 'windows' | 'linux' | undefined;
os: 'ios' | 'ipad' | 'android' | 'macos' | 'windows' | 'linux' | undefined;
browser: 'chrome' | 'firefox' | 'safari' | 'opera' | undefined;
}

0 comments on commit a7ab8e4

Please sign in to comment.