Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wallet] Add timestamp to top banner messages #1657

Merged
merged 2 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/mobile/src/alert/AlertBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class AlertBanner extends React.Component<Props> {

return (
<SmartTopAlert
timestamp={Date.now()}
text={alert && alert.message}
onPress={hideAlertAction}
type={alert && alert.type === 'error' ? NotificationTypes.ERROR : NotificationTypes.MESSAGE}
Expand Down
33 changes: 18 additions & 15 deletions packages/mobile/src/invite/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { sanitizeBase64 } from '@celo/walletkit'
import URLSearchParamsReal from '@ungap/url-search-params'
import { Platform } from 'react-native'
import RNInstallReferrer from 'react-native-install-referrer'
import Logger from 'src/utils/Logger'

Expand Down Expand Up @@ -53,23 +54,25 @@ interface ReferrerDataError {
}

export const getValidInviteCodeFromReferrerData = async () => {
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
Expand Down
1 change: 1 addition & 0 deletions packages/mobile/src/shared/BackupPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class BackupPrompt extends React.Component<Props> {

return (
<SmartTopAlert
timestamp={Date.now()}
text={isVisible && t('backupPrompt')}
onPress={this.goToBackup}
type={NotificationTypes.MESSAGE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('SmartTopAlert', () => {
it('renders correctly', async () => {
const { toJSON } = render(
<SmartTopAlert
timestamp={Date.now()}
dismissAfter={5}
title={'Smart Top Alert'}
text="dont get funny"
Expand Down
18 changes: 15 additions & 3 deletions packages/react-components/components/SmartTopAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export enum NotificationTypes {
ERROR = 'error',
}

interface Props {
interface AlertProps {
title?: string | null
text: string | null
onPress: () => void
Expand All @@ -20,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<Props | null>(null)
const [visibleAlertState, setVisibleAlertState] = useState<AlertProps | null>(null)
const insets = useSafeArea()
const yOffset = useRef(new Animated.Value(-500))
const containerRef = useRef<View>()
Expand All @@ -48,7 +52,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() {
Expand Down
1 change: 1 addition & 0 deletions packages/verifier/src/components/ErrorBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class ErrorBox extends React.Component<Props> {

return (
<SmartTopAlert
timestamp={Date.now()}
text={error && t(error)}
onPress={clearErrorAction}
type={NotificationTypes.ERROR}
Expand Down
1 change: 1 addition & 0 deletions packages/verifier/src/components/MessageBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class MessageBanner extends React.Component<Props> {

return (
<SmartTopAlert
timestamp={Date.now()}
text={message}
title={title}
onPress={clearMessageAction}
Expand Down