2023-01-24 15:10:36 +01:00
|
|
|
import { Web3Provider } from '@ethersproject/providers';
|
2021-02-04 19:15:23 +01:00
|
|
|
import ensNetworkMap from 'ethereum-ens-network-map';
|
2022-07-12 16:30:31 +02:00
|
|
|
import { NETWORK_ID_TO_ETHERS_NETWORK_NAME_MAP } from '../../../../shared/constants/network';
|
2019-11-01 18:54:00 +01:00
|
|
|
|
2020-05-06 00:19:38 +02:00
|
|
|
export default class Ens {
|
2020-11-03 00:41:28 +01:00
|
|
|
static getNetworkEnsSupport(network) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return Boolean(ensNetworkMap[network]);
|
2019-11-01 18:54:00 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
constructor({ network, provider } = {}) {
|
2022-07-12 16:30:31 +02:00
|
|
|
const networkName = NETWORK_ID_TO_ETHERS_NETWORK_NAME_MAP[network];
|
|
|
|
const ensAddress = ensNetworkMap[network];
|
2023-01-24 15:10:36 +01:00
|
|
|
const ethProvider = new Web3Provider(provider, {
|
2022-07-12 16:30:31 +02:00
|
|
|
chainId: parseInt(network, 10),
|
|
|
|
name: networkName,
|
|
|
|
ensAddress,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2022-07-12 16:30:31 +02:00
|
|
|
this._ethProvider = ethProvider;
|
2019-11-01 18:54:00 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
lookup(ensName) {
|
2022-07-12 16:30:31 +02:00
|
|
|
return this._ethProvider.resolveName(ensName);
|
2019-11-01 18:54:00 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
reverse(address) {
|
2022-07-12 16:30:31 +02:00
|
|
|
return this._ethProvider.lookupAddress(address);
|
2019-11-01 18:54:00 +01:00
|
|
|
}
|
|
|
|
}
|