-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: unsupported chain disconnection feedback (#2664)
* feat: unsupported chain disconnection feedback * refactor: create useDeferredListener hook
- Loading branch information
Showing
8 changed files
with
172 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { SvgIcon, Typography } from '@mui/material' | ||
import classNames from 'classnames' | ||
import type { ReactElement } from 'react' | ||
import type { CoreTypes } from '@walletconnect/types' | ||
|
||
import SafeAppIconCard from '@/components/safe-apps/SafeAppIconCard' | ||
import SafeLogo from '@/public/images/logo-no-text.svg' | ||
import ConnectionDots from '@/public/images/common/connection-dots.svg' | ||
import { useCurrentChain } from '@/hooks/useChains' | ||
|
||
import css from './styles.module.css' | ||
|
||
export const ConnectionBanner = ({ | ||
metadata, | ||
isDelete = false, | ||
}: { | ||
metadata?: CoreTypes.Metadata | ||
isDelete?: boolean | ||
}): ReactElement | null => { | ||
const chain = useCurrentChain() | ||
|
||
if (!metadata) { | ||
return null | ||
} | ||
|
||
const name = metadata.name || 'dApp' | ||
const icon = metadata.icons[0] || '' | ||
|
||
return ( | ||
<div className={css.container}> | ||
<div> | ||
<SafeLogo alt="Safe logo" width="28px" height="28px" /> | ||
<SvgIcon | ||
component={ConnectionDots} | ||
inheritViewBox | ||
sx={{ mx: 2 }} | ||
className={classNames({ [css.errorDots]: isDelete })} | ||
/> | ||
<SafeAppIconCard src={icon} width={28} height={28} alt={`${name} logo`} /> | ||
</div> | ||
<Typography variant="h5" mt={3}> | ||
{isDelete | ||
? `${name} was disconnected as it does not support ${chain?.chainName || 'this network'}.` | ||
: `${name} successfully connected!`} | ||
</Typography> | ||
</div> | ||
) | ||
} |
21 changes: 21 additions & 0 deletions
21
src/components/walletconnect/ConnectionBanner/styles.module.css
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 @@ | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
text-align: center; | ||
padding-top: var(--space-2); | ||
} | ||
|
||
.errorDots circle:first-of-type, | ||
.errorDots circle:last-of-type { | ||
fill: var(--color-error-dark); | ||
} | ||
|
||
.errorDots circle:nth-of-type(2), | ||
.errorDots circle:nth-of-type(5) { | ||
fill: var(--color-error-main); | ||
} | ||
.errorDots circle:nth-of-type(3), | ||
.errorDots circle:nth-of-type(4) { | ||
fill: var(--color-error-light); | ||
} |
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useState, useEffect } from 'react' | ||
import type { Dispatch, SetStateAction } from 'react' | ||
|
||
export const useDeferredListener = <T>({ | ||
listener, | ||
cb, | ||
ms, | ||
}: { | ||
listener?: (handler: (e: T) => void) => () => void | ||
cb?: () => void | ||
ms: number | ||
}): [T | undefined, Dispatch<SetStateAction<T | undefined>>] => { | ||
const [value, setValue] = useState<T>() | ||
|
||
useEffect(() => { | ||
if (!listener) { | ||
return | ||
} | ||
|
||
const unsubscribe = listener((newValue) => { | ||
setValue(newValue) | ||
cb?.() | ||
}) | ||
|
||
const timeout = setTimeout(() => { | ||
setValue(undefined) | ||
}, ms) | ||
|
||
return () => { | ||
unsubscribe() | ||
clearTimeout(timeout) | ||
} | ||
}, [cb, listener, ms]) | ||
|
||
return [value, setValue] | ||
} |
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