<commit_before>import detectEthereumProvider from '@metamask/detect-provider';
import Web3 from 'web3';
import { NetworkSymbol } from './types';
import WalletConnectProvider from '@walletconnect/web3-provider';
import WalletConnectQRCodeModal from '@walletconnect/qrcode-modal';
import config from '../../config/environment';
import CustomStorageWalletConnect, {
  clearWalletConnectStorage,
} from '../wc-connector';
import { Emitter, SimpleEmitter } from '../events';
import { WalletProviderId } from '../wallet-providers';
import { action } from '@ember/object';

const GET_PROVIDER_STORAGE_KEY = (chainId: string | number) =>
  `cardstack-chain-${chainId}-provider`;
const WALLET_CONNECT_BRIDGE = 'https://safe-walletconnect.gnosis.io/';

interface ConnectionManagerOptions {
  chainId: number;
  networkSymbol: NetworkSymbol;
}

type ConnectionManagerEvents =
  | 'connected'
  | 'disconnected'
  | 'incorrect-chain'
  | 'error';

const BROADCAST_CHANNEL_MESSAGES = {
  DISCONNECTED: 'DISCONNECTED',
} as const;

export abstract class ConnectionManager
  implements Emitter<ConnectionManagerEvents> {
  web3: Web3 | undefined;
  networkSymbol: NetworkSymbol;
  chainId: number;
  simpleEmitter: SimpleEmitter;
  broadcastChannel: BroadcastChannel;
  protected provider: any;
  abstract providerId: WalletProviderId;

  constructor(options: ConnectionManagerOptions) {
    this.networkSymbol = options.networkSymbol;
    this.chainId = options.chainId;
    this.simpleEmitter = new SimpleEmitter();<commit_msg>basic docs<commit_after>import detectEthereumProvider from '@metamask/detect-provider';
import Web3 from 'web3';
import { NetworkSymbol } from './types';
import WalletConnectProvider from '@walletconnect/web3-provider';
import WalletConnectQRCodeModal from '@walletconnect/qrcode-modal';
import config from '../../config/environment';
import CustomStorageWalletConnect, {
  clearWalletConnectStorage,
} from '../wc-connector';
import { Emitter, SimpleEmitter } from '../events';
import { WalletProviderId } from '../wallet-providers';
import { action } from '@ember/object';

const GET_PROVIDER_STORAGE_KEY = (chainId: string | number) =>
  `cardstack-chain-${chainId}-provider`;
const WALLET_CONNECT_BRIDGE = 'https://safe-walletconnect.gnosis.io/';

interface ConnectionManagerOptions {
  chainId: number;
  networkSymbol: NetworkSymbol;
}

type ConnectionManagerEvents =
  | 'connected'
  | 'disconnected'
  | 'incorrect-chain'
  | 'error';

const BROADCAST_CHANNEL_MESSAGES = {
  DISCONNECTED: 'DISCONNECTED',
} as const;

/**
 * # ConnectionManager
 * This class instantiates a web3 provider given a WalletProviderId. It then handles the EIP-1193
 * events that come from the web3 provider and filters them for events that we want to handle
 * in the Dapp:
 *
 * - connected: A wallet is connected, or the address is changed
 * - disconnected: A wallet is disconnected
 * - incorrect-chain: A wallet is connected to the wrong chain
 *
 * It handles cross-tab communication and persistence of connection information across refreshes.
 * This class does not, at the moment, store any state used directly by the UI besides providerId.
 */
export abstract class ConnectionManager
  implements Emitter<ConnectionManagerEvents> {
  web3: Web3 | undefined;
  networkSymbol: NetworkSymbol;
  chainId: number;
  simpleEmitter: SimpleEmitter;
  broadcastChannel: BroadcastChannel;
  protected provider: any;
  abstract providerId: WalletProviderId;

  constructor(options: ConnectionManagerOptions) {
    this.networkSymbol = options.networkSymbol;
    this.chainId = options.chainId;
    this.simpleEmitter = new SimpleEmitter();
{'fraction_non_alphanumeric': 0.10140148392415499, 'fraction_numerical': 0.004396812311074471, 'mean_word_length': 5.265060240963855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1466137', 'n_tokens_mistral': 1020, 'n_tokens_neox': 1032, 'n_words': 289}