on master help sign in
Merge pull request #950 from urbit/t/brave-wallet-accounts

eth: update Ethereum Provider integration

commit54f58895a149a888181ea76464593c7d802641cd authortomholford <16504501+tomholford@users.noreply.github.com> dateThu 10 Feb 2022, 17:21 (5 years ago) parent3628fc58fb988e
2 files changed+13−6
src/views/Login/LoginSelector.tsx+10−5 src/views/Login/Metamask.js+3−1
src/views/Login/LoginSelector.tsx+10−5
@@ -79,14 +79,19 @@ export default function LoginSelector({
7979
8080 const selectMetamask = useCallback(async () => {
8181 try {
82+ if (!window.ethereum) {
83+ throw new Error(
84+ 'Device does not have an Ethereum provider available (is Metamask or Brave Wallet installed?)'
85+ );
86+ }
8287 setMetamask(true);
8388 setMetamaskSelected(true);
84− const accounts = await (window as any).ethereum.send(
85− 'eth_requestAccounts'
86− );
87− const wallet = new MetamaskWallet(accounts.result[0]);
89+ const accounts = await window.ethereum.request({
90+ method: 'eth_requestAccounts',
91+ });
92+ const wallet = new MetamaskWallet(accounts[0]);
8893
89− const web3 = new Web3((window as any).ethereum);
94+ const web3 = new Web3(window.ethereum);
9095 const authToken = await getAuthToken({
9196 address: wallet.address,
9297 walletType: WALLET_TYPES.METAMASK,
src/views/Login/Metamask.js+3−1
@@ -33,7 +33,9 @@ export default function Metamask({ className, goHome }) {
3333 const onSubmit = useCallback(async () => {
3434 try {
3535 setMetamask(true);
36− const accounts = await window.ethereum.send('eth_requestAccounts');
36+ const accounts = await window.ethereum.request({
37+ method: 'eth_requestAccounts',
38+ });
3739 const wallet = new MetamaskWallet(accounts.result[0]);
3840
3941 const web3 = new Web3(window.ethereum);