message: layer2 chain: connection and chain change handling
diff: @@ -96,6 +96,8 @@ export default abstract class Layer2ChainWeb3Strategy
  this.chainId
  ),
  });
  + this.web3.setProvider(this.provider as any);
  +
  this.connector.on('display_uri', (err, payload) => {
  if (err) {
  console.error('Error in display_uri callback', err);
  @@ -104,25 +106,36 @@ export default abstract class Layer2ChainWeb3Strategy
  this.walletConnectUri = payload.params[0];
  });
  - this.provider.on('chainChanged', (chainId: number) => {
  - if (chainId !== this.chainId) {
  - this.simpleEmitter.emit('incorrect-chain');
  + this.provider.on('accountsChanged', async (accounts: string[]) => {
  + // this actually doesn't ever happen with walletconnect. we instead go through the disconnect event
  + // added just-in-case
  + if (!accounts.length) {
  + this.onDisconnect();
  + }
  +
  + try {
  + // try to initialize things safely
  + // one expected failure is if we connect to a chain which we don't have an rpc url for
  + this.#exchangeRateApi = await getSDK('ExchangeRate', this.web3);
  + this.#safesApi = await getSDK('Safes', this.web3);
  + this.#hubAuthApi = await getSDK('HubAuth', this.web3, config.hubURL);
  + this.updateWalletInfo(accounts, this.chainId);
  + } catch (e) {
  + console.error(
  + 'Error initializing layer 2 wallet and services. Wallet may be connected to an unsupported chain'
  + );
  + console.error(e);
  this.disconnect();
  - } else {
  - this.simpleEmitter.emit('correct-chain');
  }
  });
  - this.connector.on('session_update', async (error, payload) => {
  - if (error) {
  - throw error;
  - }
  - let { accounts, chainId } = payload.params[0];
  - if (chainId !== this.chainId) {
  +
  + this.provider.on('chainChanged', async (connectedChainId: number) => {
  + if (connectedChainId !== this.chainId) {
  this.simpleEmitter.emit('incorrect-chain');
  + this.disconnect();
  } else {
  this.simpleEmitter.emit('correct-chain');
  }
  - this.updateWalletInfo(accounts, chainId);
  });
  this.connector.on('disconnect', (error) => {
  @@ -133,11 +146,6 @@ export default abstract class Layer2ChainWeb3Strategy
  this.onDisconnect();
  });
  await this.provider.enable();
  - this.web3.setProvider(this.provider as any);
  - this.#exchangeRateApi = await getSDK('ExchangeRate', this.web3);
  - this.#safesApi = await getSDK('Safes', this.web3);
  - this.#hubAuthApi = await getSDK('HubAuth', this.web3, config.hubURL);
  - this.updateWalletInfo(this.connector.accounts, this.connector.chainId);
  }
  private getTokenContractInfo(
  