Skip to content

Commit

Permalink
[DT-902] fix: Ens.fetchAddress() to support ud Api as the provider wi…
Browse files Browse the repository at this point in the history
…th apiKey
  • Loading branch information
DChan0319 committed Sep 20, 2023
1 parent 01efdf0 commit 13470f8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default class Ens extends NamingService {
readonly registryContract: EthereumContract;
readonly nameWrapperContract: EthereumContract;
readonly baseRegistrarContract: EthereumContract;
readonly proxyServiceApiKey: string | undefined;

constructor(source?: EnsSource) {
super();
Expand All @@ -56,22 +57,23 @@ export default class Ens extends NamingService {
this.provider =
finalSource['provider'] ||
FetchProvider.factory(NamingServiceName.ENS, this.url);
this.proxyServiceApiKey = finalSource['proxyServiceApiKey'];

const registryAddress =
finalSource['registryAddress'] || EnsNetworkMap[this.network];
this.registryContract = new EthereumContract(
ensInterface,
registryAddress,
this.provider,
finalSource['proxyServiceApiKey'],
this.proxyServiceApiKey,
);

const nameWrapperAddress = this.determineNameWrapperAddress(this.network);
this.nameWrapperContract = new EthereumContract(
nameWrapperInterface,
nameWrapperAddress,
this.provider,
finalSource['proxyServiceApiKey'],
this.proxyServiceApiKey,
);

const baseRegistrarAddress = this.determineBaseRegistrarAddress(
Expand All @@ -81,7 +83,7 @@ export default class Ens extends NamingService {
baseRegistrarInterface,
baseRegistrarAddress,
this.provider,
finalSource['proxyServiceApiKey'],
this.proxyServiceApiKey,
);
}

Expand Down Expand Up @@ -214,6 +216,7 @@ export default class Ens extends NamingService {
resolverInterface(resolverAddress, EthCoinIndex),
resolverAddress,
this.provider,
this.proxyServiceApiKey,
);

return await this.resolverCallToName(resolverContract, nodeHash);
Expand Down Expand Up @@ -411,11 +414,14 @@ export default class Ens extends NamingService {
'@ensdomains/address-encoder',
'>= 0.1.x <= 0.2.x',
).formatsByCoinType;

const resolverContract = new EthereumContract(
resolverInterface(resolver, coinType),
resolver,
this.provider,
this.proxyServiceApiKey,
);

const nodeHash = this.namehash(domain);
const addr: string =
coinType !== EthCoinIndex
Expand All @@ -424,6 +430,7 @@ export default class Ens extends NamingService {
if (isNullAddress(addr)) {
return undefined;
}

// eslint-disable-next-line no-undef
const data = Buffer.from(addr.replace('0x', ''), 'hex');
return formatsByCoinType[coinType].encoder(data);
Expand Down

0 comments on commit 13470f8

Please sign in to comment.