Skip to content

Commit

Permalink
connection moduleType migration: roles -> roles_v1
Browse files Browse the repository at this point in the history
  • Loading branch information
jfschwarz committed Feb 12, 2024
1 parent c193044 commit 9d6ec5b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
11 changes: 11 additions & 0 deletions extension/src/connections/connectionHooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@ const CONNECTION_STATE_MIGRATIONS: ConnectionStateMigration[] = [
pilotAddress: connection.pilotAddress.toLowerCase(),
}
},

function renameRolesV1ModuleType(connection) {
// moduleType: 'roles' -> 'roles_v1' rename
return {
...connection,
moduleType:
connection.moduleType === ('roles' as unknown)
? KnownContracts.ROLES_V1
: connection.moduleType,
}
},
]

// Apply all migrations to the given connections
Expand Down
46 changes: 27 additions & 19 deletions extension/src/providers/WrappingProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { MetaTransaction } from 'react-multisend'
import { initSafeApiKit, sendTransaction } from '../safe'
import { Connection, Eip1193Provider, TransactionData } from '../types'

const RolesInterface =
const RolesV1Interface =
ContractFactories[KnownContracts.ROLES_V1].createInterface()
const RolesV2Interface =
ContractFactories[KnownContracts.ROLES_V2].createInterface()
const DelayInterface = ContractFactories[KnownContracts.DELAY].createInterface()

export function wrapRequest(
Expand All @@ -20,24 +22,30 @@ export function wrapRequest(
}

let data: string
if (connection.moduleType === KnownContracts.ROLES_V1) {
data = RolesInterface.encodeFunctionData('execTransactionWithRole', [
request.to || '',
request.value || 0,
request.data || '0x00',
('operation' in request && request.operation) || 0,
connection.roleId || 0,
true,
])
} else if (connection.moduleType === KnownContracts.DELAY) {
data = DelayInterface.encodeFunctionData('execTransactionFromModule', [
request.to || '',
request.value || 0,
request.data || '0x00',
('operation' in request && request.operation) || 0,
])
} else {
throw new Error(`Unsupported module type: ${connection.moduleType}`)
switch (connection.moduleType) {
case KnownContracts.ROLES_V1:
data = RolesV1Interface.encodeFunctionData('execTransactionWithRole', [
request.to || '',
request.value || 0,
request.data || '0x00',
('operation' in request && request.operation) || 0,
connection.roleId || 0,
true,
])
break
case KnownContracts.ROLES_V2:
// TODO
break
case KnownContracts.DELAY:
data = DelayInterface.encodeFunctionData('execTransactionFromModule', [
request.to || '',
request.value || 0,
request.data || '0x00',
('operation' in request && request.operation) || 0,
])
break
default:
throw new Error(`Unsupported module type: ${connection.moduleType}`)
}

return {
Expand Down

0 comments on commit 9d6ec5b

Please sign in to comment.