-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update wallet connection alert component
- Loading branch information
1 parent
038d631
commit fd7159e
Showing
15 changed files
with
183 additions
and
164 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
93 changes: 93 additions & 0 deletions
93
dapp/src/components/ConnectWalletModal/ConnectWalletAlert.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,93 @@ | ||
import React from "react" | ||
import { Box, Link, VStack } from "@chakra-ui/react" | ||
import { AnimatePresence, Variants, motion } from "framer-motion" | ||
import { EXTERNAL_HREF } from "#/constants" | ||
import { | ||
Alert, | ||
AlertDescription, | ||
AlertTitle, | ||
AlertIcon, | ||
AlertProps, | ||
} from "../shared/Alert" | ||
|
||
export enum ConnectionAlert { | ||
Rejected = "REJECTED", | ||
NotSupported = "NOT_SUPPORTED", | ||
NetworkMismatch = "NETWORK_MISMATCH", | ||
InvalidSIWWSignature = "INVALID_SIWW_SIGNATURE", | ||
Default = "DEFAULT", | ||
} | ||
|
||
const CONNECTION_ALERTS = { | ||
[ConnectionAlert.Rejected]: { | ||
title: "Wallet connection rejected.", | ||
description: "If you encountered an error, please try again.", | ||
}, | ||
[ConnectionAlert.NotSupported]: { | ||
title: "Not supported.", | ||
description: | ||
"Only Native SegWit, Nested SegWit or Legacy addresses supported at this time. Please try a different address or another wallet.", | ||
}, | ||
[ConnectionAlert.NetworkMismatch]: { | ||
title: "Error!", | ||
description: | ||
"Incorrect network detected in your wallet. Please choose proper network and try again.", | ||
}, | ||
[ConnectionAlert.Default]: { | ||
title: "Wallet connection error. Please try again.", | ||
description: ( | ||
<Box as="span"> | ||
If the problem persists, contact{" "} | ||
<Link | ||
color="#0E61FE" | ||
textDecoration="underline" | ||
href={EXTERNAL_HREF.DISCORD} | ||
isExternal | ||
> | ||
Acre support | ||
</Link> | ||
</Box> | ||
), | ||
}, | ||
[ConnectionAlert.InvalidSIWWSignature]: { | ||
title: "Invalid Sign In With Wallet signature", | ||
description: "We encountered an error. Please try again.", | ||
}, | ||
} | ||
|
||
const collapseVariants: Variants = { | ||
collapsed: { height: 0 }, | ||
expanded: { height: "auto" }, | ||
} | ||
|
||
type ConnectWalletAlertProps = AlertProps & { type?: ConnectionAlert } | ||
|
||
export default function ConnectWalletAlert(props: ConnectWalletAlertProps) { | ||
const { type, ...restProps } = props | ||
|
||
const data = type ? CONNECTION_ALERTS[type] : undefined | ||
|
||
return ( | ||
<AnimatePresence initial={false}> | ||
{data && ( | ||
<Box | ||
as={motion.div} | ||
variants={collapseVariants} | ||
initial="collapsed" | ||
animate="expanded" | ||
exit="collapsed" | ||
overflow="hidden" | ||
w="full" | ||
> | ||
<Alert status="error" mb={6} {...restProps}> | ||
<AlertIcon /> | ||
<VStack w="full" align="start" spacing={0}> | ||
<AlertTitle textAlign="start">{data.title}</AlertTitle> | ||
<AlertDescription>{data.description}</AlertDescription> | ||
</VStack> | ||
</Alert> | ||
</Box> | ||
)} | ||
</AnimatePresence> | ||
) | ||
} |
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
50 changes: 0 additions & 50 deletions
50
dapp/src/components/ConnectWalletModal/ConnectWalletErrorAlert.tsx
This file was deleted.
Oops, something went wrong.
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,54 @@ | ||
import { ConnectionAlert } from "#/components/ConnectWalletModal/ConnectWalletAlert" | ||
import { AlertStatus } from "@chakra-ui/react" | ||
import React, { createContext, useCallback, useMemo, useState } from "react" | ||
|
||
type WalletConnectionAlertContextValue = { | ||
type?: ConnectionAlert | ||
status: AlertStatus | ||
setConnectionAlert: (type: ConnectionAlert, status?: AlertStatus) => void | ||
resetConnectionAlert: () => void | ||
} | ||
|
||
export const WalletConnectionAlertContext = | ||
createContext<WalletConnectionAlertContextValue>( | ||
{} as WalletConnectionAlertContextValue, | ||
) | ||
|
||
export function WalletConnectionAlertContextProvider({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}): React.ReactElement { | ||
const [type, setType] = useState<ConnectionAlert>() | ||
const [status, setStatus] = useState<AlertStatus>("error") | ||
|
||
const resetConnectionAlert = useCallback(() => { | ||
setType(undefined) | ||
setStatus("error") | ||
}, [setType]) | ||
|
||
const setConnectionAlert = useCallback( | ||
(connectionAlert: ConnectionAlert, alertStatus: AlertStatus = "error") => { | ||
setType(connectionAlert) | ||
setStatus(alertStatus) | ||
}, | ||
[setType], | ||
) | ||
|
||
const contextValue: WalletConnectionAlertContextValue = | ||
useMemo<WalletConnectionAlertContextValue>( | ||
() => ({ | ||
type, | ||
status, | ||
setConnectionAlert, | ||
resetConnectionAlert, | ||
}), | ||
[resetConnectionAlert, setConnectionAlert, status, type], | ||
) | ||
|
||
return ( | ||
<WalletConnectionAlertContext.Provider value={contextValue}> | ||
{children} | ||
</WalletConnectionAlertContext.Provider> | ||
) | ||
} |
Oops, something went wrong.