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

feat(pilot-app): show v2 roles config in companion app #536

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions deployables/app/app/components/ZodiacMod.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
decodeRoleKey,
SupportedZodiacModuleType,
ZODIAC_MODULE_NAMES,
type ZodiacModule,
Expand Down Expand Up @@ -151,6 +152,14 @@ export const ZodiacMod = ({
placeholder="0"
/>
)}

{selectedModule?.type === SupportedZodiacModuleType.ROLES_V2 && (
<TextInput
label="Role Key"
defaultValue={getRoleKey(waypoints) ?? ''}
placeholder="Enter key as bytes32 hex string or in human-readable decoding"
/>
)}
</>
)
}
Expand Down Expand Up @@ -179,6 +188,16 @@ const getRoleId = (waypoints?: Waypoints) => {
return moduleWaypoint.connection.roles[0]
}

const getRoleKey = (waypoints?: Waypoints) => {
const roleId = getRoleId(waypoints)

if (roleId == null) {
return null
}

return decodeRoleKey(roleId)
}

const getModuleWaypoint = (waypoints?: Waypoints) => {
if (waypoints == null) {
return null
Expand Down
41 changes: 40 additions & 1 deletion deployables/app/app/routes/edit-route.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { render } from '@/test-utils'
import { screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { Chain, CHAIN_NAME } from '@zodiac/chains'
import { fetchZodiacModules, SupportedZodiacModuleType } from '@zodiac/modules'
import {
encodeRoleKey,
fetchZodiacModules,
SupportedZodiacModuleType,
} from '@zodiac/modules'
import type { initSafeApiKit } from '@zodiac/safe'
import { ProviderType } from '@zodiac/schema'
import {
Expand Down Expand Up @@ -227,5 +231,40 @@ describe('Edit route', () => {
roleId,
)
})

it('shows the v2 role config when the v2 route mod is used', async () => {
const moduleAddress = randomAddress()

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

const route = createMockExecutionRoute({
avatar: formatPrefixedAddress(
Chain.ETH,
'0x58e6c7ab55Aa9012eAccA16d1ED4c15795669E1C',
),
waypoints: [
createStartingWaypoint(),
createRoleWaypoint({
moduleAddress,
roleId: encodeRoleKey('TEST-KEY'),
version: 2,
}),
],
providerType: ProviderType.InjectedWallet,
})

await render('/edit-route', {
searchParams: { route: btoa(JSON.stringify(route)) },
})

expect(screen.getByRole('textbox', { name: 'Role Key' })).toHaveValue(
'TEST-KEY',
)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ import {
import { useDisconnectWalletConnectIfNeeded } from '@/providers'
import { useTransactions } from '@/state'
import type { HexAddress, LegacyConnection } from '@/types'
import {
decodeRoleKey,
encodeRoleKey,
formData,
getInt,
getOptionalString,
getString,
} from '@/utils'
import { formData, getInt, getOptionalString, getString } from '@/utils'
import {
fetchZodiacModules,
queryRolesV1MultiSend,
Expand All @@ -25,6 +18,7 @@ import {
} from '@/zodiac'
import { invariantResponse } from '@epic-web/invariant'
import { EOA_ZERO_ADDRESS } from '@zodiac/chains'
import { decodeRoleKey, encodeRoleKey } from '@zodiac/modules'
import {
Breadcrumbs,
Error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import type {
} from '@/types'
import {
decodeGenericError,
decodeRoleKey,
decodeRolesV1Error,
decodeRolesV2Error,
isSmartContractAddress,
validateAddress,
} from '@/utils'
import { SupportedZodiacModuleType } from '@zodiac/modules'
import { decodeRoleKey, SupportedZodiacModuleType } from '@zodiac/modules'
import { useEffect, useState } from 'react'
import { asLegacyConnection } from '../../legacyConnectionMigrations'
import { wrapRequest } from './wrapRequest'
Expand Down
1 change: 0 additions & 1 deletion deployables/extension/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export { injectScript } from './injectScript'
export { isValidTab } from './isValidTab'
export { reloadActiveTab } from './reloadActiveTab'
export { reloadTab } from './reloadTab'
export * from './roleKey'
export { sendMessageToTab } from './sendMessageToTab'
export { shortenAddress } from './shortenAddress'
export { sleep } from './sleep'
1 change: 1 addition & 0 deletions packages/modules/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { fetchZodiacModules } from './fetchZodiacModules'
export { decodeRoleKey, encodeRoleKey } from './roleKey'
export {
SUPPORTED_ZODIAC_MODULES,
SupportedZodiacModuleType,
Expand Down
Loading