Why call eth_accounts twice?
- Dominant language
- JavaScript
- Stars
- 642
- Forks
- 369
- PR merge metrics
- No merged PRs in 30d
Description
```
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
? ``
: '';
updateFormElements();
};
```
```
const newAccounts = await globalContext.provider.request({
method: 'eth_accounts',
});
handleNewAccounts(newAccounts);
```
Is this code duplicated?Why call eth_accounts twice?thank you~~
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing initializeProvider and setActiveProviderDetail, then compare each eth_accounts request and its call to handleNewAccounts. Determine whether the repeated request is necessary and document or remove the duplication without changing account initialization behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100