Skip to content

Commit

Permalink
Merge branch 'develop' into chromedriver-update
Browse files Browse the repository at this point in the history
  • Loading branch information
seaona committed Sep 13, 2022
2 parents ff79925 + ea947ed commit b364f98
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 199 deletions.
1 change: 1 addition & 0 deletions app/manifest/v2/chrome.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"content_security_policy": "frame-ancestors 'none'",
"externally_connectable": {
"matches": ["https://metamask.io/*"],
"ids": ["*"]
Expand Down
3 changes: 3 additions & 0 deletions app/manifest/v3/chrome.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"content_security_policy": {
"extension_pages": "default-src 'self'; frame-ancestors 'none'"
},
"externally_connectable": {
"matches": ["https://metamask.io/*"],
"ids": ["*"]
Expand Down
3 changes: 0 additions & 3 deletions app/scripts/controllers/detect-tokens.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Web3 from 'web3';
import { warn } from 'loglevel';
import { MINUTE } from '../../../shared/constants/time';
import { MAINNET_CHAIN_ID } from '../../../shared/constants/network';
Expand Down Expand Up @@ -112,7 +111,6 @@ export default class DetectTokensController {
: tokenList;

const tokensToDetect = [];
this.web3.setProvider(this._network._provider);
for (const tokenAddress in tokenListUsed) {
if (
!this.tokenAddresses.find(({ address }) =>
Expand Down Expand Up @@ -220,7 +218,6 @@ export default class DetectTokensController {
return;
}
this._network = network;
this.web3 = new Web3(network._provider);
this._network.store.subscribe(() => {
if (this.chainId !== this.getChainIdFromNetworkStore(network)) {
this.restartTokenDetection();
Expand Down
42 changes: 22 additions & 20 deletions app/scripts/lib/account-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import EthQuery from 'eth-query';
import { ObservableStore } from '@metamask/obs-store';
import log from 'loglevel';
import pify from 'pify';
import Web3 from 'web3';
import { ethers } from 'ethers';
import SINGLE_CALL_BALANCES_ABI from 'single-call-balance-checker-abi';
import {
MAINNET_CHAIN_ID,
Expand Down Expand Up @@ -41,7 +41,6 @@ import {
SINGLE_CALL_BALANCES_ADDRESS_FANTOM,
SINGLE_CALL_BALANCES_ADDRESS_ARBITRUM,
} from '../constants/contracts';
import { bnToHex } from './util';

/**
* This module is responsible for tracking any number of accounts and caching their current balances & transaction
Expand Down Expand Up @@ -85,7 +84,7 @@ export default class AccountTracker {
this._updateForBlock = this._updateForBlock.bind(this);
this.getCurrentChainId = opts.getCurrentChainId;

this.web3 = new Web3(this._provider);
this.ethersProvider = new ethers.providers.Web3Provider(this._provider);
}

start() {
Expand Down Expand Up @@ -336,26 +335,29 @@ export default class AccountTracker {
*/
async _updateAccountsViaBalanceChecker(addresses, deployedContractAddress) {
const { accounts } = this.store.getState();
this.web3.setProvider(this._provider);
const ethContract = this.web3.eth
.contract(SINGLE_CALL_BALANCES_ABI)
.at(deployedContractAddress);
const ethBalance = ['0x0'];

ethContract.balances(addresses, ethBalance, (error, result) => {
if (error) {
log.warn(
`MetaMask - Account Tracker single call balance fetch failed`,
error,
);
Promise.all(addresses.map(this._updateAccount.bind(this)));
return;
}
this.ethersProvider = new ethers.providers.Web3Provider(this._provider);

const ethContract = await new ethers.Contract(
deployedContractAddress,
SINGLE_CALL_BALANCES_ABI,
this.ethersProvider,
);
const ethBalance = ['0x0000000000000000000000000000000000000000'];

try {
const balances = await ethContract.balances(addresses, ethBalance);

addresses.forEach((address, index) => {
const balance = result[index] ? bnToHex(result[index]) : '0x0';
const balance = balances[index] ? balances[index].toHexString() : '0x0';
accounts[address] = { address, balance };
});
this.store.updateState({ accounts });
});
} catch (error) {
log.warn(
`MetaMask - Account Tracker single call balance fetch failed`,
error,
);
Promise.all(addresses.map(this._updateAccount.bind(this)));
}
}
}
109 changes: 57 additions & 52 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2641,6 +2641,7 @@
"@metamask/controllers>isomorphic-fetch": true,
"@metamask/controllers>multiformats": true,
"@metamask/controllers>nanoid": true,
"@metamask/controllers>web3": true,
"@metamask/controllers>web3-provider-engine": true,
"@metamask/metamask-eth-abis": true,
"browserify>buffer": true,
Expand All @@ -2661,8 +2662,7 @@
"jsonschema": true,
"punycode": true,
"single-call-balance-checker-abi": true,
"uuid": true,
"web3": true
"uuid": true
}
},
"@metamask/controllers>abort-controller": {
Expand Down Expand Up @@ -2805,6 +2805,22 @@
"crypto.getRandomValues": true
}
},
"@metamask/controllers>web3": {
"globals": {
"Web3": "write",
"XMLHttpRequest": true,
"clearTimeout": true,
"console.error": true,
"setTimeout": true
},
"packages": {
"@metamask/controllers>web3>bignumber.js": true,
"@metamask/controllers>web3>crypto-js": true,
"@metamask/controllers>web3>utf8": true,
"@metamask/controllers>web3>xhr2-cookies": true,
"browserify>buffer": true
}
},
"@metamask/controllers>web3-provider-engine": {
"globals": {
"WebSocket": true,
Expand Down Expand Up @@ -2943,6 +2959,38 @@
"browserify>process": true
}
},
"@metamask/controllers>web3>bignumber.js": {
"globals": {
"define": true
},
"packages": {
"browserify>crypto-browserify": true
}
},
"@metamask/controllers>web3>crypto-js": {
"globals": {
"define": true
}
},
"@metamask/controllers>web3>utf8": {
"globals": {
"define": true
}
},
"@metamask/controllers>web3>xhr2-cookies": {
"globals": {
"console.warn": true
},
"packages": {
"browserify>buffer": true,
"browserify>https-browserify": true,
"browserify>os-browserify": true,
"browserify>process": true,
"browserify>stream-http": true,
"browserify>url": true,
"pubnub>superagent>cookiejar": true
}
},
"@metamask/eth-ledger-bridge-keyring": {
"globals": {
"addEventListener": true,
Expand Down Expand Up @@ -5754,6 +5802,11 @@
"browserify>buffer": true
}
},
"pubnub>superagent>cookiejar": {
"globals": {
"console.warn": true
}
},
"pump": {
"packages": {
"browserify>browser-resolve": true,
Expand Down Expand Up @@ -6308,18 +6361,7 @@
},
"web3": {
"globals": {
"Web3": "write",
"XMLHttpRequest": true,
"clearTimeout": true,
"console.error": true,
"setTimeout": true
},
"packages": {
"browserify>buffer": true,
"web3>bignumber.js": true,
"web3>crypto-js": true,
"web3>utf8": true,
"web3>xhr2-cookies": true
"XMLHttpRequest": true
}
},
"web3-stream-provider": {
Expand All @@ -6338,43 +6380,6 @@
"msCrypto": true
}
},
"web3>bignumber.js": {
"globals": {
"define": true
},
"packages": {
"browserify>crypto-browserify": true
}
},
"web3>crypto-js": {
"globals": {
"define": true
}
},
"web3>utf8": {
"globals": {
"define": true
}
},
"web3>xhr2-cookies": {
"globals": {
"console.warn": true
},
"packages": {
"browserify>buffer": true,
"browserify>https-browserify": true,
"browserify>os-browserify": true,
"browserify>process": true,
"browserify>stream-http": true,
"browserify>url": true,
"web3>xhr2-cookies>cookiejar": true
}
},
"web3>xhr2-cookies>cookiejar": {
"globals": {
"console.warn": true
}
},
"webextension-polyfill": {
"globals": {
"browser": true,
Expand All @@ -6390,4 +6395,4 @@
}
}
}
}
}
Loading

0 comments on commit b364f98

Please sign in to comment.