Skip to content

Commit

Permalink
fix(pilot-app): make sure to not accidetally remove eoa account (#572)
Browse files Browse the repository at this point in the history
* make sure to not accidetally remove eoa account

* do not open wcm all th etime

* do not send multiple connect requests

* thought i committed this already

* fix address comparison
  • Loading branch information
frontendphil authored Jan 17, 2025
1 parent 3f2ba07 commit 95b4850
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 11 deletions.
6 changes: 5 additions & 1 deletion deployables/app/app/components/wallet/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ type ConnectProps = {

export const Connect = ({ onConnect }: ConnectProps) => {
useAccountEffect({
onConnect({ address, chainId, connector }) {
onConnect({ address, chainId, connector, isReconnected }) {
if (isReconnected) {
return
}

onConnect({
account: address,
chainId: verifyChainId(chainId),
Expand Down
2 changes: 1 addition & 1 deletion deployables/app/app/components/wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const Wallet = ({
}

const accountInWallet = addresses.some(
(address) => address.toLowerCase() === pilotAddress,
(address) => address.toLowerCase() === pilotAddress.toLowerCase(),
)

// Wrong account
Expand Down
5 changes: 4 additions & 1 deletion deployables/app/app/components/wallet/WalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const wagmiConfig = createConfig(
connectors: [
injected(),
metaMask(),
walletConnect({ projectId: WALLETCONNECT_PROJECT_ID }),
walletConnect({
projectId: WALLETCONNECT_PROJECT_ID,
showQrModal: false,
}),
],
}),
)
Expand Down
2 changes: 2 additions & 0 deletions deployables/app/app/routes/edit-route.$data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export const clientAction = async ({
const chainId = verifyChainId(getInt(data, 'chainId'))
const providerType = verifyProviderType(getInt(data, 'providerType'))

console.log({ account, chainId, providerType })

return editRoute(
request.url,
updatePilotAddress(
Expand Down
4 changes: 2 additions & 2 deletions packages/modules/src/updateConnection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getChainId, type ChainId } from '@zodiac/chains'
import { type ChainId } from '@zodiac/chains'
import type { Connection, HexAddress } from '@zodiac/schema'
import { parsePrefixedAddress } from 'ser-kit'
import { updatePrefixedAddress } from './updatePrefixedAddress'
Expand All @@ -12,7 +12,7 @@ export const updateConnection = <T extends Connection>(
connection: T,
{
from = parsePrefixedAddress(connection.from),
chainId = getChainId(connection.from),
chainId,
}: UpdateConnectionOptions,
): T => ({
...connection,
Expand Down
33 changes: 31 additions & 2 deletions packages/modules/src/updatePilotAddress.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
createMockExecutionRoute,
createMockOwnsConnection,
createMockRoleWaypoint,
createMockSafeAccount,
createMockStartingWaypoint,
createMockWaypoints,
randomAddress,
} from '@zodiac/test-utils'
Expand Down Expand Up @@ -43,7 +45,7 @@ describe('updatePilotAddress', () => {

expect(updatedRoute).toHaveProperty(
'initiator',
formatPrefixedAddress(Chain.ETH, newAddress),
formatPrefixedAddress(undefined, newAddress),
)
})

Expand All @@ -56,7 +58,10 @@ describe('updatePilotAddress', () => {
],
])('it updates the connection for "%s" waypoints', (_, waypoint) => {
const route = createMockExecutionRoute({
waypoints: createMockWaypoints({ waypoints: [waypoint] }),
waypoints: createMockWaypoints({
start: createMockStartingWaypoint(createMockSafeAccount()),
waypoints: [waypoint],
}),
})

const newAddress = randomAddress()
Expand Down Expand Up @@ -94,4 +99,28 @@ describe('updatePilotAddress', () => {
roleWaypoint.account.prefixedAddress,
)
})

describe('EOA', () => {
it('handles EOA addresses in the safe endpoint', () => {
const route = createMockExecutionRoute({
waypoints: createMockWaypoints({
end: createMockEndWaypoint({
connection: createMockOwnsConnection(
formatPrefixedAddress(undefined, randomAddress()),
),
}),
}),
})

const address = randomAddress()

const updatedRoute = updatePilotAddress(route, address)
const [endPoint] = getWaypoints(updatedRoute)

expect(endPoint.connection).toHaveProperty(
'from',
formatPrefixedAddress(undefined, address),
)
})
})
})
5 changes: 4 additions & 1 deletion packages/modules/src/updatePilotAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export const updatePilotAddress = (
address: HexAddress,
): ExecutionRoute => {
const startingPoint = getStartingWaypoint(route.waypoints)
const chainId = getChainId(route.avatar)
const chainId =
startingPoint.account.type === AccountType.EOA
? undefined
: getChainId(route.avatar)
const waypoints = getWaypoints(route)

return {
Expand Down
14 changes: 11 additions & 3 deletions packages/modules/src/updatePrefixedAddress.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getChainId } from '@zodiac/chains'
import type { HexAddress } from '@zodiac/schema'
import {
formatPrefixedAddress,
parsePrefixedAddress,
splitPrefixedAddress,
type ChainId,
type PrefixedAddress,
} from 'ser-kit'
Expand All @@ -15,7 +15,15 @@ type UpdatePrefixedAddressOptions = {
export const updatePrefixedAddress = (
prefixedAddress: PrefixedAddress,
{
chainId = getChainId(prefixedAddress),
chainId,
address = parsePrefixedAddress(prefixedAddress),
}: UpdatePrefixedAddressOptions,
) => formatPrefixedAddress(chainId, address)
) => {
if (chainId != null) {
return formatPrefixedAddress(chainId, address)
}

const [defaultChainId] = splitPrefixedAddress(prefixedAddress)

return formatPrefixedAddress(defaultChainId, address)
}

0 comments on commit 95b4850

Please sign in to comment.