-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce432c1
commit 6c4e377
Showing
8 changed files
with
292 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { View } from "react-native" | ||
import { Text, makeStyles, useTheme } from "@rneui/themed" | ||
import { useI18nContext } from "@app/i18n/i18n-react" | ||
import { GaloyIcon } from "../atomic/galoy-icon" | ||
import { useEffect, useState } from "react" | ||
import { DecemberChallengeModal } from "./modal" | ||
import { PressableCard } from "../pressable-card" | ||
|
||
import { JAN_1_2024_12_AM_UTC_MINUS_6, DEC_1_12_AM_UTC_MINUS_6 } from "./dates" | ||
|
||
function secondsToDDMMSS(totalSeconds: number) { | ||
if (totalSeconds < 0) return "" | ||
|
||
const days = Math.floor(totalSeconds / 86400) // There are 86400 seconds in a day | ||
const hours = Math.floor((totalSeconds - days * 86400) / 3600) // 3600 seconds in an hour | ||
const minutes = Math.floor((totalSeconds - days * 86400 - hours * 3600) / 60) | ||
const seconds = Math.floor(totalSeconds - days * 86400 - hours * 3600 - minutes * 60) | ||
|
||
const formattedDays = days.toString().padStart(2, "0") | ||
const formattedHours = hours.toString().padStart(2, "0") | ||
const formattedMinutes = minutes.toString().padStart(2, "0") | ||
const formattedSeconds = seconds.toString().padStart(2, "0") | ||
|
||
return `${formattedDays}:${formattedHours}:${formattedMinutes}:${formattedSeconds}` | ||
} | ||
|
||
const getTimeLeft = () => { | ||
const dateNow = Date.now() | ||
if (dateNow > JAN_1_2024_12_AM_UTC_MINUS_6 || dateNow < DEC_1_12_AM_UTC_MINUS_6) | ||
return "" | ||
|
||
const sLeft = (JAN_1_2024_12_AM_UTC_MINUS_6 - dateNow) / 1000 | ||
return secondsToDDMMSS(sLeft) | ||
} | ||
|
||
export const DecemberChallengeCard: React.FC = () => { | ||
const [modalIsOpen, setModalIsOpen] = useState(false) | ||
const openModal = () => setModalIsOpen(true) | ||
|
||
const { | ||
theme: { colors }, | ||
} = useTheme() | ||
const styles = useStyles() | ||
const { LL } = useI18nContext() | ||
|
||
const [countDown, setCountDown] = useState(getTimeLeft()) | ||
|
||
useEffect(() => { | ||
const dateNow = Date.now() | ||
if (dateNow > JAN_1_2024_12_AM_UTC_MINUS_6) return | ||
|
||
const t = setInterval(() => { | ||
setCountDown(getTimeLeft()) | ||
}, 1000) | ||
|
||
return () => clearInterval(t) | ||
}, [setCountDown]) | ||
|
||
const currentTime = Date.now() | ||
if (currentTime > JAN_1_2024_12_AM_UTC_MINUS_6 || currentTime < DEC_1_12_AM_UTC_MINUS_6) | ||
return <></> | ||
|
||
return ( | ||
<PressableCard onPress={openModal}> | ||
<DecemberChallengeModal isVisible={modalIsOpen} setIsVisible={setModalIsOpen} /> | ||
<View style={styles.card}> | ||
<View style={styles.textContainer}> | ||
<View style={styles.beside}> | ||
<Text type="p1" bold> | ||
{LL.Circles.decemberChallenge.title()} | ||
</Text> | ||
<Text color={colors.grey3}>{countDown}</Text> | ||
</View> | ||
<Text type="p2">{LL.Circles.decemberChallenge.description()}</Text> | ||
</View> | ||
<View> | ||
<GaloyIcon color={colors.primary} size={28} name="rank" /> | ||
</View> | ||
</View> | ||
</PressableCard> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles(({ colors }) => ({ | ||
card: { | ||
display: "flex", | ||
flexDirection: "row", | ||
justifyContent: "space-between", | ||
padding: 16, | ||
borderRadius: 10, | ||
backgroundColor: colors.grey5, | ||
}, | ||
textContainer: { | ||
flex: 1, | ||
display: "flex", | ||
flexDirection: "column", | ||
justifyContent: "center", | ||
rowGap: 6, | ||
}, | ||
beside: { | ||
display: "flex", | ||
flexDirection: "row", | ||
alignItems: "center", | ||
columnGap: 10, | ||
}, | ||
})) |
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,5 @@ | ||
export const DEC_1_12_AM_UTC_MINUS_6 = new Date(Date.UTC(2023, 11, 1, 6, 0, 0)).getTime() | ||
|
||
export const JAN_1_2024_12_AM_UTC_MINUS_6 = new Date( | ||
Date.UTC(2024, 0, 1, 6, 0, 0), | ||
).getTime() |
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,2 @@ | ||
export * from "./modal" | ||
export * from "./card" |
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,131 @@ | ||
import * as React from "react" | ||
import { Linking, View } from "react-native" | ||
import Modal from "react-native-modal" | ||
|
||
import { useI18nContext } from "@app/i18n/i18n-react" | ||
import { makeStyles, useTheme, Text } from "@rneui/themed" | ||
|
||
import { GaloyIconButton } from "../atomic/galoy-icon-button" | ||
import { GaloyToast } from "../galoy-toast" | ||
import { GaloyIcon } from "../atomic/galoy-icon" | ||
import { useCirclesCard } from "@app/screens/people-screen/circles/use-circles-card" | ||
import { GaloyPrimaryButton } from "../atomic/galoy-primary-button" | ||
|
||
const CHALLENGE_PAGE = "blink.sv/circles" | ||
const CHALLENGE_PAGE_URL = "https://www.blink.sv/circles" | ||
const SOCIAL_LINK_TREE = "https://linktr.ee/blinkbtc" | ||
|
||
type Props = { | ||
isVisible: boolean | ||
setIsVisible: (isVisible: boolean) => void | ||
} | ||
|
||
export const DecemberChallengeModal: React.FC<Props> = ({ isVisible, setIsVisible }) => { | ||
const { LL } = useI18nContext() | ||
|
||
const { | ||
theme: { colors }, | ||
} = useTheme() | ||
const styles = useStyles() | ||
|
||
const acknowledgeModal = () => { | ||
setIsVisible(false) | ||
} | ||
|
||
const { ShareImg, share } = useCirclesCard() | ||
|
||
return ( | ||
<Modal | ||
isVisible={isVisible} | ||
backdropOpacity={0.8} | ||
backdropTransitionOutTiming={0} | ||
backdropColor={colors.white} | ||
onBackdropPress={acknowledgeModal} | ||
> | ||
<View style={styles.modalCard}> | ||
<View style={styles.container}> | ||
<GaloyIconButton | ||
style={styles.cross} | ||
name="close" | ||
size="medium" | ||
onPress={acknowledgeModal} | ||
/> | ||
<GaloyIcon style={styles.top} name="rank" size={40} color={colors.primary} /> | ||
<Text type="h1" bold> | ||
{LL.Circles.decemberChallenge.title()} | ||
</Text> | ||
<Text type="p1" style={styles.details}> | ||
{LL.Circles.decemberChallenge.details()} | ||
</Text> | ||
{ShareImg} | ||
<GaloyPrimaryButton onPress={share} title={LL.Circles.shareCircles()} /> | ||
<Text style={styles.reminder} type="p3" color={colors.grey3}> | ||
{LL.Circles.octoberChallenge.connectOnSocial()} | ||
<Text | ||
style={styles.underline} | ||
color={colors.grey3} | ||
onPress={() => Linking.openURL(SOCIAL_LINK_TREE)} | ||
> | ||
{SOCIAL_LINK_TREE} | ||
</Text> | ||
</Text> | ||
<Text style={styles.reminder} type="p3"> | ||
{LL.Circles.octoberChallenge.fullDetails()} | ||
<Text | ||
style={styles.underline} | ||
color={colors.grey3} | ||
onPress={() => Linking.openURL(CHALLENGE_PAGE_URL)} | ||
> | ||
{CHALLENGE_PAGE} | ||
</Text> | ||
</Text> | ||
</View> | ||
</View> | ||
<GaloyToast /> | ||
</Modal> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles(({ colors }) => ({ | ||
container: { | ||
paddingHorizontal: 12, | ||
display: "flex", | ||
flexDirection: "column", | ||
rowGap: 20, | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}, | ||
cross: { | ||
position: "absolute", | ||
right: 20, | ||
top: -10, | ||
}, | ||
top: { marginTop: 40 }, | ||
modalCard: { | ||
backgroundColor: colors.grey5, | ||
borderRadius: 16, | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
paddingVertical: 30, | ||
}, | ||
details: { | ||
textAlign: "center", | ||
paddingHorizontal: 20, | ||
}, | ||
reminder: { | ||
textAlign: "center", | ||
paddingHorizontal: 20, | ||
color: colors.grey2, | ||
}, | ||
underline: { | ||
textDecorationLine: "underline", | ||
}, | ||
containerData: { | ||
display: "flex", | ||
flexDirection: "column", | ||
rowGap: 2, | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}, | ||
})) |
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