-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue-1068]: Add banner crowdloan unlock in Crowdloan tab
- Loading branch information
dominhquang
committed
Oct 19, 2023
1 parent
5d3867d
commit 86c0051
Showing
23 changed files
with
337 additions
and
44 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,14 @@ | ||
import { useMemo } from 'react'; | ||
|
||
import { RootState } from 'stores/index'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
const useGetBannerByScreen = (screen: string) => { | ||
const { banners } = useSelector((state: RootState) => state.campaign); | ||
|
||
return useMemo(() => { | ||
return banners.filter(item => item.data.position.includes(screen)); | ||
}, [banners, screen]); | ||
}; | ||
|
||
export default useGetBannerByScreen; |
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
103 changes: 103 additions & 0 deletions
103
src/screens/Home/Crowdloans/CampaignBannerModal/index.tsx
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,103 @@ | ||
import React, { useCallback, useRef } from 'react'; | ||
import { Button, Icon, SwModal } from 'components/design-system-ui'; | ||
import { useSubWalletTheme } from 'hooks/useSubWalletTheme'; | ||
import ModalStyle from './style'; | ||
import { Linking, View } from 'react-native'; | ||
import { ArrowCircleRight, XCircle } from 'phosphor-react-native'; | ||
import FastImage from 'react-native-fast-image'; | ||
import { InAppBrowser } from 'react-native-inappbrowser-reborn'; | ||
import { BrowserOptions } from 'utils/buy'; | ||
import { CampaignBanner, CampaignButton } from '@subwallet/extension-base/background/KoniTypes'; | ||
import { completeBannerCampaign } from 'messaging/index'; | ||
|
||
interface Props { | ||
visible: boolean; | ||
setVisible: (value: boolean) => void; | ||
banner: CampaignBanner; | ||
} | ||
|
||
export type ButtonSchema = 'primary' | 'secondary' | 'warning' | 'danger' | 'ghost'; | ||
|
||
enum ButtonIcon { | ||
// @ts-ignore | ||
xCircle = XCircle, | ||
// @ts-ignore | ||
arrowCircleRight = ArrowCircleRight, | ||
} | ||
|
||
const CampaignBannerModal = ({ visible, banner, setVisible }: Props) => { | ||
const theme = useSubWalletTheme().swThemes; | ||
const _style = ModalStyle(theme); | ||
const isOpenInAppBrowser = useRef(false); | ||
|
||
const onPressJoinNow = async (url?: string) => { | ||
if (url) { | ||
if (await InAppBrowser.isAvailable()) { | ||
isOpenInAppBrowser.current = true; | ||
await InAppBrowser.open(url, BrowserOptions); | ||
|
||
isOpenInAppBrowser.current = false; | ||
} else { | ||
Linking.openURL(url); | ||
} | ||
} | ||
}; | ||
|
||
const onCloseBanner = useCallback(() => { | ||
setVisible(false); | ||
completeBannerCampaign({ | ||
slug: banner.slug, | ||
}).catch(console.error); | ||
}, [banner.slug, setVisible]); | ||
|
||
const onPressBtn = (item: CampaignButton) => { | ||
return () => { | ||
if (item.type === 'open_url') { | ||
const url = item.metadata?.url as string | undefined; | ||
|
||
if (url) { | ||
onPressJoinNow(url); | ||
} | ||
} | ||
|
||
if (item.metadata?.doneOnClick) { | ||
onCloseBanner(); | ||
} | ||
}; | ||
}; | ||
|
||
return ( | ||
<SwModal | ||
isUseModalV2={true} | ||
setVisible={setVisible} | ||
modalVisible={visible} | ||
disabledOnPressBackDrop | ||
isAllowSwipeDown={false}> | ||
<View style={{ width: '100%' }}> | ||
<FastImage | ||
style={{ | ||
height: 144, | ||
borderRadius: theme.borderRadiusLG, | ||
marginBottom: theme.margin, | ||
}} | ||
resizeMode="cover" | ||
source={{ uri: banner.data.media }} | ||
/> | ||
|
||
<View style={_style.footerAreaStyle}> | ||
{banner.buttons.map(item => ( | ||
<Button | ||
type={item.color as ButtonSchema} | ||
style={{ flex: 1 }} | ||
onPress={onPressBtn(item)} | ||
icon={<Icon phosphorIcon={item.icon ? ButtonIcon[item.icon] : undefined} size={'lg'} weight={'fill'} />}> | ||
{item.name} | ||
</Button> | ||
))} | ||
</View> | ||
</View> | ||
</SwModal> | ||
); | ||
}; | ||
|
||
export default CampaignBannerModal; |
24 changes: 24 additions & 0 deletions
24
src/screens/Home/Crowdloans/CampaignBannerModal/style/index.ts
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,24 @@ | ||
import { StyleSheet, TextStyle, ViewStyle } from 'react-native'; | ||
import { ThemeTypes } from 'styles/themes'; | ||
import { FontMedium } from 'styles/sharedStyles'; | ||
|
||
export interface CreateMasterPasswordStyle { | ||
textStyle: TextStyle; | ||
footerAreaStyle: ViewStyle; | ||
} | ||
|
||
export default (theme: ThemeTypes) => | ||
StyleSheet.create<CreateMasterPasswordStyle>({ | ||
textStyle: { | ||
fontSize: theme.fontSize, | ||
lineHeight: theme.fontSize * theme.lineHeight, | ||
color: theme.colorTextLight4, | ||
textAlign: 'center', | ||
...FontMedium, | ||
}, | ||
|
||
footerAreaStyle: { | ||
flexDirection: 'row', | ||
gap: 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
Oops, something went wrong.