From d399a176aca6314e45f41059be213222f1f1e20f Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Tue, 12 Dec 2023 19:34:18 -0700 Subject: [PATCH 1/3] ref link pasting working --- .../points/content/ReferralContent.tsx | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/screens/points/content/ReferralContent.tsx b/src/screens/points/content/ReferralContent.tsx index 2c920db75d5..e071bdf947a 100644 --- a/src/screens/points/content/ReferralContent.tsx +++ b/src/screens/points/content/ReferralContent.tsx @@ -38,6 +38,17 @@ import { PointsIconAnimation } from '../components/PointsIconAnimation'; import { usePointsReferralCode } from '@/resources/points'; import { analyticsV2 } from '@/analytics'; +const parseReferralCodeFromLink = (code: string) => { + if (!code.startsWith('https://rainbow.me/points?ref=')) return; + + const [, refCode] = code.split('='); + if (!refCode) return; + + const trimmed = refCode.replace(/-/g, '').slice(0, 6).toLocaleUpperCase(); + + return trimmed; +}; + export default function ReferralContent() { const { accentColor } = useAccountAccentColor(); const { goBack, navigate } = useNavigation(); @@ -61,7 +72,7 @@ export default function ReferralContent() { const validateReferralCode = useCallback( async (code: string) => { - if (code.length !== 6) return; + if (code.length !== 6) return false; const res = await metadataPOSTClient.validateReferral({ code, }); @@ -87,7 +98,10 @@ export default function ReferralContent() { setReferralCode(code); textInputRef.current?.blur(); haptics.notificationSuccess(); + return true; } + + return false; }, [deeplinked] ); @@ -176,9 +190,21 @@ export default function ReferralContent() { }); const onChangeText = useCallback( - (code: string) => { + async (code: string) => { if (goingBack) return; + const codeFromUrl = parseReferralCodeFromLink(code); + if (codeFromUrl) { + const isValid = await validateReferralCode(codeFromUrl); + if (!isValid) return; + + setReferralCodeDisplay( + codeFromUrl.slice(0, 3) + '-' + codeFromUrl.slice(3, 7) + ); + navigate(Routes.CONSOLE_SHEET, { referralCode, deeplinked }); + return; + } + const rawCode = code.replace(/-/g, '').slice(0, 6).toLocaleUpperCase(); let formattedCode = rawCode; @@ -202,7 +228,14 @@ export default function ReferralContent() { validateReferralCode(rawCode); } }, - [goingBack, referralCodeDisplay.length, validateReferralCode] + [ + deeplinked, + referralCode, + navigate, + goingBack, + referralCodeDisplay.length, + validateReferralCode, + ] ); return ( @@ -272,7 +305,7 @@ export default function ReferralContent() { }), }} autoFocus={false} - maxLength={7} + // maxLength={7} // TODO: Figure out how to enable this and allow LINK pasting & parsing selectionColor={statusColor} textAlign="left" autoCapitalize="characters" From 93ff79b44a15c73839d7da466628098a72eeb345 Mon Sep 17 00:00:00 2001 From: Ben Goldberg Date: Wed, 13 Dec 2023 10:23:13 -0800 Subject: [PATCH 2/3] set max length to 7 --- .../points/content/ReferralContent.tsx | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/screens/points/content/ReferralContent.tsx b/src/screens/points/content/ReferralContent.tsx index e071bdf947a..248722aefab 100644 --- a/src/screens/points/content/ReferralContent.tsx +++ b/src/screens/points/content/ReferralContent.tsx @@ -37,6 +37,7 @@ import { ActionButton } from '@/screens/points/components/ActionButton'; import { PointsIconAnimation } from '../components/PointsIconAnimation'; import { usePointsReferralCode } from '@/resources/points'; import { analyticsV2 } from '@/analytics'; +import Clipboard from '@react-native-community/clipboard'; const parseReferralCodeFromLink = (code: string) => { if (!code.startsWith('https://rainbow.me/points?ref=')) return; @@ -192,16 +193,19 @@ export default function ReferralContent() { const onChangeText = useCallback( async (code: string) => { if (goingBack) return; - - const codeFromUrl = parseReferralCodeFromLink(code); - if (codeFromUrl) { - const isValid = await validateReferralCode(codeFromUrl); - if (!isValid) return; - - setReferralCodeDisplay( - codeFromUrl.slice(0, 3) + '-' + codeFromUrl.slice(3, 7) - ); - navigate(Routes.CONSOLE_SHEET, { referralCode, deeplinked }); + if (code === 'https:/') { + const url = await Clipboard.getString(); + const codeFromUrl = parseReferralCodeFromLink(url); + if (codeFromUrl) { + const formattedCode = + codeFromUrl.slice(0, 3) + '-' + codeFromUrl.slice(3, 7); + setReferralCodeDisplay(formattedCode); + if (formattedCode.length !== 7) { + setStatus('incomplete'); + } else { + validateReferralCode(codeFromUrl); + } + } return; } @@ -228,14 +232,7 @@ export default function ReferralContent() { validateReferralCode(rawCode); } }, - [ - deeplinked, - referralCode, - navigate, - goingBack, - referralCodeDisplay.length, - validateReferralCode, - ] + [goingBack, referralCodeDisplay.length, validateReferralCode] ); return ( @@ -305,7 +302,7 @@ export default function ReferralContent() { }), }} autoFocus={false} - // maxLength={7} // TODO: Figure out how to enable this and allow LINK pasting & parsing + maxLength={7} // TODO: Figure out how to enable this and allow LINK pasting & parsing selectionColor={statusColor} textAlign="left" autoCapitalize="characters" From ce7e3bbd34f769bc320fa6307e7860422f29b0dd Mon Sep 17 00:00:00 2001 From: Ben Goldberg Date: Wed, 13 Dec 2023 10:24:37 -0800 Subject: [PATCH 3/3] rm comment --- src/screens/points/content/ReferralContent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/screens/points/content/ReferralContent.tsx b/src/screens/points/content/ReferralContent.tsx index 248722aefab..73f91ef9839 100644 --- a/src/screens/points/content/ReferralContent.tsx +++ b/src/screens/points/content/ReferralContent.tsx @@ -302,7 +302,7 @@ export default function ReferralContent() { }), }} autoFocus={false} - maxLength={7} // TODO: Figure out how to enable this and allow LINK pasting & parsing + maxLength={7} selectionColor={statusColor} textAlign="left" autoCapitalize="characters"