-
-
Notifications
You must be signed in to change notification settings - Fork 368
Open
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~~
Metadata
Metadata
Assignees
Labels
No labels