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

chore(pilot-app): update account instead of only pilot address #716

Merged
merged 3 commits into from
Jan 30, 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
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"TTFB",
"Uids",
"UNWRAPPER",
"vitalik",
"vercel",
"viem",
"vnet",
Expand Down
4 changes: 2 additions & 2 deletions deployables/app/app/components/wallet/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useAccountEffect } from 'wagmi'

export type OnConnectArgs = {
providerType: ProviderType
account: HexAddress
address: HexAddress
}

type ConnectProps = {
Expand All @@ -24,7 +24,7 @@ export const Connect = ({ onConnect }: ConnectProps) => {
}

onConnect({
account: address,
address,
providerType:
connector.type === 'injected'
? ProviderType.InjectedWallet
Expand Down
2 changes: 1 addition & 1 deletion deployables/app/app/components/wallet/ConnectWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const useAutoReconnect = ({
}

onConnectRef.current({
account: address,
address,
providerType:
connector.type === 'injected'
? ProviderType.InjectedWallet
Expand Down
22 changes: 15 additions & 7 deletions deployables/app/app/routes/edit-route.$data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
} from '@zodiac/form-data'
import { CompanionAppMessageType } from '@zodiac/messages'
import {
createAccount,
createEoaAccount,
getRolesVersion,
queryRolesV1MultiSend,
queryRolesV2MultiSend,
Expand All @@ -26,10 +28,10 @@ import {
updateAvatar,
updateChainId,
updateLabel,
updatePilotAddress,
updateProviderType,
updateRoleId,
updateRolesWaypoint,
updateStartingPoint,
zodiacModuleSchema,
type ZodiacModule,
} from '@zodiac/modules'
Expand Down Expand Up @@ -154,17 +156,23 @@ export const clientAction = async ({
case Intent.ConnectWallet: {
const route = parseRouteData(params.data)

const account = getHexString(data, 'account')
const address = getHexString(data, 'address')
const providerType = verifyProviderType(getInt(data, 'providerType'))
const account = await createAccount(
jsonRpcProvider(getChainId(route.avatar)),
address,
)

return editRoute(
updatePilotAddress(updateProviderType(route, providerType), account),
updateStartingPoint(updateProviderType(route, providerType), account),
)
}
case Intent.DisconnectWallet: {
const route = parseRouteData(params.data)

return editRoute(updatePilotAddress(route, ZERO_ADDRESS))
return editRoute(
updateStartingPoint(route, createEoaAccount({ address: ZERO_ADDRESS })),
)
}

default:
Expand Down Expand Up @@ -194,11 +202,11 @@ const EditRoute = ({
<ConnectWallet
chainId={chainId}
pilotAddress={optimisticRoute.pilotAddress}
onConnect={({ account, providerType }) => {
onConnect={({ address, providerType }) => {
submit(
formData({
intent: Intent.ConnectWallet,
account,
address,
providerType,
}),
{ method: 'POST' },
Expand Down Expand Up @@ -341,7 +349,7 @@ const useOptimisticRoute = () => {

case Intent.ConnectWallet: {
setOptimisticConnection({
pilotAddress: getHexString(formData, 'account'),
pilotAddress: getHexString(formData, 'address'),
})
}
}
Expand Down
34 changes: 34 additions & 0 deletions packages/modules/src/createAccount.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Chain } from '@zodiac/chains'
import { getDefaultProvider } from 'ethers'
import { AccountType, formatPrefixedAddress } from 'ser-kit'
import { describe, expect, it } from 'vitest'
import { createAccount } from './createAccount'

describe('createAccount', () => {
const ethProvider = getDefaultProvider(1)

it('creates an EAO account if the passed address does not have code', async () => {
const vitalikEoaAddress = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'

const account = await createAccount(ethProvider, vitalikEoaAddress)

expect(account).toEqual({
type: AccountType.EOA,
address: vitalikEoaAddress,
prefixedAddress: formatPrefixedAddress(undefined, vitalikEoaAddress),
})
})
it('creates a Safe account if the passed address has code', async () => {
const gnosisDaoTreasury = '0x849d52316331967b6ff1198e5e32a0eb168d039d'

const account = await createAccount(ethProvider, gnosisDaoTreasury)

expect(account).toEqual({
type: AccountType.SAFE,
address: gnosisDaoTreasury,
prefixedAddress: formatPrefixedAddress(Chain.ETH, gnosisDaoTreasury),
threshold: NaN,
chain: Chain.ETH,
})
})
})
22 changes: 22 additions & 0 deletions packages/modules/src/createAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { verifyChainId } from '@zodiac/chains'
import type { HexAddress } from '@zodiac/schema'
import type { Provider } from 'ethers'
import { createEoaAccount } from './createEoaAccount'
import { createSafeAccount } from './createSafeAccount'

export const createAccount = async (
provider: Provider,
address: HexAddress,
) => {
const isEoa = (await provider.getCode(address)) === '0x'
const network = await provider.getNetwork()

if (isEoa) {
return createEoaAccount({ address })
}

return createSafeAccount({
address,
chainId: verifyChainId(Number(network.chainId)),
})
}
4 changes: 3 additions & 1 deletion packages/modules/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export { createAccount } from './createAccount'
export { createBlankRoute } from './createBlankRoute'
export { createEoaAccount } from './createEoaAccount'
export { createEoaStartingPoint } from './createEoaStartingPoint'
export { fetchZodiacModules } from './fetchZodiacModules'
export { getPilotAddress } from './getPilotAddress'
Expand All @@ -16,10 +18,10 @@ export { decodeRoleKey, encodeRoleKey } from './roleKey'
export { updateAvatar } from './updateAvatar'
export { updateChainId } from './updateChainId'
export { updateLabel } from './updateLabel'
export { updatePilotAddress } from './updatePilotAddress'
export { updateProviderType } from './updateProviderType'
export { updateRoleId } from './updateRoleId'
export { updateRolesWaypoint } from './updateRolesWaypoint'
export { updateStartingPoint } from './updateStartingPoint'
export {
SUPPORTED_ZODIAC_MODULES,
SupportedZodiacModuleType,
Expand Down
123 changes: 0 additions & 123 deletions packages/modules/src/updatePilotAddress.spec.ts

This file was deleted.

46 changes: 0 additions & 46 deletions packages/modules/src/updatePilotAddress.ts

This file was deleted.

Loading
Loading