Skip to content

Commit

Permalink
Style wc error
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Nov 1, 2023
1 parent b88498e commit f741f38
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 deletions.
8 changes: 2 additions & 6 deletions src/components/walletconnect/WcErrorMessage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ const WcErrorMessage = ({ error, onClose }: { error: Error; onClose: () => void

return (
<div className={css.errorContainer}>
<WcLogoHeader error />
<WcLogoHeader errorMessage={summary} />

<Typography title={error.message} className={css.errorMessage} mb={3}>
{summary}
</Typography>

{details && <Typography variant="body2">{details}</Typography>}
{details && <Typography mt={1}>{details}</Typography>}

<Button variant="contained" onClick={onClose} className={css.button}>
OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
text-align: center;
}

.errorMessage {
overflow: hidden;
text-overflow: ellipsis;
width: 100%;
}

.button {
padding: var(--space-1) var(--space-4);
margin-top: var(--space-3);
}
8 changes: 4 additions & 4 deletions src/components/walletconnect/WcLogoHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import WalletConnect from '@/public/images/common/walletconnect.svg'
import Alert from '@/public/images/notifications/alert.svg'
import css from './styles.module.css'

const WcLogoHeader = ({ error }: { error?: boolean }): ReactElement => {
const WcLogoHeader = ({ errorMessage }: { errorMessage?: string }): ReactElement => {
return (
<>
<div>
<SvgIcon component={WalletConnect} inheritViewBox className={css.icon} />
{error && <SvgIcon component={Alert} inheritViewBox className={css.errorBadge} fontSize="small" />}
{errorMessage && <SvgIcon component={Alert} inheritViewBox className={css.errorBadge} fontSize="small" />}
</div>

<Typography variant="h5" mt={2} mb={0.5}>
Connect dApps to {`Safe{Wallet}`}
<Typography variant="h5" mt={2} mb={0.5} className={css.title}>
{errorMessage || 'Connect dApps to Safe{Wallet}'}
</Typography>
</>
)
Expand Down
6 changes: 6 additions & 0 deletions src/components/walletconnect/WcLogoHeader/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@
border-radius: 50%;
border: 1px solid var(--color-background-paper);
}

.title {
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
}
19 changes: 19 additions & 0 deletions src/services/walletconnect/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { splitError } from '../utils'

describe('WalletConnect utils', () => {
describe('splitError', () => {
it('should return the error summary and detail', () => {
const error = new Error('WalletConnect failed to switch chain: { session: "0x1234", chainId: 1 }')
const [summary, detail] = splitError(error.message)
expect(summary).toEqual('WalletConnect failed to switch chain')
expect(detail).toEqual('{ session: "0x1234", chainId: 1 }')
})

it('should return the error summary if no details', () => {
const error = new Error('WalletConnect failed to switch chain')
const [summary, detail] = splitError(error.message)
expect(summary).toEqual('WalletConnect failed to switch chain')
expect(detail).toBeUndefined()
})
})
})
2 changes: 1 addition & 1 deletion src/services/walletconnect/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ export const getPeerName = (peer: SessionTypes.Struct['peer'] | ProposalTypes.St
}

export const splitError = (message: string): string[] => {
return message.split(': ')
return message.split(/: (.+)/).slice(0, 2)
}

0 comments on commit f741f38

Please sign in to comment.