Skip to content

Commit

Permalink
refactor(accounts-actions): dont pass hook params to subplebbit.edit
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanabaroa committed Aug 30, 2024
1 parent a80ef4b commit 52d575c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/stores/accounts/accounts-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,16 @@ export const publishSubplebbitEdit = async (subplebbitAddress: string, publishSu
}
validator.validateAccountsActionsPublishSubplebbitEditArguments({subplebbitAddress, publishSubplebbitEditOptions, accountName, account})

const subplebbitEditOptions = {...publishSubplebbitEditOptions}
delete subplebbitEditOptions.onChallenge
delete subplebbitEditOptions.onChallengeVerification
delete subplebbitEditOptions.onError
delete subplebbitEditOptions.onPublishingStateChange

// account is the owner of the subplebbit and can edit it locally, no need to publish
const localSubplebbitAddresses = await account.plebbit.listSubplebbits()
if (localSubplebbitAddresses.includes(subplebbitAddress)) {
await subplebbitsStore.getState().editSubplebbit(subplebbitAddress, publishSubplebbitEditOptions, account)
await subplebbitsStore.getState().editSubplebbit(subplebbitAddress, subplebbitEditOptions, account)
// create fake success challenge verification for consistent behavior with remote subplebbit edit
publishSubplebbitEditOptions.onChallengeVerification({challengeSuccess: true})
publishSubplebbitEditOptions.onPublishingStateChange?.('succeeded')
Expand All @@ -746,14 +752,10 @@ export const publishSubplebbitEdit = async (subplebbitAddress: string, publishSu
timestamp: Math.round(Date.now() / 1000),
author: account.author,
signer: account.signer,
...publishSubplebbitEditOptions,
...subplebbitEditOptions,
// not possible to edit subplebbit.address over pubsub, only locally
address: subplebbitAddress,
}
delete createSubplebbitEditOptions.onChallenge
delete createSubplebbitEditOptions.onChallengeVerification
delete createSubplebbitEditOptions.onError
delete createSubplebbitEditOptions.onPublishingStateChange

let subplebbitEdit = await account.plebbit.createSubplebbitEdit(createSubplebbitEditOptions)
let lastChallenge: Challenge | undefined
Expand Down

0 comments on commit 52d575c

Please sign in to comment.