Skip to content

Commit

Permalink
Add error handling for smart account predictions and validate smart a…
Browse files Browse the repository at this point in the history
…ddresses in role creation
  • Loading branch information
Da-Colon committed Dec 9, 2024
1 parent 3d324ce commit d1f5bb0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/hooks/utils/useCreateRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,9 @@ export default function useCreateRoles() {
throw new Error('Cannot prepare transactions for edited role without smart address');
}
const newPredictedHatSmartAccount = await predictSmartAccount(BigInt(formHat.id));
if (!newPredictedHatSmartAccount) {
throw new Error('Cannot predict smart account');
}
const newStreamTxData = createBatchLinearStreamCreationTx(
newStreamsOnHat.map(stream => ({ ...stream, recipient: newPredictedHatSmartAccount })),
);
Expand Down
9 changes: 8 additions & 1 deletion src/store/roles/rolesStoreUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const predictAccountAddress = async (params: {
tokenId,
]);
if (!(await publicClient.getBytecode({ address: predictedAddress }))) {
throw new DecentHatsError('Predicted address is not a contract');
return;
}
return predictedAddress;
};
Expand Down Expand Up @@ -288,6 +288,10 @@ export const sanitize = async (
publicClient,
});

if (!topHatSmartAddress) {
throw new DecentHatsError('Top Hat smart address is not valid');
}

const whitelistingVotingContract = whitelistingVotingStrategy
? getContract({
abi: abis.LinearERC20VotingWithHatsProposalCreation,
Expand Down Expand Up @@ -320,6 +324,9 @@ export const sanitize = async (
tokenId: BigInt(rawAdminHat.id),
publicClient,
});
if (!adminHatSmartAddress) {
throw new DecentHatsError('Admin Hat smart address is not valid');
}

const adminHat: DecentAdminHat = {
id: rawAdminHat.id,
Expand Down

0 comments on commit d1f5bb0

Please sign in to comment.