-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: news on welcome screen (#1132)
- Loading branch information
1 parent
6f0ef58
commit eb1bffb
Showing
10 changed files
with
219 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters