Skip to content

Commit

Permalink
chore: remove @metamask/ethjs-contract & @metamask/ethjs-query
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptodev-2s committed Jan 13, 2025
1 parent c54a5c9 commit f43efd9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
44 changes: 29 additions & 15 deletions app/scripts/lib/ens-ipfs/resolver.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
import namehash from 'eth-ens-namehash';
import Eth from '@metamask/ethjs-query';
import EthContract from '@metamask/ethjs-contract';
import contentHash from '@ensdomains/content-hash';
import { Web3Provider } from '@ethersproject/providers';
import { Contract } from '@ethersproject/contracts';
import registryAbi from './contracts/registry';
import resolverAbi from './contracts/resolver';

export default async function resolveEnsToIpfsContentId({ provider, name }) {
const eth = new Eth(provider);
const hash = namehash.hash(name);
const contract = new EthContract(eth);

// lookup registry
const chainId = Number.parseInt(await eth.net_version(), 10);
const chainId = Number.parseInt(
await provider.request({ method: 'net_version' }),
10,
);
const registryAddress = getRegistryForChainId(chainId);
if (!registryAddress) {
throw new Error(
`EnsIpfsResolver - no known ens-ipfs registry for chainId "${chainId}"`,
);
}
const Registry = contract(registryAbi).at(registryAddress);
const web3Provider = new Web3Provider(provider);
const registryContract = new Contract(
registryAddress,
registryAbi,
web3Provider,
);
// lookup resolver
const resolverLookupResult = await Registry.resolver(hash);
const resolverAddress = resolverLookupResult[0];
const resolverAddress = await registryContract.resolver(hash);
if (hexValueIsEmpty(resolverAddress)) {
throw new Error(`EnsIpfsResolver - no resolver found for name "${name}"`);
}
const Resolver = contract(resolverAbi).at(resolverAddress);
const resolverContract = new Contract(
resolverAddress,
resolverAbi,
web3Provider,
);

const isEIP1577Compliant = await Resolver.supportsInterface('0xbc1c58d1');
const isLegacyResolver = await Resolver.supportsInterface('0xd8389dc5');
if (isEIP1577Compliant[0]) {
const contentLookupResult = await Resolver.contenthash(hash);
const isEIP1577Compliant = await resolverContract.supportsInterface(
'0xbc1c58d1',
);
const isLegacyResolver = await resolverContract.supportsInterface(
'0xd8389dc5',
);
if (isEIP1577Compliant) {
const contentLookupResult = await resolverContract.contenthash(hash);
const rawContentHash = contentLookupResult[0];
let decodedContentHash = contentHash.decode(rawContentHash);
const type = contentHash.getCodec(rawContentHash);
Expand All @@ -41,9 +55,9 @@ export default async function resolveEnsToIpfsContentId({ provider, name }) {

return { type, hash: decodedContentHash };
}
if (isLegacyResolver[0]) {
if (isLegacyResolver) {
// lookup content id
const contentLookupResult = await Resolver.content(hash);
const contentLookupResult = await resolverContract.content(hash);
const content = contentLookupResult[0];
if (hexValueIsEmpty(content)) {
throw new Error(
Expand Down
16 changes: 4 additions & 12 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import LatticeKeyring from 'eth-lattice-keyring';
import { rawChainData } from 'eth-chainlist';
import { MetaMaskKeyring as QRHardwareKeyring } from '@keystonehq/metamask-airgapped-keyring';
import EthQuery from '@metamask/eth-query';
import EthJSQuery from '@metamask/ethjs-query';
import { nanoid } from 'nanoid';
import { captureException } from '@sentry/browser';
import { AddressBookController } from '@metamask/address-book-controller';
Expand Down Expand Up @@ -5400,18 +5399,11 @@ export default class MetamaskController extends EventEmitter {
}

async estimateGas(estimateGasParams) {
return new Promise((resolve, reject) => {
return new EthJSQuery(this.provider).estimateGas(
estimateGasParams,
(err, res) => {
if (err) {
return reject(err);
}

return resolve(res.toString(16));
},
);
const result = await this.provider.request({
method: 'eth_estimateGas',
params: [estimateGasParams],
});
return result.toString(16);
}

handleWatchAssetRequest = ({ asset, type, origin, networkClientId }) => {
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,6 @@
"@metamask/eth-token-tracker": "^9.0.0",
"@metamask/eth-trezor-keyring": "^6.0.0",
"@metamask/etherscan-link": "^3.0.0",
"@metamask/ethjs-contract": "^0.4.1",
"@metamask/ethjs-query": "^0.7.1",
"@metamask/gas-fee-controller": "^22.0.1",
"@metamask/jazzicon": "^2.0.0",
"@metamask/json-rpc-engine": "^10.0.0",
Expand Down
2 changes: 0 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26603,8 +26603,6 @@ __metadata:
"@metamask/eth-token-tracker": "npm:^9.0.0"
"@metamask/eth-trezor-keyring": "npm:^6.0.0"
"@metamask/etherscan-link": "npm:^3.0.0"
"@metamask/ethjs-contract": "npm:^0.4.1"
"@metamask/ethjs-query": "npm:^0.7.1"
"@metamask/forwarder": "npm:^1.1.0"
"@metamask/gas-fee-controller": "npm:^22.0.1"
"@metamask/jazzicon": "npm:^2.0.0"
Expand Down

0 comments on commit f43efd9

Please sign in to comment.