Skip to content

Commit

Permalink
Merge pull request #180 from enkryptcom/devop/cleanup-ens-ud
Browse files Browse the repository at this point in the history
Devop: tweak ENS and UD
  • Loading branch information
kvhnuke authored Oct 25, 2022
2 parents 7e22b81 + 2f8cafc commit 1669050
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 45 deletions.
23 changes: 23 additions & 0 deletions packages/extension/src/libs/name-resolver/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import NameResolver, { CoinType } from "@enkryptcom/name-resolution";
class GenericNameResolver {
nameResolver: NameResolver;

constructor() {
this.nameResolver = new NameResolver({
ens: { node: "https://nodes.mewapi.io/rpc/eth" },
});
}

async resolveName(name: string, coins: CoinType[]): Promise<string | null> {
let response: string | null = null;
for (const coin of coins) {
response = await this.nameResolver
.resolveAddress(name, coin)
.catch(() => null);
if (response) return response;
}
return response;
}
}

export { CoinType, GenericNameResolver };
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<script setup lang="ts">
import { ref, onMounted, PropType, computed, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import { debounce } from "lodash";
import SendHeader from "./components/send-header.vue";
import SendAddressInput from "./components/send-address-input.vue";
import SendFromContactsList from "./components/send-from-contacts-list.vue";
Expand Down Expand Up @@ -164,7 +165,7 @@ import getUiPath from "@/libs/utils/get-ui-path";
import Browser from "webextension-polyfill";
import { ProviderName } from "@/types/provider";
import PublicKeyRing from "@/libs/keyring/public-keyring";
import NameResolver, { CoinType } from "@enkryptcom/name-resolution";
import { GenericNameResolver, CoinType } from "@/libs/name-resolver";
const props = defineProps({
network: {
Expand All @@ -188,10 +189,8 @@ const loadingAsset = new Erc20Token({
const route = useRoute();
const router = useRouter();
const nameResolver = new NameResolver({
ens: { node: "https://nodes.mewapi.io/rpc/eth" },
});
const nameResolver = new GenericNameResolver();
const addressInputTo = ref();
const selected: string = route.params.id as string;
const accountAssets = ref<Erc20Token[]>([]);
Expand Down Expand Up @@ -219,8 +218,6 @@ const addressFrom = ref<string>(
const addressTo = ref<string>("");
const isLoadingAssets = ref(true);
const resolveTimeoutId = ref<ReturnType<typeof setTimeout> | null>(null);
const nativeBalance = computed(() => {
const accountIndex = props.accountInfo.activeAccounts.findIndex(
(acc) => acc.address === addressFrom.value
Expand Down Expand Up @@ -448,24 +445,16 @@ const inputAddressFrom = (text: string) => {
};
const inputAddressTo = async (text: string) => {
if (resolveTimeoutId.value) {
clearTimeout(resolveTimeoutId.value);
resolveTimeoutId.value = null;
}
resolveTimeoutId.value = setTimeout(async () => {
// Get the resolved address for the current network, or default to ETH
const resolved =
(await nameResolver
.resolveAddress(text, props.network.name as CoinType)
.catch(() => null)) ||
(await nameResolver.resolveAddress(text, "ETH").catch(() => null));
if (resolved) {
addressTo.value = resolved;
}
const debounceResolve = debounce(() => {
nameResolver
.resolveName(text, [props.network.name as CoinType, "ETH"])
.then((resolved) => {
if (resolved) {
addressTo.value = resolved;
}
});
}, 500);
debounceResolve();
addressTo.value = text;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<script setup lang="ts">
import { computed, onMounted, PropType, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import { debounce } from "lodash";
import CloseIcon from "@action/icons/common/close-icon.vue";
import SendAddressInput from "./components/send-address-input.vue";
import SendContactsList from "./components/send-contacts-list.vue";
Expand Down Expand Up @@ -124,7 +125,7 @@ import getUiPath from "@/libs/utils/get-ui-path";
import { ProviderName } from "@/types/provider";
import PublicKeyRing from "@/libs/keyring/public-keyring";
import { polkadotEncodeAddress } from "@enkryptcom/utils";
import NameResolver, { CoinType } from "@enkryptcom/name-resolution";
import { GenericNameResolver, CoinType } from "@/libs/name-resolver";
const props = defineProps({
network: {
Expand All @@ -139,9 +140,7 @@ const props = defineProps({
const route = useRoute();
const router = useRouter();
const nameResolver = new NameResolver({
ens: { node: "https://nodes.mewapi.io/rpc/eth" },
});
const nameResolver = new GenericNameResolver();
const addressInputTo = ref();
const addressInputFrom = ref();
Expand Down Expand Up @@ -315,25 +314,16 @@ const inputAddressFrom = (text: string) => {
};
const inputAddressTo = (text: string) => {
if (resolveTimeoutId.value) {
clearTimeout(resolveTimeoutId.value);
resolveTimeoutId.value = null;
}
resolveTimeoutId.value = setTimeout(async () => {
// Get the resolved address for the current network, then try for DOT, then KSM
const resolved =
(await nameResolver
.resolveAddress(text, props.network.name as CoinType)
.catch(() => null)) ||
(await nameResolver.resolveAddress(text, "DOT").catch(() => null)) ||
(await nameResolver.resolveAddress(text, "KSM").catch(() => null));
if (resolved) {
addressTo.value = resolved;
}
const debounceResolve = debounce(() => {
nameResolver
.resolveName(text, [props.network.name as CoinType, "DOT", "KSM"])
.then((resolved) => {
if (resolved) {
addressTo.value = resolved;
}
});
}, 500);
debounceResolve();
addressTo.value = text;
};
Expand Down

3 comments on commit 1669050

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.