Skip to content

Commit

Permalink
fix: store owner and Safe name in addressBook on all chosen networks (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
schmanu authored Oct 7, 2024
1 parent 150013a commit fcaa83e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 37 deletions.
38 changes: 20 additions & 18 deletions src/components/new-safe/create/logic/address-book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { defaultSafeInfo } from '@/store/safeInfoSlice'
import type { NamedAddress } from '@/components/new-safe/create/types'

export const updateAddressBook = (
chainId: string,
chainIds: string[],
address: string,
name: string,
owners: NamedAddress[],
Expand All @@ -14,7 +14,7 @@ export const updateAddressBook = (
return (dispatch) => {
dispatch(
upsertAddressBookEntries({
chainIds: [chainId],
chainIds,
address,
name,
}),
Expand All @@ -23,24 +23,26 @@ export const updateAddressBook = (
owners.forEach((owner) => {
const entryName = owner.name || owner.ens
if (entryName) {
dispatch(upsertAddressBookEntries({ chainIds: [chainId], address: owner.address, name: entryName }))
dispatch(upsertAddressBookEntries({ chainIds, address: owner.address, name: entryName }))
}
})

dispatch(
addOrUpdateSafe({
safe: {
...defaultSafeInfo,
address: { value: address, name },
threshold,
owners: owners.map((owner) => ({
value: owner.address,
name: owner.name || owner.ens,
})),
chainId,
nonce: 0,
},
}),
)
chainIds.forEach((chainId) => {
dispatch(
addOrUpdateSafe({
safe: {
...defaultSafeInfo,
address: { value: address, name },
threshold,
owners: owners.map((owner) => ({
value: owner.address,
name: owner.name || owner.ens,
})),
chainId,
nonce: 0,
},
}),
)
})
}
}
12 changes: 12 additions & 0 deletions src/components/new-safe/create/steps/ReviewStep/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { type ReplayedSafeProps } from '@/store/slices'
import { predictAddressBasedOnReplayData } from '@/components/welcome/MyAccounts/utils/multiChainSafe'
import { createWeb3 } from '@/hooks/wallets/web3'
import { type DeploySafeProps } from '@safe-global/protocol-kit'
import { updateAddressBook } from '../../logic/address-book'

export const NetworkFee = ({
totalFee,
Expand Down Expand Up @@ -215,6 +216,17 @@ const ReviewStep = ({ data, onSubmit, onBack, setStep }: StepRenderProps<NewSafe
await createSafe(network, replayedSafeWithNonce, safeAddress)
}

// Update addressbook with owners and Safe on all chosen networks
dispatch(
updateAddressBook(
data.networks.map((network) => network.chainId),
safeAddress,
data.name,
data.owners,
data.threshold,
),
)

gtmSetChainId(chain.chainId)

if (isCounterfactualEnabled && payMethod === PayMethod.PayLater) {
Expand Down
2 changes: 0 additions & 2 deletions src/components/new-safe/create/steps/StatusStep/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useCounter } from '@/components/common/Notifications/useCounter'
import type { StepRenderProps } from '@/components/new-safe/CardStepper/useCardStepper'
import type { NewSafeFormData } from '@/components/new-safe/create'
import { getRedirect } from '@/components/new-safe/create/logic'
import { updateAddressBook } from '@/components/new-safe/create/logic/address-book'
import StatusMessage from '@/components/new-safe/create/steps/StatusStep/StatusMessage'
import useUndeployedSafe from '@/components/new-safe/create/steps/StatusStep/useUndeployedSafe'
import lightPalette from '@/components/theme/lightPalette'
Expand Down Expand Up @@ -54,7 +53,6 @@ export const CreateSafeStatus = ({
if (!chain || !safeAddress) return

if (status === SafeCreationEvent.SUCCESS) {
dispatch(updateAddressBook(chain.chainId, safeAddress, data.name, data.owners, data.threshold))
const redirect = getRedirect(chain.shortName, safeAddress, router.query?.safeViewRedirectURL)
if (typeof redirect !== 'string' || redirect.startsWith('/')) {
router.push(redirect)
Expand Down
17 changes: 0 additions & 17 deletions src/features/counterfactual/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import ExternalStore from '@/services/ExternalStore'
import { getSafeSDKWithSigner, getUncheckedSigner, tryOffChainTxSigning } from '@/services/tx/tx-sender/sdk'
import { getRelayTxStatus, TaskState } from '@/services/tx/txMonitor'
import type { AppDispatch } from '@/store'
import { addOrUpdateSafe } from '@/store/addedSafesSlice'
import { upsertAddressBookEntries } from '@/store/addressBookSlice'
import { defaultSafeInfo } from '@/store/safeInfoSlice'
import { didRevert, type EthersError } from '@/utils/ethers-utils'
import { assertProvider, assertTx, assertWallet } from '@/utils/helpers'
Expand Down Expand Up @@ -175,21 +173,6 @@ export const replayCounterfactualSafeDeployment = (
}

dispatch(addUndeployedSafe(undeployedSafe))
dispatch(upsertAddressBookEntries({ chainIds: [chainId], address: safeAddress, name }))
dispatch(
addOrUpdateSafe({
safe: {
...defaultSafeInfo,
address: { value: safeAddress, name },
threshold: setup.threshold,
owners: setup.owners.map((owner) => ({
value: owner,
name: undefined,
})),
chainId,
},
}),
)
}

const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
Expand Down

0 comments on commit fcaa83e

Please sign in to comment.