Why call eth_accounts twice?
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
- Issue type
- Refactor
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript
- Domain
- frontend
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.
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
? `<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~~
- Dominant language
- JavaScript
- Stars
- 642
- Forks
- 369
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MetaMask/test-dapp
-
vvxg66w6tx Open
Difficulty 5/5 Over a week Newbie friendliness 1/100
-
Difficulty 3/5 1-2 days Newbie friendliness 20/100
-
Add EIP-7702 example Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
team-wallet-framework wf-project-standardization
Difficulty 4/5 3-5 days Newbie friendliness 42/100
All issues in MetaMask/test-dapp
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·