poanetwork / poa-dapps-voting

POA Network Governance Dapp
https://voting.poa.network
GNU General Public License v3.0
26 stars 54 forks source link

Call `window.ethereum.enable` only when that's really needed #209

Closed varasev closed 4 years ago

varasev commented 4 years ago

Problem: For a user who has installed MetaMask and opened the Voting DApp for the first time in the current browser's session, the DApp asks permissions to get access to the list of accounts in MetaMask. But the app doesn't need to know the list of user's accounts until validator's Voting Key is really needed for some operation.

Solution: call window.ethereum.enable only when DApp requires Voting Key to take some action which supposes transaction signing (when the user gives their vote for a ballot, finalizes a ballot, or goes to New Ballot page).

Note that some logic in the current implementation depends on the current votingKey and miningKey (e.g., contractsStore.getBallotsLimits uses the miningKey), so after the user clicks Connect in the above window, the current DApp's page should be reloaded to retrieve the data which depend on the keys.

varasev commented 4 years ago

Done in https://github.com/poanetwork/poa-dapps-voting/pull/213.