diff --git a/lib/facts/links.js b/lib/facts/links.js --- a/lib/facts/links.js +++ b/lib/facts/links.js @@ -1,9 +1,23 @@ // @flow +/* Invite Links */ function inviteLinkUrl(secret: string): string { return `https://comm.app/invite/${secret}`; } +function parseSecretFromInviteLinkURL(url: string): ?string { + const urlRegex = /invite\/(\S+)$/; + const match = urlRegex.exec(url); + return match?.[1]; +} + +function parseInstallReferrerFromInviteLinkURL(referrer: string): ?string { + const referrerRegex = /utm_source=(invite\/(\S+))$/; + const match = referrerRegex.exec(referrer); + return match?.[1]; +} + +/* QR Code */ function qrCodeLinkUrl(aes256Param: string, ed25519Param: string): string { const keys = { aes256: aes256Param, @@ -19,4 +33,10 @@ return match?.[1]; } -export { inviteLinkUrl, qrCodeLinkUrl, parseKeysFromQRCodeURL }; +export { + inviteLinkUrl, + parseSecretFromInviteLinkURL, + parseInstallReferrerFromInviteLinkURL, + qrCodeLinkUrl, + parseKeysFromQRCodeURL, +}; diff --git a/native/invite-links/invite-links-context-provider.react.js b/native/invite-links/invite-links-context-provider.react.js --- a/native/invite-links/invite-links-context-provider.react.js +++ b/native/invite-links/invite-links-context-provider.react.js @@ -9,6 +9,10 @@ verifyInviteLink, verifyInviteLinkActionTypes, } from 'lib/actions/link-actions.js'; +import { + parseSecretFromInviteLinkURL, + parseInstallReferrerFromInviteLinkURL, +} from 'lib/facts/links.js'; import { isLoggedIn } from 'lib/selectors/user-selectors.js'; import type { SetState } from 'lib/types/hook-types.js'; import { @@ -67,7 +71,7 @@ if (!installReferrer) { return; } - const linkSecret = parseInstallReferrer(installReferrer); + const linkSecret = parseInstallReferrerFromInviteLinkURL(installReferrer); if (linkSecret) { setCurrentLink(linkSecret); } @@ -87,7 +91,7 @@ // results in at most one validation and navigation. setCurrentLink(null); - const secret = parseSecret(currentLink); + const secret = parseSecretFromInviteLinkURL(currentLink); if (!secret) { return; } @@ -123,16 +127,4 @@ ); } -const urlRegex = /invite\/(\S+)$/; -function parseSecret(url: string) { - const match = urlRegex.exec(url); - return match?.[1]; -} - -const referrerRegex = /utm_source=(invite\/(\S+))$/; -function parseInstallReferrer(referrer: string) { - const match = referrerRegex.exec(referrer); - return match?.[1]; -} - export { InviteLinksContext, InviteLinksContextProvider };