Skip to content

Commit

Permalink
fix: clear module when switching piloted account (#463)
Browse files Browse the repository at this point in the history
* fix: make sure to clear the module input when the pilot address changes

* chore: create some test utils
  • Loading branch information
frontendphil authored Jan 6, 2025
1 parent 57352e6 commit 14bf6d9
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
import { useInjectedWallet } from '@/providers'
import {
createMockRoute,
createRoleWaypoint,
createStartingWaypoint,
createTransaction,
expectRouteToBe,
MockProvider,
Expand Down Expand Up @@ -171,7 +173,7 @@ describe('Edit Zodiac route', () => {

describe('Piloted Safe', () => {
it('is possible to define a safe', async () => {
mockRoute({ id: 'route-id' })
await mockRoute({ id: 'route-id' })

await render('/routes/edit/route-id', [
{
Expand All @@ -197,6 +199,40 @@ describe('Edit Zodiac route', () => {
formatPrefixedAddress(1, address).toLowerCase(),
)
})

it('clears the module when the piloted safe changes', async () => {
const moduleAddress = randomAddress()

await mockRoute({
id: 'route-id',
avatar: randomPrefixedAddress(),
waypoints: [
createStartingWaypoint(),
createRoleWaypoint({ moduleAddress }),
],
})

mockFetchZodiacModules.mockResolvedValue([
{ moduleAddress, type: KnownContracts.ROLES_V2 },
])

mockQueryRolesV2MultiSend.mockResolvedValue({})

await render('/routes/edit/route-id', [
{
path: '/routes/edit/:routeId',
Component: EditRoute,
loader,
action,
},
])

await userEvent.click(
screen.getByRole('button', { name: 'Clear piloted Safe' }),
)

expect(screen.queryByText('Roles v2')).not.toBeInTheDocument()
})
})

describe('Zodiac modules', () => {
Expand Down
4 changes: 3 additions & 1 deletion extension/src/panel/pages/routes/edit.$routeId/ZodiacMod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ export const ZodiacMod = ({
value: value.moduleAddress,
label: MODULE_NAMES[value.moduleType],
}
: defaultModOption
: defaultModOption != null
? defaultModOption
: null
}
isDisabled={disabled}
placeholder="Select a module"
Expand Down
30 changes: 30 additions & 0 deletions extension/test-utils/creators/createRoleWaypoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { HexAddress } from '@/types'
import {
AccountType,
ConnectionType,
formatPrefixedAddress,
type Waypoint,
} from 'ser-kit'
import { randomAddress, randomPrefixedAddress } from './randomHex'

type CreateRoleWaypointOptions = {
moduleAddress?: HexAddress
}

export const createRoleWaypoint = ({
moduleAddress = randomAddress(),
}: CreateRoleWaypointOptions = {}): Waypoint => ({
account: {
type: AccountType.ROLES,
address: moduleAddress,
prefixedAddress: formatPrefixedAddress(1, moduleAddress),
chain: 1,
multisend: [],
version: 2,
},
connection: {
from: randomPrefixedAddress(),
type: ConnectionType.IS_MEMBER,
roles: [],
},
})
14 changes: 14 additions & 0 deletions extension/test-utils/creators/createStartingWaypoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { AccountType, type StartingPoint } from 'ser-kit'
import { randomAddress, randomPrefixedAddress } from './randomHex'

export const createStartingWaypoint = ({
account,
}: Partial<StartingPoint> = {}): StartingPoint => ({
account: {
address: randomAddress(),
prefixedAddress: randomPrefixedAddress(),
type: AccountType.EOA,

...account,
},
})
2 changes: 2 additions & 0 deletions extension/test-utils/creators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ export { createMockRoute } from './createMockRoute'
export { createMockTab } from './createMockTab'
export type { MockTab } from './createMockTab'
export { createMockWebRequest } from './createMockWebRequest'
export { createRoleWaypoint } from './createRoleWaypoint'
export { createStartingWaypoint } from './createStartingWaypoint'
export { createTransaction } from './createTransaction'
export { randomAddress, randomPrefixedAddress } from './randomHex'

0 comments on commit 14bf6d9

Please sign in to comment.