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(wallets): fix switch network bug in wallet connect #435

Merged
merged 1 commit into from
Nov 12, 2023

Conversation

RanGojo
Copy link
Member

@RanGojo RanGojo commented Nov 12, 2023

  • handle switch network without creating new session
  • fix minor bugs in subscribe
  • update manifest
  • handle async/sync switch network state update
  • update wallet-connect deps to the latest version

@@ -126,12 +132,18 @@ export const subscribe: Subscribe = ({
// Listen to events triggred by wallet. (e.g. accountsChanged and chainChanged)
client.on('session_event', (args) => {
if (args.params.event.name === EthereumEvents.ACCOUNTS_CHANGED) {
const accounts = args.params.event.data;
const chainId = args.params.chainId;
const accounts = args.params.event.data.map((account: string) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use caip package for working with CAIP standard.

Copy link
Collaborator

Choose a reason for hiding this comment

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

line 142 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.

fixed

@@ -192,3 +201,76 @@ export function getChainIdByNetworkName(

return chainId;
}

export async function switchOrAddEvmChain(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use caip package for working with CAIP standard.
It can parse and also generate the string. Please make sure you are using it in this function.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

});
instance.session = session;
const isAsyncSwitchNetork = needSessionRecreateOnSwitchNetwork(instance);
config.isAsyncInstance = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

*/
if (
requestedNetwork !== this.state.network &&
!this.options.config.isAsyncSwitchNetwork
Copy link
Collaborator

Choose a reason for hiding this comment

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

To make it more general I suggest change it to something like this:

this.options.config.avoidUpdateOnSwitchNetwork({
  instance: this.provider,
  network: requestedNetwork,
  getState: this.getState.bind(this),
})

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 will fix this comment and next related ones in my next PR.

const isAsyncSwitchNetork = needSessionRecreateOnSwitchNetwork(instance);
config.isAsyncInstance = true;
if (isAsyncSwitchNetork) {
config.isAsyncSwitchNetwork = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

if you've implemented avoidUpdateOnSwitchNetwork, you can remove this line from here.

meta,
});
instance.session = session;
const isAsyncSwitchNetork = needSessionRecreateOnSwitchNetwork(instance);
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can directly call your function (as avoidUpdateOnSwitchNetwork) here as well.

@RanGojo RanGojo force-pushed the fix/fix-wallet-connect-switch-network branch from 8873683 to f60f65a Compare November 12, 2023 18:19
@RanGojo RanGojo merged commit 8c4a17b into next Nov 12, 2023
1 check passed
@RanGojo RanGojo deleted the fix/fix-wallet-connect-switch-network branch November 12, 2023 18:21
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.

2 participants