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: fallback to chainId of wallet #1587

Merged
merged 3 commits into from
Jan 24, 2023
Merged

fix: fallback to chainId of wallet #1587

merged 3 commits into from
Jan 24, 2023

Conversation

iamacook
Copy link
Member

What it solves

Resolves #1554

How this PR fixes it

useChainId returns the chainId of the connected wallet if no chainId is present in the URL or cached from the last session.

How to test it

  1. Open a "non-chainId" URL in an Incognito window (e.g. /welcome).
  2. Ensure the wallet is connected to a chain that is present in the environment chain configuration and connect the wallet.
  3. Observe the chain in the top right matches that of the wallet.

  1. Open a "non-chainId" URL in an Incognito window (e.g. /welcome).
  2. Ensure the wallet is connected to a chain that is NOT present in the environment chain configuration and connect the wallet.
  3. Observe the chain in the top right is the default fallback, Mainnet on prod. or Goerli on dev.

@github-actions
Copy link

github-actions bot commented Jan 23, 2023

Branch preview

✅ Deploy successful!

https://fallback_wallet_chainid--webcore.review-web-core.5afe.dev

@github-actions
Copy link

github-actions bot commented Jan 23, 2023

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

? wallet.chainId
: defaultChainId

return urlChainId || session.lastChainId || fallbackChainId
Copy link
Member

Choose a reason for hiding this comment

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

I would define the wallet chainId as a separate thing and fall back in this order:

  return urlChainId || walletChainId || session.lastChainId || fallbackChainId

Copy link
Member

Choose a reason for hiding this comment

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

Is fallbackChainId and walletChainId the same thing?

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've inverted the order and added tests to cover it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is fallbackChainId and walletChainId the same thing?

In my previous commit, fallbackChainId was either that of the wallet or from defaultChainId. I've changed it in accordance with the first suggestion. Wdyt?

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! 👍

@katspaugh katspaugh added this to the 1.5.0 milestone Jan 24, 2023
@katspaugh
Copy link
Member

katspaugh commented Jan 24, 2023

Tested, it correctly sets the app network with the current wallet network if you're on a page w/o a Safe address or ?chain= in the URL. ✅
It even changes the app network when you change the wallet network.
It briefly flashes the initial default network on page load, but that's expected.

On pages with a Safe address or the chain query param, it works the same as before.

@katspaugh katspaugh merged commit ab547e7 into dev Jan 24, 2023
@katspaugh katspaugh deleted the fallback-wallet-chainid branch January 24, 2023 15:04
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2023
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.

Use the chain the wallet is connected to as fallback
3 participants