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

Feat: add swaps card to safe apps list #3786

Merged
merged 24 commits into from
Jun 11, 2024
Merged

Conversation

jmealy
Copy link
Contributor

@jmealy jmealy commented May 31, 2024

What it solves

Resolves https://www.notion.so/safe-global/Add-a-block-to-apps-page-985e220c975b42b7950929ecb02a6715?pvs=4

How this PR fixes it

  • Add a component for showing native swaps in the safe apps list
  • Allow the card to be dismissed. This decision is persisted in localstorage.
  • Make the cards respond to the search and filter like the other safe apps.

How to test it

  • Open the safe apps list.
  • By default the new swaps card should be shown first in the list
  • It should be shown when searching with the keyword swap, along with other swapping apps.
  • It should show when filtering for the defi category
  • Clicking try now should bring you to the swaps feature
  • Clicking Don't show should remove the card from the list. It will remain hidden unless localstorage is cleared.

Screenshots

image

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) 🧑‍💻

Copy link

github-actions bot commented May 31, 2024

features: [],
socialProfiles: [],
developerWebsite: '',
chainIds: [chainId],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here I have the card shown on whatever chain is selected. Is swaps enabled on all chains?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, you can use: const isSwapFeatureEnabled = useHasFeature(FEATURES.NATIVE_SWAPS) to determine if swaps are enabled on the current chain.
Also how about we don't go for a custom "isNativeFeature" flag, but instead expose the swap app id as a custom const NATIVE_SWAP_APP_ID = 100_000
and then later you can compare against that id, instead of taht new isNativeFeature flag.

Copy link

github-actions bot commented May 31, 2024

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 1 0
Ignored 0 N/A
  • Result: ✅ success

  • Annotations: 1 total


[warning] react-hooks/exhaustive-deps

verifies the list of dependencies for Hooks like useEffect and similar

  • src/pages/apps/index.tsx Line 22 - The 'allApps' array makes the dependencies of useMemo Hook (at line 30) change on every render. To fix this, wrap the initialization of 'allApps' in its own useMemo() Hook.

Report generated by eslint-plus-action

@jmealy jmealy marked this pull request as ready for review May 31, 2024 13:20
@jmealy jmealy requested a review from compojoom May 31, 2024 13:20
Copy link

github-actions bot commented May 31, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
79.44% (+0.03% 🔼)
11513/14493
🔴 Branches
58.52% (+0.04% 🔼)
2777/4745
🟡 Functions
66.63% (-0.01% 🔻)
1845/2769
🟢 Lines
80.78% (+0.03% 🔼)
10379/12849
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / index.tsx
91.67% 75% 50% 95.45%

Test suite run success

1443 tests passing in 199 suites.

Report generated by 🧪jest coverage report action from d8f3a18

@compojoom compojoom requested a review from schmanu June 3, 2024 14:26
Copy link

github-actions bot commented Jun 3, 2024

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

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

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 950.38 KB (-15 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!

Three Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/apps 49.67 KB (🟡 +672 B) 1000.05 KB
/apps/custom 41.29 KB (🟡 +666 B) 991.66 KB
/home 59.46 KB (🟡 +689 B) 1009.84 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

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

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

const { remoteSafeApps, remoteSafeAppsLoading, pinnedSafeApps, pinnedSafeAppIds, togglePin } = useSafeApps()
const allApps = [swapsCardDetails, ...remoteSafeApps]
Copy link
Member

Choose a reason for hiding this comment

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

I get a lint warning that this should be memo'ed to avoid re-renders

name: 'Native swaps are here!',
description: 'Experience seamless trading with better decoding and security in native swaps.',
accessControl: { type: SafeAppAccessPolicyTypes.NoRestrictions },
tags: ['DeFi'],
Copy link
Member

Choose a reason for hiding this comment

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

The app should also have the DEX tag.

description: 'Experience seamless trading with better decoding and security in native swaps.',
accessControl: { type: SafeAppAccessPolicyTypes.NoRestrictions },
tags: ['DeFi'],
features: [],
Copy link
Member

Choose a reason for hiding this comment

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

We should also add that this app is batch tx optimized, otherwise it will not show when filtering for those.

Copy link

github-actions bot commented Jun 4, 2024

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@compojoom
Copy link
Collaborator

It's ok for me now. @schmanu ?

Copy link

Add a block to apps page

@francovenica
Copy link
Contributor

Ok, looks good. I've checked the things asked in the description plus what manu asked to be changed: be filtered by DEX and "Optimized with batched tx"

Question:
Currently when you search, the card leaves the first place and places just among the other apps. Would it be possible to make it appear always first since is technically not an app, so it shouldn't be mixed with them.
image

I don't consider this a blocker, so if too outside of the scope we can create a new ticket for just that and pass this one

@compojoom
Copy link
Collaborator

Currently when you search, the card leaves the first place and places just among the other apps. Would it be possible to make it appear always first since is technically not an app, so it shouldn't be mixed with them.

Actually this seems to be a bug, we have to fix this :(

Comment on lines 90 to 100
return safeApp.id !== NATIVE_SWAPS_APP_ID ? (
<li key={safeApp.id}>
<SafeAppCard
safeApp={safeApp}
isBookmarked={bookmarkedSafeAppsId?.has(safeApp.id)}
onBookmarkSafeApp={onBookmarkSafeApp}
removeCustomApp={removeCustomApp}
onClickSafeApp={handleSafeAppClick(safeApp)}
openPreviewDrawer={openPreviewDrawer}
/>
</li>
Copy link
Member

Choose a reason for hiding this comment

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

Why does this card have to be added into the safeAppsList? Why can't it just be rendered outside of the map? Feels very hacky to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It gets mixed in with the safe apps in the parent component just so that it responds to filtering.
I changed it here to render outside of the map, hopefully it's a bit better

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 it's totally fine if it disappears when the list is filtered.

Copy link

github-actions bot commented Jun 10, 2024

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@jmealy
Copy link
Contributor Author

jmealy commented Jun 10, 2024

Currently when you search, the card leaves the first place and places just among the other apps. Would it be possible to make it appear always first since is technically not an app, so it shouldn't be mixed with them.

Should be ok now

src/pages/apps/index.tsx Outdated Show resolved Hide resolved
src/components/safe-apps/NativeFeatureCard/index.tsx Outdated Show resolved Hide resolved
src/components/safe-apps/SafeAppList/index.tsx Outdated Show resolved Hide resolved
src/components/safe-apps/SafeAppList/index.tsx Outdated Show resolved Hide resolved
src/components/safe-apps/hooks/useNativeSwapsAppCard.ts Outdated Show resolved Hide resolved
src/pages/apps/index.tsx Outdated Show resolved Hide resolved
@katspaugh
Copy link
Member

I don't understand why so many abstraction layers were added just to show a static card in the beginning of the apps list...

@francovenica
Copy link
Contributor

@jmealy The deploy has failed, can you re-trigger it to see if it at least creates the environment again to test?

@@ -0,0 +1 @@
export const NATIVE_SWAPS_APP_ID = 100_000
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export const NATIVE_SWAPS_APP_ID = 100_000

@jmealy
Copy link
Contributor Author

jmealy commented Jun 10, 2024

I don't understand why so many abstraction layers were added just to show a static card in the beginning of the apps list...

It was mostly so the filtering would work. Hopefully it's ok now, sorry for the mess!

Copy link
Member

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

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

Thanks for refactoring it! 🙏

@compojoom
Copy link
Collaborator

But wait, so now we no longer show the safe widget when we filter?

@francovenica
Copy link
Contributor

francovenica commented Jun 10, 2024

But wait, so now we no longer show the safe widget when we filter?

I was going to comment the same thing ☝️

Also I just saw that, if the card is too thin (for some viewports) the button text are in 2 rows. If you reduce the padding to 21px it fits just fine with the thiniest cards
image
image

@katspaugh
Copy link
Member

katspaugh commented Jun 10, 2024

Yes, it's fine to not show it when you filter.

@francovenica
Copy link
Contributor

Ok, the filtering is out.

See if the padding of that button can be fixed.

Beyond that the ticket is fine to be merged

Copy link

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@katspaugh katspaugh merged commit 9720343 into dev Jun 11, 2024
13 of 14 checks passed
@katspaugh katspaugh deleted the feat/safe-apps-swaps-block branch June 11, 2024 08:13
@github-actions github-actions bot locked and limited conversation to collaborators Jun 11, 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.

5 participants