Skip to content

Why call eth_accounts twice? #413

Description

@wenhui7788
const initializeProvider = async () => {
  initializeContracts();
  updateFormElements();

  if (isMetaMaskInstalled()) {
    globalContext.provider.autoRefreshOnNetworkChange = false;
    await getNetworkAndChainId();

    globalContext.provider.on('chainChanged', handleNewChain);
    globalContext.provider.on('chainChanged', handleEIP1559Support);
    globalContext.provider.on('networkChanged', handleNewNetwork);
    globalContext.provider.on('accountsChanged', handleNewAccounts);
    globalContext.provider.on('accountsChanged', handleEIP1559Support);

    try {
      const newAccounts = await globalContext.provider.request({
        method: 'eth_accounts',
      });
      handleNewAccounts(newAccounts);
    } catch (err) {
      console.error('Error on init when getting accounts', err);
    }
  } else {
    handleScrollTo();
  }
};

export const setActiveProviderDetail = async (providerDetail) => {
  closeProvider();
  console.log(providerDetail);
  // When the extension is not installed the providerDetails comes in undefined
  // but because the SDK is already init the window.ethereum has been injected
  // this doesn't mean we can refer to it directly as the connection may have
  // not been approved which is there uuid comes in as empty
  if (!providerDetail || providerDetail.info.uuid === '') {
    return;
  }
  globalContext.provider = providerDetail.provider;
  await initializeProvider();

  try {
    const newAccounts = await globalContext.provider.request({
      method: 'eth_accounts',
    });
    handleNewAccounts(newAccounts);
  } catch (err) {
    console.error('Error on init when getting accounts', err);
  }

  const { uuid, name, icon } = providerDetail.info;
  activeProviderUUIDResult.innerText = uuid;
  activeProviderNameResult.innerText = name;
  activeProviderIconResult.innerHTML = icon
    ? `<img src="${icon}" height="90" width="90" />`
    : '';
  updateFormElements();
};

    const newAccounts = await globalContext.provider.request({
      method: 'eth_accounts',
    });
    handleNewAccounts(newAccounts);

Is this code duplicated?Why call eth_accounts twice?thank you~~

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions