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(web): appUrl query was getting lost while switching network in safeApp #5081

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

chiranjeev13
Copy link

What it solves

Resolves #4980

How this PR fixes it

In File apps/web/src/components/common/NetworkSelector/index.tsx

export const getNetworkLink = (router: NextRouter, safeAddress: string, networkShortName: string) => {
  const isSafeOpened = safeAddress !== ''

  const query = (
    isSafeOpened
      ? {
          safe: `${networkShortName}:${safeAddress}`,
        }
      : { chain: networkShortName }
  ) as {
    safe?: string
    chain?: string
    safeViewRedirectURL?: string
    appUrl?: string // Added this to the query
  }

  const route = {
    pathname: router.pathname,
    query,
  }

  if (router.query?.safeViewRedirectURL) {
    route.query.safeViewRedirectURL = router.query?.safeViewRedirectURL.toString()
  }

  if (router.query?.appUrl) {
    route.query.appUrl = router.query.appUrl.toString()
  } // if present then appUrl should be populated

  return route
}

How to test it

yarn workspace @safe-global/web start

create a safe multi chain account
go inside a safeApp
switch network in there

Screenshots

Screen.Recording.2025-02-23.at.1.40.51.AM.mov

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 Feb 22, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@chiranjeev13
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@@ -92,6 +93,10 @@ export const getNetworkLink = (router: NextRouter, safeAddress: string, networkS
route.query.safeViewRedirectURL = router.query?.safeViewRedirectURL.toString()
}

if (router.query?.appUrl) {
route.query.appUrl = router.query.appUrl.toString()
Copy link
Member

Choose a reason for hiding this comment

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

This preserves the query indeed but ignores the fact that a Safe App might be not enabled on all chains.

From the original issue requirements:

Providing the Safe App is present on the destination chain, the Safe App should remain open, otherwise the dashboard navigated to, for example.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I was thinking the same. However, in the case of other EOAs, when we switch to a different network within an app, it's the app that indicates it as an unsupported network.

Since we're displaying the app within Safe's dashboard, I guess it's a better user experience for Safe to indicate an unsupported network. Working on this fix !!

Copy link
Author

Choose a reason for hiding this comment

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

Updated the unsupported chain handling logic in apps/web/src/pages/apps/open.tsx:

In this commit 8211879

Key Modifications:

  • Refined the condition to check when safeApp.chainIds is empty
  • Maintained 3-second redirect timeout
  • ensured the remoteSafeAppsLoading is false before we check for chainIds

Video Preview

Screen.Recording.2025-02-23.at.10.11.45.PM.mov

Let me know if any thing else needs to be updated @katspaugh

Copy link
Member

Choose a reason for hiding this comment

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

Good idea!

Comment on lines 92 to 97
setTimeout(() => {
router.push({
pathname: AppRoutes.apps.index,
query: { safe: router.query.safe },
})
}, 3000)
Copy link
Member

Choose a reason for hiding this comment

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

This should be done in a useEffect.

p={2}
>
<Typography variant="body1" gutterBottom>
Chain {chainId} is not supported in this app. <br />
Copy link
Member

Choose a reason for hiding this comment

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

Can we display chainName here? It can be taken from useCurrentChain().

Copy link
Author

Choose a reason for hiding this comment

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

Sure let me just do that instead!

Copy link
Author

Choose a reason for hiding this comment

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

Updated fix:

  • Using useEffect for routing back to safeApp Dashboard
  • Displaying chain name instead of chainId using useCurrentChain()

check it out here: c288de4

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 so much!
Sending to our QA.

@chiranjeev13
Copy link
Author

Not sure why the cypress tests failed @katspaugh

@katspaugh
Copy link
Member

@chiranjeev13 that's normal, they can't run on external forks.

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.

appUrl removed when switching chains
2 participants