From e14d65dabc0be89e63c0cbf032d1526e4dc2bdab Mon Sep 17 00:00:00 2001 From: Ivan Sorokin Date: Mon, 11 Nov 2019 18:42:29 +0100 Subject: [PATCH 1/2] Add timestamp to top banner messages This would allow to show the same message again if needed --- packages/mobile/src/alert/AlertBanner.tsx | 1 + packages/mobile/src/invite/utils.ts | 33 ++++++++++--------- packages/mobile/src/shared/BackupPrompt.tsx | 1 + .../components/SmartTopAlert.test.tsx | 1 + .../components/SmartTopAlert.tsx | 11 ++++++- packages/verifier/src/components/ErrorBox.tsx | 1 + .../verifier/src/components/MessageBanner.tsx | 1 + 7 files changed, 33 insertions(+), 16 deletions(-) diff --git a/packages/mobile/src/alert/AlertBanner.tsx b/packages/mobile/src/alert/AlertBanner.tsx index 6c4fb658c4d..307ec48eafa 100644 --- a/packages/mobile/src/alert/AlertBanner.tsx +++ b/packages/mobile/src/alert/AlertBanner.tsx @@ -31,6 +31,7 @@ export class AlertBanner extends React.Component { return ( { - const referrerData: ReferrerData | ReferrerDataError = await RNInstallReferrer.getReferrer() - Logger.info( - 'invite/utils/getInviteCodeFromReferrerData', - 'Referrer Data: ' + JSON.stringify(referrerData) - ) - if (referrerData && referrerData.hasOwnProperty('installReferrer')) { - const params = new URLSearchParamsReal( - decodeURIComponent((referrerData as ReferrerData).installReferrer) + if (Platform.OS === 'android') { + const referrerData: ReferrerData | ReferrerDataError = await RNInstallReferrer.getReferrer() + Logger.info( + 'invite/utils/getInviteCodeFromReferrerData', + 'Referrer Data: ' + JSON.stringify(referrerData) ) - const inviteCode = params.get('invite-code') - if (inviteCode) { - const sanitizedCode = inviteCode.replace(' ', '+') - // Accept invite codes which are either base64 encoded or direct hex keys - if (isValidPrivateKey(sanitizedCode)) { - return sanitizedCode + if (referrerData && referrerData.hasOwnProperty('installReferrer')) { + const params = new URLSearchParamsReal( + decodeURIComponent((referrerData as ReferrerData).installReferrer) + ) + const inviteCode = params.get('invite-code') + if (inviteCode) { + const sanitizedCode = inviteCode.replace(' ', '+') + // Accept invite codes which are either base64 encoded or direct hex keys + if (isValidPrivateKey(sanitizedCode)) { + return sanitizedCode + } + return extractValidInviteCode(sanitizedCode) } - return extractValidInviteCode(sanitizedCode) } } return null diff --git a/packages/mobile/src/shared/BackupPrompt.tsx b/packages/mobile/src/shared/BackupPrompt.tsx index c268eec07bb..b903bacc428 100644 --- a/packages/mobile/src/shared/BackupPrompt.tsx +++ b/packages/mobile/src/shared/BackupPrompt.tsx @@ -42,6 +42,7 @@ export class BackupPrompt extends React.Component { return ( { it('renders correctly', async () => { const { toJSON } = render( void @@ -48,7 +49,15 @@ function SmartTopAlert(props: Props) { return null } }, - [props.type, props.title, props.text, props.buttonMessage, props.dismissAfter, props.onPress] + [ + props.timestamp, + props.type, + props.title, + props.text, + props.buttonMessage, + props.dismissAfter, + props.onPress, + ] ) function hide() { diff --git a/packages/verifier/src/components/ErrorBox.tsx b/packages/verifier/src/components/ErrorBox.tsx index 0f35856faad..1a09b48ebb2 100644 --- a/packages/verifier/src/components/ErrorBox.tsx +++ b/packages/verifier/src/components/ErrorBox.tsx @@ -34,6 +34,7 @@ export class ErrorBox extends React.Component { return ( { return ( Date: Mon, 11 Nov 2019 18:51:59 +0100 Subject: [PATCH 2/2] Fix type error --- packages/react-components/components/SmartTopAlert.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/react-components/components/SmartTopAlert.tsx b/packages/react-components/components/SmartTopAlert.tsx index 3dc178b4b8c..704bc4048de 100644 --- a/packages/react-components/components/SmartTopAlert.tsx +++ b/packages/react-components/components/SmartTopAlert.tsx @@ -11,8 +11,7 @@ export enum NotificationTypes { ERROR = 'error', } -interface Props { - timestamp: number +interface AlertProps { title?: string | null text: string | null onPress: () => void @@ -21,9 +20,13 @@ interface Props { buttonMessage?: string | null } +interface Props extends AlertProps { + timestamp: number +} + // This component needs to be always mounted for the hide animation to be visible function SmartTopAlert(props: Props) { - const [visibleAlertState, setVisibleAlertState] = useState(null) + const [visibleAlertState, setVisibleAlertState] = useState(null) const insets = useSafeArea() const yOffset = useRef(new Animated.Value(-500)) const containerRef = useRef()