<commit_before>import ENS from './resolvers/ens';
import UNS from './resolvers/uns';
import { normalise } from './helpers';
import { isAddress } from '@/core/helpers/addressUtils.js';
const ETH_DEFAULT_ADDRESS = '0x0000000000000000000000000000000000000000';
export default class NameResolver {
  constructor(network, web3) {
    this.network = network;
    this.web3 = web3;
    this.ens = new ENS(this.network, this.web3);
    this.uns = new UNS(this.network, this.web3);
  }
  isValidName(name) {
    const splitName = name.split('.');
    if (splitName.length > 1) {
      name = normalise(name);
      return name.indexOf('.') > 0;
    }
    return true;
  }
  async resolveName(name) {
    name = normalise(name);
    let address = '';
    const ensAddress = await this.ens.resolveName(name);
    if (ensAddress === ETH_DEFAULT_ADDRESS) {
      const unsAddress = await this.uns.resolveName(name);
      address = unsAddress !== ETH_DEFAULT_ADDRESS ? unsAddress : '';
    } else {
      address = ensAddress;
    }

    if (isAddress(address)) {
      return address;
    }
    throw new Error('Invalid Address!');
  }
}<commit_msg>devop: 🔧 tweak the resolveName<commit_after>import ENS from './resolvers/ens';
import UNS from './resolvers/uns';
import { normalise } from './helpers';
import { isAddress } from '@/core/helpers/addressUtils.js';
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
export default class NameResolver {
  constructor(network, web3) {
    this.network = network;
    this.web3 = web3;
    this.ens = new ENS(this.network, this.web3);
    this.uns = new UNS(this.network, this.web3);
  }
  isValidName(name) {
    const splitName = name.split('.');
    if (splitName.length > 1) {
      name = normalise(name);
      return name.indexOf('.') > 0;
    }
    return false;
  }
  async resolveName(name) {
    if (!this.isValidName(name)) throw new Error('Invalid Address!');
    name = normalise(name);
    let address = await this.ens.resolveName(name);
    if (address === ZERO_ADDRESS) {
      address = await this.uns.resolveName(name);
    }
    if (isAddress(address) && address !== ZERO_ADDRESS) {
      return address;
    }
    throw new Error('Invalid Address!');
  }
}
{'fraction_non_alphanumeric': 0.13842696629213483, 'fraction_numerical': 0.043146067415730335, 'mean_word_length': 3.3056092843326885, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1346668', 'n_tokens_mistral': 777, 'n_tokens_neox': 697, 'n_words': 168}