-
Notifications
You must be signed in to change notification settings - Fork 505
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 #1356 from blockscout/marketplace-improvements
Marketplace improvements
- Loading branch information
Showing
53 changed files
with
1,215 additions
and
149 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.
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
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,81 @@ | ||
import { Heading, Modal, ModalBody, ModalContent, ModalFooter, ModalHeader, ModalOverlay, Text, Button, useColorModeValue } from '@chakra-ui/react'; | ||
import NextLink from 'next/link'; | ||
import React from 'react'; | ||
|
||
import useIsMobile from 'lib/hooks/useIsMobile'; | ||
|
||
type Props = { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
appId: string; | ||
} | ||
|
||
const MarketplaceDisclaimerModal = ({ isOpen, onClose, appId }: Props) => { | ||
|
||
const isMobile = useIsMobile(); | ||
|
||
const handleContinueClick = React.useCallback(() => { | ||
window.localStorage.setItem('marketplace-disclaimer-shown', 'true'); | ||
}, [ ]); | ||
|
||
return ( | ||
<Modal | ||
isOpen={ isOpen } | ||
onClose={ onClose } | ||
size={ isMobile ? 'full' : 'md' } | ||
isCentered | ||
> | ||
<ModalOverlay/> | ||
|
||
<ModalContent> | ||
<ModalHeader> | ||
<Heading | ||
as="h2" | ||
fontSize="2xl" | ||
fontWeight="medium" | ||
lineHeight={ 1 } | ||
color={ useColorModeValue('blackAlpha.800', 'whiteAlpha.800') } | ||
> | ||
Disclaimer | ||
</Heading> | ||
</ModalHeader> | ||
|
||
<ModalBody> | ||
<Text color={ useColorModeValue('gray.800', 'whiteAlpha.800') }> | ||
You are now accessing a third-party app. Blockscout does not own, control, maintain, or audit 3rd party apps,{ ' ' } | ||
and is not liable for any losses associated with these interactions. Please do so at your own risk. | ||
<br/><br/> | ||
By clicking continue, you agree that you understand the risks and have read the Disclaimer. | ||
</Text> | ||
</ModalBody> | ||
|
||
<ModalFooter | ||
display="flex" | ||
flexDirection="row" | ||
alignItems="center" | ||
> | ||
<NextLink href={{ pathname: '/apps/[id]', query: { id: appId } }} passHref legacyBehavior> | ||
<Button | ||
variant="solid" | ||
colorScheme="blue" | ||
mr={ 6 } | ||
py="10px" | ||
onClick={ handleContinueClick } | ||
> | ||
Continue to app | ||
</Button> | ||
</NextLink> | ||
<Button | ||
variant="outline" | ||
colorScheme="blue" | ||
onClick={ onClose } | ||
> | ||
Cancel | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default MarketplaceDisclaimerModal; |
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,64 @@ | ||
import type { TypedData } from 'abitype'; | ||
import { useCallback } from 'react'; | ||
import type { Account, SignTypedDataParameters } from 'viem'; | ||
import { useAccount, useSendTransaction, useSwitchNetwork, useNetwork, useSignMessage, useSignTypedData } from 'wagmi'; | ||
|
||
import config from 'configs/app'; | ||
|
||
type SendTransactionArgs = { | ||
chainId?: number; | ||
mode?: 'prepared'; | ||
to: string; | ||
}; | ||
|
||
export type SignTypedDataArgs< | ||
TTypedData extends | ||
| TypedData | ||
| { | ||
[key: string]: unknown; | ||
} = TypedData, | ||
TPrimaryType extends string = string, | ||
> = SignTypedDataParameters<TTypedData, TPrimaryType, Account>; | ||
|
||
export default function useMarketplaceWallet() { | ||
const { address } = useAccount(); | ||
const { chain } = useNetwork(); | ||
const { sendTransactionAsync } = useSendTransaction(); | ||
const { signMessageAsync } = useSignMessage(); | ||
const { signTypedDataAsync } = useSignTypedData(); | ||
const { switchNetworkAsync } = useSwitchNetwork({ chainId: Number(config.chain.id) }); | ||
|
||
const switchNetwork = useCallback(async() => { | ||
if (Number(config.chain.id) !== chain?.id) { | ||
await switchNetworkAsync?.(); | ||
} | ||
}, [ chain, switchNetworkAsync ]); | ||
|
||
const sendTransaction = useCallback(async(transaction: SendTransactionArgs) => { | ||
await switchNetwork(); | ||
const tx = await sendTransactionAsync(transaction); | ||
return tx.hash; | ||
}, [ sendTransactionAsync, switchNetwork ]); | ||
|
||
const signMessage = useCallback(async(message: string) => { | ||
await switchNetwork(); | ||
const signature = await signMessageAsync({ message }); | ||
return signature; | ||
}, [ signMessageAsync, switchNetwork ]); | ||
|
||
const signTypedData = useCallback(async(typedData: SignTypedDataArgs) => { | ||
await switchNetwork(); | ||
if (typedData.domain) { | ||
typedData.domain.chainId = Number(typedData.domain.chainId); | ||
} | ||
const signature = await signTypedDataAsync(typedData); | ||
return signature; | ||
}, [ signTypedDataAsync, switchNetwork ]); | ||
|
||
return { | ||
address, | ||
sendTransaction, | ||
signMessage, | ||
signTypedData, | ||
}; | ||
} |
Oops, something went wrong.