1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 18:41:38 +01:00
metamask-extension/app/scripts/controllers/ens/ens.js

29 lines
819 B
JavaScript
Raw Normal View History

import { ethers } from 'ethers';
import ensNetworkMap from 'ethereum-ens-network-map';
import { NETWORK_ID_TO_ETHERS_NETWORK_NAME_MAP } from '../../../../shared/constants/network';
export default class Ens {
2020-11-03 00:41:28 +01:00
static getNetworkEnsSupport(network) {
return Boolean(ensNetworkMap[network]);
}
2020-11-03 00:41:28 +01:00
constructor({ network, provider } = {}) {
const networkName = NETWORK_ID_TO_ETHERS_NETWORK_NAME_MAP[network];
const ensAddress = ensNetworkMap[network];
const ethProvider = new ethers.providers.Web3Provider(provider, {
chainId: parseInt(network, 10),
name: networkName,
ensAddress,
});
this._ethProvider = ethProvider;
}
2020-11-03 00:41:28 +01:00
lookup(ensName) {
return this._ethProvider.resolveName(ensName);
}
2020-11-03 00:41:28 +01:00
reverse(address) {
return this._ethProvider.lookupAddress(address);
}
}