forked from ava-labs/core-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: link to Core Webs Halliday flow from Bridge (ava-labs#118)
- Loading branch information
Showing
8 changed files
with
143 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { | ||
Card, | ||
CardActionArea, | ||
Grow, | ||
IconButton, | ||
Link, | ||
Stack, | ||
Typography, | ||
XIcon, | ||
} from '@avalabs/core-k2-components'; | ||
|
||
import { getCoreWebUrl } from '@src/utils/getCoreWebUrl'; | ||
import { useDismissedBanners } from '@src/hooks/useDismissedBanners'; | ||
import { useFeatureFlagContext } from '@src/contexts/FeatureFlagsProvider'; | ||
import { FeatureGates } from '@src/background/services/featureFlags/models'; | ||
|
||
const HALLIDAY_BANNER_ID = 'halliday-e2d6f109-2175-4303-9321-17b010781371'; | ||
|
||
export const HallidayBanner = () => { | ||
const { t } = useTranslation(); | ||
|
||
const [isOpen, setIsOpen] = useState(false); | ||
const { isDismissed, dismiss } = useDismissedBanners(); | ||
const { isFlagEnabled } = useFeatureFlagContext(); | ||
|
||
useEffect(() => { | ||
if (!isFlagEnabled(FeatureGates.HALLIDAY_BRIDGE_BANNER)) { | ||
setIsOpen(false); | ||
return; | ||
} | ||
|
||
let isMounted = true; | ||
|
||
isDismissed(HALLIDAY_BANNER_ID).then((isHallidayDismissed) => { | ||
if (!isMounted) { | ||
return; | ||
} | ||
|
||
setIsOpen(!isHallidayDismissed); | ||
}); | ||
|
||
return () => { | ||
isMounted = false; | ||
}; | ||
}, [isDismissed, isFlagEnabled]); | ||
|
||
return ( | ||
<Grow in={isOpen} unmountOnExit mountOnEnter> | ||
<Card sx={{ mx: 2, mb: 2, position: 'relative' }}> | ||
<IconButton | ||
size="small" | ||
sx={{ position: 'absolute', top: 4, right: 4, zIndex: 9999 }} | ||
onClick={() => { | ||
setIsOpen(false); | ||
dismiss(HALLIDAY_BANNER_ID); | ||
}} | ||
> | ||
<XIcon size={20} /> | ||
</IconButton> | ||
<CardActionArea | ||
component={Link} | ||
href={`${getCoreWebUrl()}/bridge?useHalliday=1`} | ||
rel="noopener noreferrer" | ||
target="_blank" | ||
> | ||
<Stack sx={{ gap: 1, py: 1, px: 2 }}> | ||
<Stack sx={{ flexDirection: 'row', gap: 1, alignItems: 'center' }}> | ||
<img | ||
src="/images/halliday-icon.png" | ||
style={{ height: 24 }} | ||
alt="Halliday Logo" | ||
/> | ||
<Typography variant="button" sx={{ fontSize: 'body2.fontSize' }}> | ||
{t('Bridge using Halliday')} | ||
</Typography> | ||
</Stack> | ||
<Typography | ||
variant="caption" | ||
sx={{ color: 'text.secondary', lineHeight: 1.5 }} | ||
> | ||
{t( | ||
'Buy and bridge USD and other currencies directly to L1s using Halliday.', | ||
)} | ||
</Typography> | ||
</Stack> | ||
</CardActionArea> | ||
</Card> | ||
</Grow> | ||
); | ||
}; |
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,25 @@ | ||
import { useLocalStorage } from './useLocalStorage'; | ||
|
||
const DISMISSED_BANNERS_STORAGE_KEY = 'dismissed-banners'; | ||
|
||
export const useDismissedBanners = () => { | ||
const { get, set } = useLocalStorage(); | ||
|
||
return { | ||
async isDismissed(bannerId: string) { | ||
const dismissedBanners = await get(DISMISSED_BANNERS_STORAGE_KEY); | ||
|
||
return dismissedBanners && Array.isArray(dismissedBanners) | ||
? dismissedBanners.includes(bannerId) | ||
: false; | ||
}, | ||
async dismiss(bannerId: string) { | ||
const alreadyDismissedBanners = await get(DISMISSED_BANNERS_STORAGE_KEY); | ||
const newDismissedBanners = alreadyDismissedBanners | ||
? [...alreadyDismissedBanners, bannerId] | ||
: [bannerId]; | ||
|
||
return set(DISMISSED_BANNERS_STORAGE_KEY, newDismissedBanners); | ||
}, | ||
}; | ||
}; |
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 { storage } from 'webextension-polyfill'; | ||
|
||
export const useLocalStorage = () => { | ||
return { | ||
async get(key: string) { | ||
const stored = await storage.local.get(key); | ||
|
||
return stored[key]; | ||
}, | ||
async set(key: string, value: any) { | ||
return storage.local.set({ [key]: value }); | ||
}, | ||
}; | ||
}; |
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