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

feat: news on welcome screen #1132

Merged
merged 1 commit into from
Jun 26, 2023
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
17 changes: 15 additions & 2 deletions .github/workflows/distribute-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ on:
type: choice
description: IS_DEVELOPMENT
options:
- 0
- 1
- false
- true

IS_SSS_ENABLED:
type: choice
description: IS_SSS_ENABLED
options:
- false
- true

IS_WELCOME_NEWS_ENABLED:
type: choice
description: IS_WELCOME_NEWS_ENABLED
options:
- false
- true

workflow_call:
inputs:
IS_DEVELOPMENT:
Expand All @@ -23,6 +32,9 @@ on:
IS_SSS_ENABLED:
required: true
type: string
IS_WELCOME_NEWS_ENABLED:
required: true
type: string

jobs:
build:
Expand Down Expand Up @@ -79,6 +91,7 @@ jobs:
echo "ADJUST_TOKEN=${{secrets.ADJUST_TOKEN}}" >> .env
echo "ADJUST_ENVIRONMENT=${{secrets.ADJUST_ENVIRONMENT}}" >> .env
echo "IS_SSS_ENABLED=${{github.event.inputs.IS_SSS_ENABLED}}" >> .env
echo "IS_WELCOME_NEWS_ENABLED=${{github.event.inputs.IS_WELCOME_NEWS_ENABLED}}" >> .env

- name: Install Fastlane
run: |
Expand Down
17 changes: 15 additions & 2 deletions .github/workflows/distribute-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ on:
type: choice
description: IS_DEVELOPMENT
options:
- 0
- 1
- false
- true

IS_SSS_ENABLED:
type: choice
description: IS_SSS_ENABLED
options:
- false
- true

IS_WELCOME_NEWS_ENABLED:
type: choice
description: IS_WELCOME_NEWS_ENABLED
options:
- false
- true

workflow_call:
inputs:
IS_DEVELOPMENT:
Expand All @@ -23,6 +32,9 @@ on:
IS_SSS_ENABLED:
required: true
type: string
IS_WELCOME_NEWS_ENABLED:
required: true
type: string

jobs:
build:
Expand Down Expand Up @@ -95,6 +107,7 @@ jobs:
echo "ADJUST_TOKEN=${{secrets.ADJUST_TOKEN}}" >> .env
echo "ADJUST_ENVIRONMENT=${{secrets.ADJUST_ENVIRONMENT}}" >> .env
echo "IS_SSS_ENABLED=${{github.event.inputs.IS_SSS_ENABLED}}" >> .env
echo "IS_WELCOME_NEWS_ENABLED=${{github.event.inputs.IS_WELCOME_NEWS_ENABLED}}" >> .env

- name: Execute build
run: |
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/distribute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ name: Distribute apps
on:
workflow_dispatch:
inputs:
IS_WELCOME_NEWS_ENABLED:
type: choice
description: IS_WELCOME_NEWS_ENABLED
options:
- false
- true

IS_SSS_ENABLED:
type: choice
description: IS_SSS_ENABLED
Expand Down Expand Up @@ -32,8 +39,9 @@ jobs:
uses: ./.github/workflows/distribute-android.yml
secrets: inherit
with:
IS_DEVELOPMENT: 0
IS_DEVELOPMENT: false
IS_SSS_ENABLED: ${{github.event.inputs.IS_SSS_ENABLED}}
IS_WELCOME_NEWS_ENABLED: ${{github.event.inputs.IS_WELCOME_NEWS_ENABLED}}
needs:
- test

Expand All @@ -43,8 +51,9 @@ jobs:
uses: ./.github/workflows/distribute-ios.yml
secrets: inherit
with:
IS_DEVELOPMENT: 0
IS_DEVELOPMENT: false
IS_SSS_ENABLED: ${{github.event.inputs.IS_SSS_ENABLED}}
IS_WELCOME_NEWS_ENABLED: ${{github.event.inputs.IS_WELCOME_NEWS_ENABLED}}
needs:
- test

Expand Down
15 changes: 14 additions & 1 deletion src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {StakingDelegateScreen} from '@app/screens/staking-delegate';
import {StakingInfoScreen} from '@app/screens/staking-info';
import {StakingUnDelegateScreen} from '@app/screens/staking-undelegate';
import {StakingValidatorsScreen} from '@app/screens/staking-validators';
import {WelcomeNewsScreen} from '@app/screens/welcome-news';
import {
ActionSheetType,
AppTheme,
Expand Down Expand Up @@ -295,6 +296,17 @@ export const App = () => {
});
}, []);

const initialRoute = useMemo(() => {
if (app.onboarded) {
return 'home';
}
if (app.isWelcomeNewsEnabled) {
return 'welcomeNews';
}

return 'welcome';
}, []);

// @ts-ignore
return (
<GestureHandlerRootView style={styles.rootView}>
Expand All @@ -307,9 +319,10 @@ export const App = () => {
<Stack.Navigator
screenOptions={basicScreenOptions}
key={theme}
initialRouteName={app.onboarded ? 'home' : 'welcome'}>
initialRouteName={initialRoute}>
<Stack.Screen name="home" component={HomeScreen} />
<Stack.Screen name="welcome" component={WelcomeScreen} />
<Stack.Screen name="welcomeNews" component={WelcomeNewsScreen} />
{/* Modals group */}
<Stack.Group screenOptions={stackScreenOptions}>
<Stack.Screen
Expand Down
79 changes: 79 additions & 0 deletions src/components/welcome-news.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from 'react';

import {FlatList, View} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import {Results} from 'realm';

import {Color} from '@app/colors';
import {NewsRow} from '@app/components/news/news-row';
import {Button, ButtonSize, ButtonVariant} from '@app/components/ui';
import {createTheme} from '@app/helpers';
import {I18N} from '@app/i18n';
import {News as NewsModel} from '@app/models/news';

type WelcomeProps = {
news: Results<NewsModel>;
onPress: (id: string) => void;
onPressSignup: () => void;
onPressLedger: () => void;
onPressSignIn: () => void;
};

export const WelcomeNews = ({
onPressSignup,
onPressLedger,
onPressSignIn,
news,
onPress,
}: WelcomeProps) => {
const insets = useSafeAreaInsets();

return (
<View
style={[
styles.container,
{paddingTop: insets.top, paddingBottom: insets.bottom},
]}>
<FlatList
data={news}
renderItem={({item}) => <NewsRow item={item} onPress={onPress} />}
/>

<Button
i18n={I18N.welcomeCreateWallet}
testID="welcome_signup"
style={styles.button}
variant={ButtonVariant.contained}
onPress={onPressSignup}
size={ButtonSize.large}
/>
<Button
testID="welcome_ledger"
i18n={I18N.welcomeLedgerWallet}
iconRight="ledger"
iconRightColor={Color.graphicGreen1}
style={styles.button}
variant={ButtonVariant.second}
onPress={onPressLedger}
size={ButtonSize.large}
/>
<Button
testID="welcome_signin"
i18n={I18N.welcomeRestoreWallet}
style={styles.button}
onPress={onPressSignIn}
size={ButtonSize.large}
/>
</View>
);
};

const styles = createTheme({
container: {
flex: 1,
marginHorizontal: 20,
},
button: {
marginBottom: 16,
},
});
21 changes: 20 additions & 1 deletion src/contexts/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {EventEmitter} from 'events';

import {ENVIRONMENT} from '@env';
import {ENVIRONMENT, IS_DEVELOPMENT, IS_WELCOME_NEWS_ENABLED} from '@env';
import {appleAuth} from '@invertase/react-native-apple-authentication';
import dynamicLinks from '@react-native-firebase/dynamic-links';
import {GoogleSignin} from '@react-native-google-signin/google-signin';
Expand Down Expand Up @@ -110,6 +110,17 @@ class App extends EventEmitter {

Appearance.addChangeListener(this.listenTheme);
AppState.addEventListener('change', this.listenTheme);

if (!VariablesBool.exists('isDeveloper')) {
VariablesBool.set('isDeveloper', IS_DEVELOPMENT === 'true');
}

if (!VariablesBool.exists('isWelcomeNewsEnabled')) {
VariablesBool.set(
'isWelcomeNewsEnabled',
IS_WELCOME_NEWS_ENABLED === 'true',
);
}
}

private _biometryType: BiometryType | null = null;
Expand Down Expand Up @@ -241,6 +252,14 @@ class App extends EventEmitter {
VariablesBool.set('isDeveloper', value);
}

get isWelcomeNewsEnabled() {
return VariablesBool.get('isWelcomeNewsEnabled') ?? false;
}

set isWelcomeNewsEnabled(value) {
VariablesBool.set('isWelcomeNewsEnabled', value);
}

get currentTheme() {
return this.theme === AppTheme.system
? this._systemTheme ?? AppTheme.light
Expand Down
1 change: 1 addition & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare module '@env' {
export const PATTERNS_SOURCE: string;
export const ENVIRONMENT: string;
export const IS_DEVELOPMENT: string;
export const IS_WELCOME_NEWS_ENABLED: string;
export const PUSH_NOTIFICATIONS_URL: string;
export const PROVIDER_BASE_PACKAGE: string;
export const WALLET_CONNECT_PROJECT_ID: string;
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/is-feature-enabled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum Feature {
earn,
governanceAndStaking,
nft,
abnews,
}

export const isFeatureEnabled = (feature: Feature): boolean => {
Expand All @@ -19,6 +20,8 @@ export const isFeatureEnabled = (feature: Feature): boolean => {
return app.isDeveloper;
case Feature.nft:
return app.isDeveloper;
case Feature.abnews:
return app.isWelcomeNewsEnabled;
default:
return false;
}
Expand Down
60 changes: 60 additions & 0 deletions src/screens/welcome-news.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, {useCallback, useEffect, useState} from 'react';

import {WelcomeNews} from '@app/components/welcome-news';
import {onNewsSync} from '@app/event-actions/on-news-sync';
import {useTypedNavigation} from '@app/hooks';
import {News} from '@app/models/news';
import {VariablesBool} from '@app/models/variables-bool';
import {PushNotifications} from '@app/services/push-notifications';

export const WelcomeNewsScreen = () => {
const navigation = useTypedNavigation();

const [news, setNews] = useState(
News.getAll().filtered('status = "published"').sorted('publishedAt', true),
);

useEffect(() => {
if (!VariablesBool.exists('notifications')) {
PushNotifications.instance
.requestPermissions()
.then(() => {
VariablesBool.set('notifications', true);
})
.catch(() => {
VariablesBool.set('notifications', false);
});
}

onNewsSync().then(() => {
setNews(
News.getAll()
.filtered('status = "published"')
.sorted('publishedAt', true),
);
});
}, []);

const onPressSignup = () => navigation.navigate('signup', {next: 'create'});
const onPressLedger = () => navigation.navigate('ledger');
const onPressSignIn = () => navigation.navigate('signin', {next: 'restore'});

const onPressRow = useCallback(
(id: string) => {
navigation.navigate('newsDetail', {
id,
});
},
[navigation],
);

return (
<WelcomeNews
onPressSignup={onPressSignup}
onPressLedger={onPressLedger}
onPressSignIn={onPressSignIn}
news={news}
onPress={onPressRow}
/>
);
};
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export type RootStackParamList = {
accountId: string;
};
welcome: undefined;
welcomeNews: undefined;
create: undefined;
scanQr: undefined;
signin: {next: string};
Expand Down
Loading