From f1df19e612af2d87ca583e662eda1d8769a1d8a2 Mon Sep 17 00:00:00 2001 From: MananTank Date: Tue, 25 Mar 2025 22:39:38 +0000 Subject: [PATCH] [TOOL-3689] Dashboard: Keep switch in disabled state if field value is empty in Sponsorship rules form (#6535) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## PR-Codex overview This PR focuses on improving the `transformedQueryData` computation by filtering out empty values from the `policy` properties. It enhances data handling for `allowedContractAddresses`, `allowedWallets`, `blockedWallets`, and `allowedChainIds`, ensuring cleaner and more accurate data is returned. ### Detailed summary - Refactored `transformedQueryData` to filter out empty values from `allowedContractAddresses`, `allowedWallets`, `blockedWallets`, and `allowedChainIds`. - Simplified return conditions for these properties. - Changed handling of `allowedChainIds` to return an empty array instead of null to prevent API issues. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- .../SponsorshipPolicies/index.tsx | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/apps/dashboard/src/components/smart-wallets/SponsorshipPolicies/index.tsx b/apps/dashboard/src/components/smart-wallets/SponsorshipPolicies/index.tsx index 77c1a168bdf..05efcf0747b 100644 --- a/apps/dashboard/src/components/smart-wallets/SponsorshipPolicies/index.tsx +++ b/apps/dashboard/src/components/smart-wallets/SponsorshipPolicies/index.tsx @@ -112,24 +112,31 @@ export function AccountAbstractionSettingsPage( const policy = props.bundlerService; - const transformedQueryData = useMemo( - () => ({ + const transformedQueryData = useMemo(() => { + const allowedContractAddresses = policy.allowedContractAddresses?.filter( + (x) => x !== "", + ); + + const allowedWallets = policy.allowedWallets?.filter((x) => x !== ""); + const blockedWallets = policy.blockedWallets?.filter((x) => x !== ""); + + // there is a bug in API server that makes `allowedChainIds` an array with `0` if we set it to null + const allowedChainIds = policy.allowedChainIds?.filter((x) => x !== 0); + + return { allowedChainIds: - policy.allowedChainIds && policy.allowedChainIds?.length > 0 - ? policy.allowedChainIds - : null, + allowedChainIds && allowedChainIds?.length > 0 ? allowedChainIds : null, allowedContractAddresses: - policy.allowedContractAddresses && - policy.allowedContractAddresses?.length > 0 - ? joinWithComma(policy.allowedContractAddresses) + allowedContractAddresses && allowedContractAddresses.length > 0 + ? joinWithComma(allowedContractAddresses) : null, allowedWallets: - policy.allowedWallets && policy.allowedWallets?.length > 0 - ? joinWithComma(policy.allowedWallets) + allowedWallets && allowedWallets?.length > 0 + ? joinWithComma(allowedWallets) : null, blockedWallets: - policy.blockedWallets && policy.blockedWallets?.length > 0 - ? joinWithComma(policy.blockedWallets) + blockedWallets && blockedWallets?.length > 0 + ? joinWithComma(blockedWallets) : null, bypassWallets: policy.bypassWallets && policy.bypassWallets?.length > 0 @@ -148,14 +155,13 @@ export function AccountAbstractionSettingsPage( }, globalLimit: policy.limits?.global ?? null, allowedOrBlockedWallets: - policy.allowedWallets && policy.allowedWallets?.length > 0 + allowedWallets && allowedWallets?.length > 0 ? "allowed" - : policy.blockedWallets && policy.blockedWallets?.length > 0 + : blockedWallets && blockedWallets?.length > 0 ? "blocked" : null, - }), - [policy], - ); + }; + }, [policy]); const form = useForm>({ resolver: zodResolver(aaSettingsFormSchema), @@ -212,11 +218,12 @@ export function AccountAbstractionSettingsPage( const parsedValues: Omit = { - allowedContractAddresses: - values.allowedContractAddresses !== null - ? toArrFromList(values.allowedContractAddresses) - : null, - allowedChainIds: values.allowedChainIds, + allowedContractAddresses: values.allowedContractAddresses + ? toArrFromList(values.allowedContractAddresses) + : null, + + // don't set null - `updateProject` API adds chainId 0 to the list if its null and makes it `[0]` + allowedChainIds: values.allowedChainIds || [], allowedWallets: values.allowedOrBlockedWallets === "allowed" && values.allowedWallets !== null