-
Notifications
You must be signed in to change notification settings - Fork 29
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
Conversation
RanGojo
commented
Nov 12, 2023
•
edited
Loading
edited
- 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) => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 142 as well.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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),
})
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
8873683
to
f60f65a
Compare