mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 09:33:46 +00:00
fix(connection): happ cryptolink flow + ui fixes (#385)
* fix(connection): respect happ_cryptolink mode - read connect_mode from connection-link endpoint - auto-redirect to happ cryptolink flow when mode is HAPP_CRYPTOLINK - keep installation guide behavior for other modes * docs(readme): fix source build step 2 - use compose service name for build/create commands - copy static files from created compose container - remove compose container via docker compose rm * fix(connection): handle mode and ws path - treat any non-guide connect mode as direct happ redirect - wait for connection-link response before rendering installation guide - build websocket URL from VITE_API_URL (supports /api and absolute URLs) * docs(readme): fix docker cp static path - copy /usr/share/nginx/html contents via html/. - prevent nested /srv/cabinet/html deployment and 404 on root * fix(connection): keep guide, use happ links - restore guide page behavior for /connection (no auto redirect) - use happ cryptolink URL in /connection/qr when happ crypt mode is active - replace subscription page connection URL with happ cryptolink from connection-link API * fix(connection): avoid wrong redirect flow - force happ scheme deeplink in HAPP_CRYPTOLINK mode for guide connect buttons - use cabinet redirect page only inside Telegram Mini App - open deeplink directly in regular browsers * fix(connection): enforce happ cryptolink - prioritize backend crypt deeplink fields in HAPP_CRYPTOLINK mode - fallback to local crypt4/crypt3 generation from subscription URL when backend returns plain happ://sub... - apply same resolution for guide open action, qr page source and subscription page link display/copy * fix(subscription): truncate long connect link - render connection URL in a single line with ellipsis on /subscriptions - preserve full URL in tooltip for easier manual copy - keep copy button behavior unchanged * fix(connection): build cryptolink from happ sub - allow cryptolink fallback generation from happ://sub... URLs in addition to http(s) - prevent plain happ://sub links from leaking into UI in HAPP_CRYPTOLINK mode
This commit is contained in:
67
src/utils/connectionLink.ts
Normal file
67
src/utils/connectionLink.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { createHappCryptoLink } from '@kastov/cryptohapp';
|
||||
|
||||
export function isHappCryptolinkMode(mode: string | null | undefined): boolean {
|
||||
const normalized = String(mode ?? '').toUpperCase();
|
||||
if (!normalized) return false;
|
||||
return normalized.includes('HAPP') && normalized.includes('CRYPT');
|
||||
}
|
||||
|
||||
function isHttpUrl(url: string | null | undefined): url is string {
|
||||
return typeof url === 'string' && /^https?:\/\//i.test(url);
|
||||
}
|
||||
|
||||
function isHappSubscriptionLink(url: string | null | undefined): url is string {
|
||||
return typeof url === 'string' && /^happ:\/\/sub/i.test(url);
|
||||
}
|
||||
|
||||
function isCryptSourceUrl(url: string | null | undefined): url is string {
|
||||
return isHttpUrl(url) || isHappSubscriptionLink(url);
|
||||
}
|
||||
|
||||
function isHappCryptDeepLink(url: string | null | undefined): url is string {
|
||||
return typeof url === 'string' && /^happ:\/\/crypt/i.test(url);
|
||||
}
|
||||
|
||||
interface ResolveConnectionUrlInput {
|
||||
mode?: string | null;
|
||||
subscriptionUrl?: string | null;
|
||||
displayLink?: string | null;
|
||||
happSchemeLink?: string | null;
|
||||
happCryptLink?: string | null;
|
||||
happCryptoLink?: string | null;
|
||||
happLink?: string | null;
|
||||
fallbackUrl?: string | null;
|
||||
}
|
||||
|
||||
export function resolveConnectionUrlForUi(input: ResolveConnectionUrlInput): string | null {
|
||||
const defaultUrl =
|
||||
input.fallbackUrl ?? input.subscriptionUrl ?? input.displayLink ?? input.happSchemeLink ?? null;
|
||||
|
||||
if (!isHappCryptolinkMode(input.mode)) return defaultUrl;
|
||||
|
||||
const backendCryptLink =
|
||||
[
|
||||
input.happCryptLink,
|
||||
input.happCryptoLink,
|
||||
input.happLink,
|
||||
input.happSchemeLink,
|
||||
input.displayLink,
|
||||
input.subscriptionUrl,
|
||||
].find((value) => isHappCryptDeepLink(value)) ?? null;
|
||||
if (backendCryptLink) return backendCryptLink;
|
||||
|
||||
const sourceSubscriptionUrl =
|
||||
[input.subscriptionUrl, input.displayLink, input.fallbackUrl].find((value) =>
|
||||
isCryptSourceUrl(value),
|
||||
) ?? null;
|
||||
|
||||
if (sourceSubscriptionUrl) {
|
||||
return (
|
||||
createHappCryptoLink(sourceSubscriptionUrl, 'v4', true) ??
|
||||
createHappCryptoLink(sourceSubscriptionUrl, 'v3', true) ??
|
||||
defaultUrl
|
||||
);
|
||||
}
|
||||
|
||||
return defaultUrl;
|
||||
}
|
||||
Reference in New Issue
Block a user