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 upgrade): preserve fallback handler + show queue warning only for <1.3.0 #4708

Merged
merged 4 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
}

.gridContainer.conflictGroup {
grid-template-columns: var(--grid-type) var(--grid-info) var(--grid-date) var(--grid-confirmations) var(--grid-status) var(
--grid-actions
);
grid-template-columns:
var(--grid-type) var(--grid-info) var(--grid-date) var(--grid-confirmations) var(--grid-status)
var(--grid-actions);
grid-template-areas: 'type info date confirmations status actions';
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'
import { _UpdateSafe as UpdateSafe } from './index'
import { render } from '@/tests/test-utils'

const chain = {
recommendedMasterCopyVersion: '1.4.1',
} as ChainInfo

const warningText = 'This upgrade will invalidate all queued transactions!'

describe('Container', () => {
it('renders correctly with a queue warning', async () => {
const container = render(<UpdateSafe safeVersion="1.1.1" queueSize="10+" chain={chain} />)
await expect(container.findByText(warningText)).resolves.not.toBeNull()
})

it('renders correctly without a queue warning because no queue', async () => {
const container = render(<UpdateSafe safeVersion="1.1.1" queueSize="" chain={chain} />)
await expect(container.findByText(warningText)).rejects.toThrowError(Error)
})

it('renders correctly without a queue warning because of compatible Safe version', async () => {
const container = render(<UpdateSafe safeVersion="1.3.0" queueSize="10" chain={chain} />)
await expect(container.findByText(warningText)).rejects.toThrowError(Error)
})
})
37 changes: 29 additions & 8 deletions apps/web/src/components/tx/confirmation-views/UpdateSafe/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import type { ReactNode } from 'react'
import { Alert, AlertTitle, Box, Divider, Stack, Typography } from '@mui/material'
import semverSatisfies from 'semver/functions/satisfies'
import { LATEST_SAFE_VERSION } from '@/config/constants'
import { useCurrentChain } from '@/hooks/useChains'
import useSafeInfo from '@/hooks/useSafeInfo'
import { useQueuedTxsLength } from '@/hooks/useTxQueue'
import ExternalLink from '@/components/common/ExternalLink'
import { maybePlural } from '@/utils/formatters'
import madProps from '@/utils/mad-props'

const QUEUE_WARNING_VERSION = '<1.3.0'

function BgBox({ children, light }: { children: ReactNode; light?: boolean }) {
return (
Expand All @@ -23,38 +27,55 @@ function BgBox({ children, light }: { children: ReactNode; light?: boolean }) {
)
}

function UpdateSafe() {
const { safe } = useSafeInfo()
const chain = useCurrentChain()
const queueSize = useQueuedTxsLength()
export function _UpdateSafe({
safeVersion,
queueSize,
chain,
}: {
safeVersion: string
queueSize: string
chain: ReturnType<typeof useCurrentChain>
}) {
const showQueueWarning = queueSize && semverSatisfies(safeVersion, QUEUE_WARNING_VERSION)
const latestSafeVersion = chain?.recommendedMasterCopyVersion || LATEST_SAFE_VERSION

return (
<>
<Stack direction="row" alignItems="center" spacing={2}>
<BgBox>Current version: {safe.version}</BgBox>
<BgBox>Current version: {safeVersion}</BgBox>
<Box fontSize={28}>→</Box>
<BgBox light>New version: {latestSafeVersion}</BgBox>
</Stack>

<Typography mb={1}>
<Typography>
Read about the updates in the new Safe contracts version in the{' '}
<ExternalLink href={`https://github.com/safe-global/safe-contracts/releases/tag/v${latestSafeVersion}`}>
version {latestSafeVersion} changelog
</ExternalLink>
</Typography>

{queueSize && (
{showQueueWarning && (
<Alert severity="warning">
<AlertTitle sx={{ fontWeight: 700 }}>This upgrade will invalidate all queued transactions!</AlertTitle>
You have {queueSize} unexecuted transaction{maybePlural(parseInt(queueSize))}. Please make sure to execute or
delete them before upgrading, otherwise you&apos;ll have to reject or replace them after the upgrade.
</Alert>
)}

<Divider sx={{ mt: 1, mx: -3 }} />
<Divider sx={{ my: 1, mx: -3 }} />
</>
)
}

function useSafeVersion() {
const { safe } = useSafeInfo()
return safe?.version || ''
}

const UpdateSafe = madProps(_UpdateSafe, {
chain: useCurrentChain,
safeVersion: useSafeVersion,
queueSize: useQueuedTxsLength,
})

export default UpdateSafe
Loading