Skip to content

feat: add signerAddress prop to DELETE subscriptions endpoint #2651

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

Merged
merged 5 commits into from
Jul 18, 2025

Conversation

compojoom
Copy link
Contributor

Summary

Resolves https://linear.app/safe-global/issue/COR-336/expose-signeraddress-to-the-delete-subscriptions-endpoint

adds a signerAddress prop to the delete subscriptions endpoint. This allows us to delete just a single signerAddress.

With this change the endpoint behaves as follows

  • no signer address provided -> drop everything row related to the safeAddress and deviceId
  • signerAddress provided -> drop only the rows that match the signerAddress and safeAddress and deviceId
  • signerAddress set to null -> drop only the rows where signerAddress is NULL and SafeAddress and DeviceId match

@compojoom compojoom requested a review from a team as a code owner July 16, 2025 07:08
Copy link
Contributor

@LucieFaire LucieFaire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks legit, but left some small comments :)

@@ -203,4 +203,146 @@ describe('DeleteAllSubscriptionsDtoSchema', () => {
},
]);
});

it('should validate signerAddress when provided', () => {
const deleteAllSubscriptionsDto = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: you could use the builder and only provide the signerAddress on demand

expect(result.success).toBe(true);
});

it('should validate when signerAddress is not provided', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the very first test checks the same, so maybe we dont need it, or should be more explicit in a check


it('should checksum signerAddress when provided', () => {
const nonChecksummedAddress = faker.finance.ethereumAddress().toLowerCase();
const deleteAllSubscriptionsDto = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: maybe we could use builder everywhere instead of specifying the whole obj?

@@ -10,6 +10,7 @@ export const DeleteAllSubscriptionsDtoSchema = z.object({
chainId: NumericStringSchema,
deviceUuid: UuidSchema,
safeAddress: AddressSchema,
signerAddress: AddressSchema.nullable().optional(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be replaced with nullish() - it is an equivalent

signer_address: signerAddress,
});

const deleteAllSubscriptionsDto = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we please also use the builder in these tests


it('Should include signerAddress in where conditions when provided', async () => {
const signerAddress = getAddress(faker.finance.ethereumAddress());
const deleteAllSubscriptionsDto = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

builder ? :)

},
};

// Handle signerAddress: undefined (omitted) vs null (explicit) vs string (specific address)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be simplified:

return subscription.signerAddress === undefined
  ? baseCondition
  : {
      ...baseCondition,
      signer_address:
        subscription.signerAddress === null
          ? IsNull()
          : subscription.signerAddress,
    };

And maybe we can leave one comment before describing all cases in one place

Copy link
Contributor Author

@compojoom compojoom Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @LucieFaire, Thanks for the suggestion, but I'm going to resist it for as long as I can :D
I don't think that nested ternaries make the code simpler. They make it more compact, but sacrifice readibility.

@PooyaRaki PooyaRaki marked this pull request as draft July 16, 2025 14:28
@PooyaRaki
Copy link
Contributor

@compojoom I marked it as a draft since the tests are failing. Please feel free to mark it as ready for review once the tests are fixed. thanks

@compojoom compojoom marked this pull request as ready for review July 17, 2025 08:00
);

// The subscription with signerAddress1 should still exist
const remainingSubscriptions =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We can rename it to otherSubscriptions for more readability, Specially that the previous test also has const remainingSubscriptions and expect it to be zero.

type: 'string',
required: false,
nullable: true,
description:
Copy link
Contributor

@PooyaRaki PooyaRaki Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the thorough explanation. 👏

@compojoom compojoom enabled auto-merge (squash) July 18, 2025 08:43
@compojoom compojoom merged commit 2d2d4e4 into main Jul 18, 2025
36 of 38 checks passed
@compojoom compojoom deleted the feat/delete-subscription-for-signer branch July 18, 2025 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants