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: Show raw data if decodedData doesn't contain any parameters [SW-435] #4622

Merged
merged 3 commits into from
Dec 15, 2024

Conversation

usame-algan
Copy link
Member

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

What it solves

Resolves SW-435

How this PR fixes it

Screenshot 2024-12-06 at 15 52 16

How to test it

  1. Open a transaction where the method name is there but no parameters
  2. Observe it displays Hex encoded data instead of nothing

Screenshots

Screenshot 2024-12-06 at 15 52 24

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 13:55
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


expect(getByText('Data (hex-encoded)')).toBeInTheDocument()
})
})
Copy link

Choose a reason for hiding this comment

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

Consider organizing your mock data and expected results in their own files or constants to enhance readability and maintainability. Additionally, verify if the imported path is correct or if there's a need for dynamic imports to optimize performance.

@@ -49,7 +47,7 @@ export const DecodedData = ({ txData, toInfo }: Props): ReactElement | null => {
? 'this Safe Account'
: addressInfo?.name || toInfo?.name || txData.to.name
const avatar = addressInfo?.logoUri || toInfo?.logoUri || txData.to.logoUri
const isFallback = !method && !txData?.dataDecoded?.parameters
const isFallback = !method || txData?.dataDecoded?.parameters?.length === 0

let decodedData = <></>
if (txData.dataDecoded && !isFallback) {
Copy link

Choose a reason for hiding this comment

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

  1. Simplify the conditional structure in the blocks handling txData and toInfo. Consider reorganizing nested if statements for readability.
  2. For isFallback calculation: method check should use logical ||, but simplifying direct logic expressions might improve readability.

@@ -38,8 +38,6 @@ export const DecodedData = ({ txData, toInfo }: Props): ReactElement | null => {
)
}

if (!txData) return null
Copy link
Member Author

Choose a reason for hiding this comment

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

While writing tests I realised the only reason this condition is here is to satisfy Typescript so I refactored it. Now it will show that txData is defined further down.

@@ -49,7 +47,7 @@ export const DecodedData = ({ txData, toInfo }: Props): ReactElement | null => {
? 'this Safe Account'
: addressInfo?.name || toInfo?.name || txData.to.name
const avatar = addressInfo?.logoUri || toInfo?.logoUri || txData.to.logoUri
const isFallback = !method && !txData?.dataDecoded?.parameters
const isFallback = !method || txData?.dataDecoded?.parameters?.length === 0
Copy link
Member Author

Choose a reason for hiding this comment

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

This will cover the case listed where there is a method but no parameters. I am not sure if we have the case where there is no method but parameters (don't think so) but in that case it would also fallback to raw data now.

Copy link
Member

Choose a reason for hiding this comment

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

There are plenty of methods with no parameters.
E.g. WETH wrap/unwrap (value is passed as value, not in parameters), NFT mints etc.

Screenshot 2024-12-06 at 15 07 54

Copy link
Member Author

Choose a reason for hiding this comment

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

That case is fine and should now display the raw data instead of "No parameters"
Screenshot 2024-12-06 at 15 20 09

I was talking about the opposite case where potential transactions don't have a method name but parameters for some reason but feels like if the method name is missing then surely the ABI will be missing so there won't be decoded parameters either.

Copy link
Member

@katspaugh katspaugh Dec 6, 2024

Choose a reason for hiding this comment

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

I wouldn't replace "No parameters" with a raw data string. The raw data could be added to the list below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I undertand what you mean now. There are legitimate transactions without parameters so we should clearly tell the user in those cases that there are no parameters but still have the fallback to raw data. Lets display both to them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Like so
Screenshot 2024-12-06 at 15 31 25

Copy link
Member

@katspaugh katspaugh Dec 6, 2024

Choose a reason for hiding this comment

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

Yes, exactly. And I would move it down, below the separator. It's a bit weird that the copy button would be in front though.

Also maybe we should just always show it, not just when there are no params.

Copy link
Member Author

@usame-algan usame-algan Dec 9, 2024

Choose a reason for hiding this comment

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

The part below the separator is the Summary which we don't render for Multisends but we need this raw data especially for the Multisend transactions. I checked if we can just add another divider between but imo it looks strange:
Screenshot 2024-12-09 at 10 17 19
Screenshot 2024-12-09 at 10 17 29

For top-level transactions we always render the raw data under Advanced details.

I would keep it as is since it has a very limited scope (only rendered when we also render "No parameters")

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. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 1 MB (🟡 +13 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Copy link

github-actions bot commented Dec 6, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
73.71% (+0.01% 🔼)
14363/19487
🔴 Branches
51.06% (-0.01% 🔻)
3411/6680
🔴 Functions
56.43% (+0% 🔼)
2027/3592
🟡 Lines
75.27% (-0% 🔻)
13033/17316
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / index.tsx
100%
95.56% (-2.27% 🔻)
100% 100%
🟢
... / SignForm.tsx
91.8% (-0.13% 🔻)
84.85% (-0.45% 🔻)
100%
92.98% (-0.12% 🔻)

Test suite run success

1667 tests passing in 227 suites.

Report generated by 🧪jest coverage report action from 9d51ce8

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


expect(getByText('Data (hex-encoded)')).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 parameterizing repeated elements in your test cases. Use a test matrix or utility functions to reduce duplication, especially for common inputs and expectations between tests.
  2. Address DRY violations in mock setup for test consistency and to ease future changes.

@@ -49,7 +47,7 @@ export const DecodedData = ({ txData, toInfo }: Props): ReactElement | null => {
? 'this Safe Account'
: addressInfo?.name || toInfo?.name || txData.to.name
const avatar = addressInfo?.logoUri || toInfo?.logoUri || txData.to.logoUri
const isFallback = !method && !txData?.dataDecoded?.parameters
const isFallback = !method || txData?.dataDecoded?.parameters?.length === 0

let decodedData = <></>
if (txData.dataDecoded && !isFallback) {
Copy link

Choose a reason for hiding this comment

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

Refactor the conditional logic for returning null by consolidating multiple checks into one if statement. Replace the existing redundant conditionals with if (!txData && !toInfo) return null;. This reduces clutter and improves readability.

Copy link
Member Author

Choose a reason for hiding this comment

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

Typescript can't deal with that for some reason.

if (!txData && !toInfo) return null

if (!txData && toInfo) return <XYZ />

// txData should be defined from here on out but isn't

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

No parameters
</Typography>
{hexData && <HexEncodedData title="Data (hex-encoded)" hexData={hexData} />}
</>
)
}

Copy link

Choose a reason for hiding this comment

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

Adding hexData prop requires handling undefined values when it's not provided. Consider using hexData?.length > 0 instead of just hexData for better clarity. The conditional rendering implies hexData should be checked for both existence and non-emptiness.

},
value: '0',
operation: 0,
dataDecoded: {
Copy link

Choose a reason for hiding this comment

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

  1. The toInfo object is missing the name property in multiple test instances. Confirm if this change is intended; otherwise, inconsistency might affect related logic or conditional rendering, especially if other parts of the code rely on this property.

@@ -38,8 +38,6 @@ export const DecodedData = ({ txData, toInfo }: Props): ReactElement | null => {
)
}

Copy link

Choose a reason for hiding this comment

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

The removal of the isFallback check leads to MethodDetails rendering even if there are no parameters which might not be intended. Ensure method presence or conditions are correctly handled to avoid unintended render logic changes.

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

No parameters
</Typography>
{hexData && <HexEncodedData title="Data (hex-encoded)" hexData={hexData} />}
</>
)
}

Copy link

Choose a reason for hiding this comment

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

Review:

  1. Improve Conditional Rendering:
    Current:
    if (!data.parameters?.length) {...}
    Suggestion: Utilize optional chaining consistently and prefer nullish coalescing for clarity:
    if (!(data.parameters ?? []).length) {...}

const mockTxData = {
to: {
value: '0x874E2190e6B10f5173F00E27E6D5D9F90b7664C4',
},
Copy link

Choose a reason for hiding this comment

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

  1. The test description for "shows an Interact with block if there is no txData but toInfo" needs adjustment. The removal of name from toInfo implies a change in test focus without updating the description.
  2. Consider adding a beforeEach section to minimize duplications when initializing mockTxData. It reduces redundancy and applies DRY principles.
  3. The test for "only shows Hex encoded data if no decodedData exists" might imply a redundancy; ensure the condition doesn't overlap with other tests.
  4. Check if getByText and queryByText can be consolidated for clarity when both are used in a single case.

@@ -38,8 +38,6 @@ export const DecodedData = ({ txData, toInfo }: Props): ReactElement | null => {
)
}

Copy link

Choose a reason for hiding this comment

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

Remove isFallback if it's no longer used. Unused variables can clutter the code and confuse future maintainers. Consider refactoring to ensure the logical flow remains clear and concise without introducing redundant checks or variables.

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

@@ -7,21 +8,26 @@ import { Value } from '@/components/transactions/TxDetails/TxData/DecodedData/Va

type MethodDetailsProps = {

Choose a reason for hiding this comment

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

Remove the unnecessary extra blank line after the Typography component to maintain code consistency and readability.

@francovenica
Copy link
Contributor

Lgtm:

Before after comparison:
image

image

@usame-algan usame-algan merged commit 4a379f6 into dev Dec 15, 2024
16 checks passed
@usame-algan usame-algan deleted the raw-data-fallback branch December 15, 2024 22:40
@github-actions github-actions bot locked and limited conversation to collaborators Dec 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants