-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1469 from blockscout/fe-1439
add hype provider
- Loading branch information
Showing
10 changed files
with
113 additions
and
5 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
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,55 @@ | ||
import { Flex, chakra } from '@chakra-ui/react'; | ||
import { Banner, setWalletAddresses } from '@hypelab/sdk-react'; | ||
import Script from 'next/script'; | ||
import React from 'react'; | ||
import { useAccount } from 'wagmi'; | ||
|
||
import Web3ModalProvider from '../Web3ModalProvider'; | ||
import { hypeInit } from './hypeBannerScript'; | ||
|
||
const DESKTOP_BANNER_SLUG = 'b1559fc3e7'; | ||
const MOBILE_BANNER_SLUG = '668ed80a9e'; | ||
|
||
const HypeBannerContent = ({ className }: { className?: string }) => { | ||
|
||
return ( | ||
<> | ||
<Script | ||
id="hypelab" | ||
strategy="afterInteractive" | ||
>{ hypeInit }</Script> | ||
<Flex className={ className } h="90px" display={{ base: 'none', lg: 'flex' }}> | ||
<Banner placement={ DESKTOP_BANNER_SLUG }/> | ||
</Flex> | ||
<Flex className={ className } h="50px" display={{ base: 'flex', lg: 'none' }}> | ||
<Banner placement={ MOBILE_BANNER_SLUG }/> | ||
</Flex> | ||
</> | ||
); | ||
}; | ||
|
||
const HypeBannerWithWalletAddress = ({ className }: { className?: string }) => { | ||
const { address } = useAccount(); | ||
React.useEffect(() => { | ||
if (address) { | ||
setWalletAddresses([ address ]); | ||
} | ||
}, [ address ]); | ||
|
||
return <HypeBannerContent className={ className }/>; | ||
}; | ||
|
||
const HypeBanner = ({ className }: { className?: string }) => { | ||
|
||
const fallback = React.useCallback(() => { | ||
return <HypeBannerContent className={ className }/>; | ||
}, [ className ]); | ||
|
||
return ( | ||
<Web3ModalProvider fallback={ fallback }> | ||
<HypeBannerWithWalletAddress className={ className }/> | ||
</Web3ModalProvider> | ||
); | ||
}; | ||
|
||
export default chakra(HypeBanner); |
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,21 @@ | ||
import config from 'configs/app'; | ||
|
||
const PRODUCTION_PROPERTY_SLUG = '127fddd522'; | ||
const HYPE_API_URL = 'https://api.hypelab.com'; | ||
|
||
export const hypeInit = (() => { | ||
const feature = config.features.adsBanner; | ||
|
||
if (!feature.isEnabled || feature.provider !== 'hype') { | ||
return; | ||
} | ||
|
||
return `!(function (h, y, p, e, l, a, b) { | ||
((l = document.createElement(h)).async = !0), | ||
(l.src = y), | ||
(l.onload = function () { | ||
(a = { URL: p, propertySlug: e, environment: 'production' }), HypeLab.initialize(a); | ||
}), | ||
(b = document.getElementsByTagName(h)[0]).parentNode.insertBefore(l, b); | ||
})('script', 'https://api.hypelab.com/v1/scripts/hp-sdk.js?v=0', '${ HYPE_API_URL }', '${ PRODUCTION_PROPERTY_SLUG }');`; | ||
})(); |
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