Skip to content
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

fix: Disable Add to Batch button for safe apps [SW-363] #4623

Merged
merged 3 commits into from
Dec 10, 2024

Conversation

usame-algan
Copy link
Member

@usame-algan usame-algan commented Dec 6, 2024

What it solves

Resolves SW-363

How this PR fixes it

  • Disables the BatchButton if there is an origin passed (it is a safe app or walletconnect)

How to test it

  1. Create a transaction through a safe app
  2. Choose Sign
  3. Observe Add to batch button is disabled
  4. Create a transaction through the native UI
  5. Observe there is an Add to batch button when signing and it is enabled

Checklist

  • I've tested the branch on mobile 📱
  • I've documented how it affects the analytics (if at all) 📊
  • I've written a unit/e2e test for it (if applicable) 🧑‍💻

@usame-algan usame-algan requested a review from katspaugh December 6, 2024 15:11
Copy link

Copy link

github-actions bot commented Dec 6, 2024

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code review by ChatGPT

@@ -130,7 +132,7 @@ export const SignForm = ({
spacing={{ xs: 2, md: 2 }}
>
{/* Batch button */}
{isCreation && !isBatch && (
{isCreation && !isBatch && !isSafeAppTransaction && (
<BatchButton
onClick={onBatchClick}
disabled={submitDisabled || !isBatchable}
Copy link

Choose a reason for hiding this comment

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

Ensure the new isSafeAppTransaction variable is meaningful. Its usage is currently limited to a check condition in the render block. Consider consolidating this logic and removing it if it doesn't add clarity or functionality.

Copy link

github-actions bot commented Dec 6, 2024

📦 Next.js Bundle Analysis for safe-wallet-web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code review by ChatGPT

const button = getByText('Add to batch')

expect(button).toBeInTheDocument()
})
})
Copy link

Choose a reason for hiding this comment

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

  1. Consider refactoring the repeated render logic into a helper function to adhere to the DRY principle. This reduces redundancy and enhances maintainability.

  2. The usage of queryByText and getByText could lead to inconsistent behavior if the text content changes. Consider using a more robust method like test IDs for querying elements.

Copy link

github-actions bot commented Dec 6, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
73.7% (-0% 🔻)
14364/19490
🔴 Branches
51.05% (-0.01% 🔻)
3415/6689
🔴 Functions
56.43% (+0% 🔼)
2027/3592
🟡 Lines
75.27% (-0.01% 🔻)
13035/17318

Test suite run success

1664 tests passing in 226 suites.

Report generated by 🧪jest coverage report action from fe87c47

@@ -101,6 +101,8 @@ export const SignForm = ({
const submitDisabled =
!safeTx || !isSubmittable || disableSubmit || cannotPropose || (needsRiskConfirmation && !isRiskConfirmed)

const isSafeAppTransaction = !!origin
Copy link
Member

Choose a reason for hiding this comment

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

I think origin is also non-null in case of WalletConnect txs and probably swaps/staking/bridging as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we should hide it for those transactions as well to be on the safe side. At least for swaps the button is already disabled since it is a delegate call:
Screenshot 2024-12-09 at 10 29 49

@usame-algan usame-algan changed the title fix: Hide Add to Batch button for safe apps [SW-363] fix: Disable Add to Batch button for safe apps [SW-363] Dec 9, 2024
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code review by ChatGPT

@@ -133,7 +135,7 @@ export const SignForm = ({
{isCreation && !isBatch && (
<BatchButton
onClick={onBatchClick}
Copy link

Choose a reason for hiding this comment

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

The condition for rendering BatchButton has been modified, potentially affecting its visibility logic. Review if excluding !isSafeAppTransaction in the surrounding condition and adding it to the disabled prop aligns with the desired behavior.

@usame-algan
Copy link
Member Author

Slightly adjusted it so we always show the button but it is disabled to keep it consistent with previous behaviour.

@francovenica
Copy link
Contributor

LGTM

Checked that dapps don't have the add to batch button. Same for other types of tx like reject tx, swap, stake, bridge....
Made sure that the tx that must have the add to batch are still there: send funds, edit owner, edit policies, remove modules...

@usame-algan usame-algan merged commit 608d004 into dev Dec 10, 2024
9 of 16 checks passed
@usame-algan usame-algan deleted the hide-add-to-batch branch December 10, 2024 08:25
@github-actions github-actions bot locked and limited conversation to collaborators Dec 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants