Skip to content

Commit

Permalink
Merge pull request #124 from gnosisguild/fix-connection-migration
Browse files Browse the repository at this point in the history
fix issues in connection migration
  • Loading branch information
jfschwarz authored Jul 25, 2024
2 parents 35255c9 + 2114e7e commit ecd14de
Show file tree
Hide file tree
Showing 19 changed files with 315 additions and 190 deletions.
100 changes: 50 additions & 50 deletions extension/.pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
33 changes: 22 additions & 11 deletions extension/src/routes/RoutesDrawer/ConnectButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import metamaskLogoUrl from './metamask-logo.svg'
import classes from './style.module.css'
import walletConnectLogoUrl from './wallet-connect-logo.png'
import { ChainId, parsePrefixedAddress } from 'ser-kit'
import {
asLegacyConnection,
fromLegacyConnection,
} from '../../legacyConnectionMigrations'

const walletConnectLogo = (
<img src={PUBLIC_PATH + walletConnectLogoUrl} alt="wallet connect logo" />
Expand All @@ -28,7 +32,7 @@ const metamaskLogo = (
)

const ConnectButton: React.FC<{ id: string }> = ({ id }) => {
const [connections, setConnections] = useRoutes()
const [routes, setRoutes] = useRoutes()
const { connected, route, chainId } = useRoute(id)
const pilotAddress =
route.initiator && parsePrefixedAddress(route.initiator)[1].toLowerCase()
Expand All @@ -41,16 +45,16 @@ const ConnectButton: React.FC<{ id: string }> = ({ id }) => {
chainId: ChainId,
account: string
) => {
setConnections(
connections.map((c) =>
c.id === id
? {
...route,
setRoutes(
routes.map((r) =>
r.id === id
? fromLegacyConnection({
...asLegacyConnection(r),
providerType,
chainId,
pilotAddress: account.toLowerCase(),
}
: c
pilotAddress: account,
})
: r
)
)
}
Expand All @@ -63,8 +67,15 @@ const ConnectButton: React.FC<{ id: string }> = ({ id }) => {
walletConnect.disconnect()
}

setConnections(
connections.map((c) => (c.id === id ? { ...route, pilotAddress: '' } : c))
setRoutes(
routes.map((r) =>
r.id === id
? fromLegacyConnection({
...asLegacyConnection(route),
pilotAddress: '',
})
: r
)
)
}

Expand Down
15 changes: 8 additions & 7 deletions extension/src/routes/RoutesDrawer/Edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
asLegacyConnection,
fromLegacyConnection,
} from '../../legacyConnectionMigrations'
import { ZeroAddress } from 'ethers'

interface Props {
connectionId: string
Expand Down Expand Up @@ -107,11 +108,10 @@ const EditConnection: React.FC<Props> = ({ connectionId, onLaunched }) => {

const updateConnection = (patch: ConnectionPatch) => {
setRoutes((routes) =>
routes.map((r) =>
r.id === route.id
? fromLegacyConnection({ ...asLegacyConnection(r), ...patch })!
: r
)
routes.map((r) => {
if (r.id !== route.id) return r
return fromLegacyConnection({ ...asLegacyConnection(r), ...patch })
})
)
}

Expand Down Expand Up @@ -219,16 +219,17 @@ const EditConnection: React.FC<Props> = ({ connectionId, onLaunched }) => {
<Field label="Piloted Safe" labelFor="">
<AvatarInput
availableSafes={safes}
value={avatarAddress}
value={avatarAddress === ZeroAddress ? '' : avatarAddress || ''}
onChange={async (address) => {
const keepTransactionBundle =
address.toLowerCase() ===
connection.avatarAddress.toLowerCase()
const confirmed =
keepTransactionBundle || (await confirmClearTransactions())

if (confirmed) {
updateConnection({
avatarAddress: address,
avatarAddress: address || undefined,
moduleAddress: '',
moduleType: undefined,
})
Expand Down
Loading

0 comments on commit ecd14de

Please sign in to comment.