Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Safe Creation color issues #1204

Merged
merged 3 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/create-safe/InfoWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ const InfoWidget = ({ title, steps, variant, startExpanded = false }: InfoWidget
}

return (
<Card sx={{ backgroundColor: ({ palette }) => palette[variant]?.background }}>
<Card
sx={{
backgroundColor: ({ palette }) => palette[variant]?.background,
borderColor: ({ palette }) => palette[variant]?.main,
borderWidth: 1,
}}
>
<CardHeader
className={css.cardHeader}
title={
Expand Down
11 changes: 9 additions & 2 deletions src/components/new-safe/CardStepper/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { useState } from 'react'
import { Box } from '@mui/system'
import css from './styles.module.css'
import { Card, LinearProgress, CardHeader, Avatar, Typography, CardContent } from '@mui/material'
import type { TxStepperProps } from './useCardStepper'
import { useCardStepper } from './useCardStepper'

export function CardStepper<StepperData>(props: TxStepperProps<StepperData>) {
const [progressColor, setProgressColor] = useState('static.primary')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest we add a type to this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried using keyof Palette which would allow values like primary etc. but it seems Mui doesn't provide a type for the dot syntax. I will add a comment as a research task for the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As these are static values used only in one place. What do you think about importing the colour directly instead of extending the palette?

const { activeStep, onSubmit, onBack, stepData, setStep } = useCardStepper<StepperData>(props)
const { steps } = props
const currentStep = steps[activeStep]
const progress = ((activeStep + 1) / steps.length) * 100

return (
<Card className={css.card}>
<LinearProgress color="secondary" variant="determinate" value={Math.min(progress, 100)} />
<Box className={css.progress} color={progressColor}>
<LinearProgress color="inherit" variant="determinate" value={Math.min(progress, 100)} />
</Box>
{currentStep.title && (
<CardHeader
title={currentStep.title}
Expand All @@ -26,7 +31,9 @@ export function CardStepper<StepperData>(props: TxStepperProps<StepperData>) {
className={css.header}
/>
)}
<CardContent className={css.content}>{currentStep.render(stepData, onSubmit, onBack, setStep)}</CardContent>
<CardContent className={css.content}>
{currentStep.render(stepData, onSubmit, onBack, setStep, setProgressColor)}
</CardContent>
</Card>
)
}
4 changes: 4 additions & 0 deletions src/components/new-safe/CardStepper/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
padding: var(--space-3) 52px;
}

.progress :global .MuiLinearProgress-root::before {
display: none;
}

@media (max-width: 600px) {
.header {
padding: var(--space-2);
Expand Down
4 changes: 3 additions & 1 deletion src/components/new-safe/CardStepper/useCardStepper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ReactElement, SetStateAction } from 'react'
import type { Dispatch, ReactElement, SetStateAction } from 'react'
import { useState } from 'react'
import { trackEvent, MODALS_CATEGORY } from '@/services/analytics'

Expand All @@ -7,6 +7,7 @@ export type StepRenderProps<TData> = {
onSubmit: (data: Partial<TData>) => void
onBack: (data?: Partial<TData>) => void
setStep: (step: number) => void
setProgressColor?: Dispatch<SetStateAction<string>>
}

export type Step<TData> = {
Expand All @@ -17,6 +18,7 @@ export type Step<TData> = {
onSubmit: StepRenderProps<TData>['onSubmit'],
onBack: StepRenderProps<TData>['onBack'],
setStep: StepRenderProps<TData>['setStep'],
setProgressColor: StepRenderProps<TData>['setProgressColor'],
) => ReactElement
}

Expand Down
10 changes: 8 additions & 2 deletions src/components/new-safe/CreateSafe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,14 @@ const CreateSafe = () => {
{
title: '',
subtitle: '',
render: (data, onSubmit, onBack, setStep) => (
<CreateSafeStatus data={data} onSubmit={onSubmit} onBack={onBack} setStep={setStep} />
render: (data, onSubmit, onBack, setStep, setProgressColor) => (
<CreateSafeStatus
data={data}
onSubmit={onSubmit}
onBack={onBack}
setStep={setStep}
setProgressColor={setProgressColor}
/>
),
},
]
Expand Down
3 changes: 2 additions & 1 deletion src/components/new-safe/OverviewWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useCurrentChain } from '@/hooks/useChains'
import useWallet from '@/hooks/wallets/useWallet'
import { Card, Grid, Typography } from '@mui/material'
import type { ReactElement } from 'react'
import SafeLogo from '@/public/images/logo-no-text.svg'

import css from './styles.module.css'

Expand All @@ -22,7 +23,7 @@ const OverviewWidget = ({ safeName }: { safeName: string }): ReactElement | null
<Grid item xs={12}>
<Card className={css.card}>
<div className={css.header}>
<img src="/images/logo-no-text.svg" alt="Safe logo" width={LOGO_DIMENSIONS} />
<SafeLogo alt="Safe logo" width={LOGO_DIMENSIONS} height={LOGO_DIMENSIONS} />
<Typography variant="h4">Your Safe preview</Typography>
</div>
{rows?.map((row) => (
Expand Down
10 changes: 9 additions & 1 deletion src/components/new-safe/steps/Step3/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,15 @@ const CreateSafeStep3 = ({ data, onSubmit, onBack, setStep }: StepRenderProps<Ne
name="Est. network fee"
value={
<>
<Box p={1} sx={{ backgroundColor: 'secondary.background', width: 'fit-content' }}>
<Box
p={1}
sx={{
backgroundColor: 'static.light',
color: 'static.main',
width: 'fit-content',
borderRadius: '6px',
}}
>
<Typography variant="body1">
<b>
&asymp; {totalFee} {chain?.nativeCurrency.symbol}
Expand Down
12 changes: 10 additions & 2 deletions src/components/new-safe/steps/Step4/StatusMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ const getStep = (status: SafeCreationStatus) => {
}
}

const StatusMessage = ({ status }: { status: SafeCreationStatus }) => {
const StatusMessage = ({ status, isError }: { status: SafeCreationStatus; isError: boolean }) => {
const stepInfo = getStep(status)

const color = isError ? 'success' : 'warning'

return (
<>
<Box paddingX={3} mt={3}>
Expand All @@ -68,7 +70,13 @@ const StatusMessage = ({ status }: { status: SafeCreationStatus }) => {
</Box>
{stepInfo.instruction && (
<Box
sx={({ palette }) => ({ backgroundColor: palette.warning.background, borderRadius: '6px' })}
sx={({ palette }) => ({
backgroundColor: palette[color].background,
borderColor: palette[color].light,
borderWidth: 1,
borderStyle: 'solid',
borderRadius: '6px',
})}
padding={3}
mt={4}
mb={0}
Expand Down
28 changes: 19 additions & 9 deletions src/components/new-safe/steps/Step4/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useState } from 'react'
import { Box, Button, Divider, Grid, Paper, Tooltip, Typography } from '@mui/material'
import { useCallback, useEffect, useState } from 'react'
import { Box, Button, Divider, Paper, Tooltip, Typography } from '@mui/material'
import { useRouter } from 'next/router'

import Track from '@/components/common/Track'
Expand Down Expand Up @@ -29,7 +29,7 @@ export type PendingSafeData = NewSafeFormData & {
saltNonce: number
}

export const CreateSafeStatus = ({ setStep }: StepRenderProps<NewSafeFormData>) => {
export const CreateSafeStatus = ({ setProgressColor }: StepRenderProps<NewSafeFormData>) => {
const [status, setStatus] = useState<SafeCreationStatus>(SafeCreationStatus.AWAITING)
const [pendingSafe, setPendingSafe] = useLocalStorage<PendingSafeData | undefined>(SAFE_PENDING_CREATION_STORAGE_KEY)
const router = useRouter()
Expand Down Expand Up @@ -69,7 +69,17 @@ export const CreateSafeStatus = ({ setStep }: StepRenderProps<NewSafeFormData>)
}, [chainId, pendingSafe, router, setPendingSafe])

const displaySafeLink = status >= SafeCreationStatus.INDEXED
const displayActions = status >= SafeCreationStatus.WALLET_REJECTED && status <= SafeCreationStatus.TIMEOUT
const isError = status >= SafeCreationStatus.WALLET_REJECTED && status <= SafeCreationStatus.TIMEOUT

useEffect(() => {
if (!setProgressColor) return

if (isError) {
setProgressColor('error.main')
} else {
setProgressColor('static.primary')
}
}, [isError, setProgressColor])

return (
<Paper
Expand All @@ -78,10 +88,10 @@ export const CreateSafeStatus = ({ setStep }: StepRenderProps<NewSafeFormData>)
}}
>
<Box className={layoutCss.row}>
<StatusMessage status={status} />
<StatusMessage status={status} isError={isError} />
</Box>

{!displayActions && pendingSafe && (
{!isError && pendingSafe && (
<>
<Divider />
<Box className={layoutCss.row}>
Expand All @@ -103,11 +113,11 @@ export const CreateSafeStatus = ({ setStep }: StepRenderProps<NewSafeFormData>)
</>
)}

{displayActions && (
{isError && (
<>
<Divider />
<Box className={layoutCss.row}>
<Grid container justifyContent="center" gap={2}>
<Box display="flex" flexDirection="row" justifyContent="space-between" gap={3}>
<Track {...CREATE_SAFE_EVENTS.CANCEL_CREATE_SAFE}>
<Button onClick={onClose} variant="outlined">
Cancel
Expand All @@ -124,7 +134,7 @@ export const CreateSafeStatus = ({ setStep }: StepRenderProps<NewSafeFormData>)
</Typography>
</Tooltip>
</Track>
</Grid>
</Box>
</Box>
</>
)}
Expand Down
2 changes: 2 additions & 0 deletions src/styles/colors-dark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const darkPalette = {
},
static: {
main: '#121312',
primary: '#12FF80',
light: '#EFFFF4',
},
}
export default darkPalette
2 changes: 2 additions & 0 deletions src/styles/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const palette = {
},
static: {
main: '#121312',
primary: '#12FF80',
light: '#EFFFF4',
},
}
export default palette