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

[5.3] Add On-Ramp Aggregator What's new modal #4484

Merged
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
79 changes: 58 additions & 21 deletions app/components/UI/WhatsNewModal/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import {
StyleSheet,
View,
Expand Down Expand Up @@ -26,7 +26,11 @@ import compareVersions from 'compare-versions';
import PropTypes from 'prop-types';
import { findRouteNameFromNavigatorState } from '../../../util/general';
import StyledButton from '../StyledButton';
import { useAppThemeFromContext, mockTheme } from '../../../util/theme';
import {
useAppThemeFromContext,
mockTheme,
useAssetFromTheme,
} from '../../../util/theme';
const modalMargin = 24;
const modalPadding = 24;
const screenWidth = Device.getDeviceWidth();
Expand All @@ -51,7 +55,13 @@ const createStyles = (colors) =>
flex: 1,
width: slideItemWidth,
paddingHorizontal: modalPadding,
},
slideItemContainerContent: {
paddingBottom: 16,
flexGrow: 1,
},
slide: {
flex: 1,
Comment on lines +58 to +64
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows the slide to be full height

},
progessContainer: {
flexDirection: 'row',
Expand Down Expand Up @@ -119,12 +129,13 @@ const createStyles = (colors) =>
});

const WhatsNewModal = (props) => {
const scrollViewRef = useRef();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ref is later used to scroll when indicators are pressed.

const [featuresToShow, setFeaturesToShow] = useState(null);
const [show, setShow] = useState(false);
const routes = useNavigationState((state) => state.routes);
const slideIds = [0, 1];
const [currentSlide, setCurrentSlide] = useState(slideIds[0]);
const [currentSlide, setCurrentSlide] = useState(0);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slides where fixed to be 2, this is now agnostic of the length of the slides coming from whatsNew

const { colors } = useAppThemeFromContext() || mockTheme;
const imageKey = useAssetFromTheme('light', 'dark');
const styles = createStyles(colors);

useEffect(() => {
Expand Down Expand Up @@ -208,16 +219,23 @@ const WhatsNewModal = (props) => {
return (element = (
<Text style={styles.slideDescription}>{elementInfo.description}</Text>
));
case 'image':
case 'image': {
let image;
if (elementInfo.images) {
image = elementInfo.images[imageKey];
} else {
image = elementInfo.image;
}
return (
<View style={styles.slideImageContainer}>
<Image
source={elementInfo.image}
source={image}
style={styles.slideImage}
resizeMode={'stretch'}
/>
</View>
);
}
case 'button':
return (
<View style={styles.button}>
Expand All @@ -236,9 +254,13 @@ const WhatsNewModal = (props) => {
const renderSlide = (slideInfo, index) => {
const key = `slide-info-${index}`;
return (
<ScrollView key={key} style={styles.slideItemContainer}>
<ScrollView
key={key}
style={styles.slideItemContainer}
contentContainerStyle={styles.slideItemContainerContent}
>
<TouchableWithoutFeedback>
<View>
<View style={styles.slide}>
Comment on lines +257 to +263
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows slides to be full height

{slideInfo.map((elementInfo, elIndex) => {
const elKey = `${key}-${elIndex}`;
return <View key={elKey}>{renderSlideElement(elementInfo)}</View>;
Expand Down Expand Up @@ -276,13 +298,15 @@ const WhatsNewModal = (props) => {
onPress={closeModal}
hitSlop={{ top: 10, left: 10, bottom: 10, right: 10 }}
>
<Icon name="times" size={16} />
<Icon name="times" size={16} color={colors.icon.default} />
</TouchableOpacity>
</View>
</View>
{featuresToShow && (
{whatsNew.slides.length > 0 && (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditionally rendering based on featuresToShow was causing a content flash when CTAs were pressed.

<View style={styles.slideContent}>
<ScrollView
ref={scrollViewRef}
scrollEnabled={whatsNew.slides.length > 1}
Copy link
Member Author

@wachunei wachunei Jun 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ref is used to scroll then indicators are pressed. Scroll is disabled if there's only one page.

// This is not duplicate. Needed for Android.
onScrollEndDrag={onScrollEnd}
onMomentumScrollEnd={onScrollEnd}
Expand All @@ -292,17 +316,30 @@ const WhatsNewModal = (props) => {
>
{whatsNew.slides.map(renderSlide)}
</ScrollView>
<View style={styles.progessContainer}>
{slideIds.map((id) => (
<View
key={id}
style={[
styles.slideCircle,
currentSlide === id ? styles.slideSolidCircle : {},
]}
/>
))}
</View>
{whatsNew.slides.length > 1 && (
<View style={styles.progessContainer}>
{whatsNew.slides.map((_, index) => (
<TouchableWithoutFeedback
key={`slide-circle-${index}`}
onPress={() => {
scrollViewRef?.current?.scrollTo({
y: 0,
x: index * slideItemWidth,
});
setCurrentSlide(index);
}}
hitSlop={{ top: 8, left: 8, bottom: 8, right: 8 }}
>
<View
style={[
styles.slideCircle,
currentSlide === index && styles.slideSolidCircle,
]}
/>
</TouchableWithoutFeedback>
))}
</View>
)}
</View>
)}
</View>
Expand Down
15 changes: 13 additions & 2 deletions app/components/UI/WhatsNewModal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ interface SlideImage {
image: ImageSourcePropType;
}

interface SlideImages {
type: 'image';
images: {
light: ImageSourcePropType;
dark: ImageSourcePropType;
};
}

interface SlideTitle {
type: 'title';
title: string;
Expand All @@ -26,16 +34,19 @@ interface SlideButton {

type SlideContentType =
| SlideImage
| SlideImages
| SlideTitle
| SlideDescription
| SlideButton;

type WhatsNewSlides = SlideContentType[][];

type VersionString = `${number}.${number}.${number}`;

export interface WhatsNew {
onlyUpdates: boolean;
maxLastAppVersion: string;
minAppVersion: string;
maxLastAppVersion: VersionString;
minAppVersion: VersionString;
/**
* Slides utilizes a templating system in the form of a 2D array, which is eventually rendered within app/components/UI/WhatsNewModal/index.js.
* The root layer determines the number of slides. Ex. To display 3 slides, the root layer should contain 3 arrays.
Expand Down
38 changes: 33 additions & 5 deletions app/components/UI/WhatsNewModal/whatsNewList.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
/* eslint-disable import/prefer-default-export */
import Routes from '../../../constants/navigation/Routes';
import { strings } from '../../../../locales/i18n';
import { WhatsNew } from './types';

export const whatsNew: WhatsNew = {
// All users that have <1.0.7 and are updating to >=1.0.7 should see
onlyUpdates: true, // Only users who updated the app will see this, not newly installs
maxLastAppVersion: '1.0.7', // Only users who had a previous version <1.0.7 version will see this
minAppVersion: '1.0.7', // Only users who updated to a version >= 1.0.7 will see this
slides: [[], [], []],
// All users that have <5.3.0 and are updating to >=5.3.0 should see
onlyUpdates: false, // Only users who updated the app will see this, not newly installs
maxLastAppVersion: '5.3.0', // Only users who had a previous version <5.3.0 version will see this
minAppVersion: '5.3.0', // Only users who updated to a version >=5.3.0 will see this
slides: [
[
{
type: 'image',
/* eslint-disable import/no-commonjs, @typescript-eslint/no-require-imports */
images: {
light: require('../../../images/whats_new_onramp_agg_light.png'),
dark: require('../../../images/whats_new_onramp_agg_dark.png'),
},
},
{
type: 'title',
title: strings('whats_new.feature_on_ramp_title'),
},
{
type: 'description',
description: strings('whats_new.feature_on_ramp_text'),
},
{
type: 'button',
buttonType: 'blue',
buttonText: strings('whats_new.feature_on_ramp_button'),
onPress: ({ navigation }) =>
navigation.navigate(Routes.FIAT_ON_RAMP_AGGREGATOR.ID),
},
],
],
};
Binary file added app/images/whats_new_onramp_agg_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/whats_new_onramp_agg_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions locales/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1859,9 +1859,9 @@
},
"whats_new": {
"title": "See what's new",
"feature_security_settings_title": "Improved security settings",
"feature_security_settings_text": "You can now change your MetaMask app password & review how to backup your wallet Secret Recovery Phrase from Settings > Security & Privacy.",
"feature_security_settings_button": "View in Settings"
"feature_on_ramp_title": "Buy Crypto improvements",
"feature_on_ramp_text": "Our updated Buy Crypto feature aggregates quotes from multiple providers to help you find the best deal for your region and payment method.",
"feature_on_ramp_button": "Try it out"
},
"invalid_network": {
"title": "The chain ID for custom network \n %{network} \n has to be re-entered.",
Expand Down