From eac6b50ad393465fdc3ce206e53a0a7626737a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Mon, 10 Mar 2025 16:08:06 +0100 Subject: [PATCH] fix: network issues with drep images and adahandle --- .../frontend/src/utils/drepSearchPhraseProcessor.ts | 12 ++++++------ govtool/frontend/src/utils/getImageSha.ts | 7 ++++++- govtool/frontend/src/utils/isValidFormat.ts | 10 ++++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/govtool/frontend/src/utils/drepSearchPhraseProcessor.ts b/govtool/frontend/src/utils/drepSearchPhraseProcessor.ts index 27d77a62a..d50763490 100644 --- a/govtool/frontend/src/utils/drepSearchPhraseProcessor.ts +++ b/govtool/frontend/src/utils/drepSearchPhraseProcessor.ts @@ -15,12 +15,6 @@ export const dRepSearchPhraseProcessor = async (phrase: string) => { let drepIDPhrase = phrase; try { - const adaHandleCIP105DRepId = - await adaHandleService.getAdaHandleCIP105DRepId(phrase); - if (adaHandleCIP105DRepId) { - return adaHandleCIP105DRepId; - } - if ( drepIDPhrase.startsWith("drep_script") || drepIDPhrase.startsWith("drep") @@ -33,6 +27,12 @@ export const dRepSearchPhraseProcessor = async (phrase: string) => { return drepIDPhrase.slice(2); } + const adaHandleCIP105DRepId = + await adaHandleService.getAdaHandleCIP105DRepId(phrase); + if (adaHandleCIP105DRepId) { + return adaHandleCIP105DRepId; + } + return drepIDPhrase; } catch (e) { return phrase; diff --git a/govtool/frontend/src/utils/getImageSha.ts b/govtool/frontend/src/utils/getImageSha.ts index 31af478f3..18b80550e 100644 --- a/govtool/frontend/src/utils/getImageSha.ts +++ b/govtool/frontend/src/utils/getImageSha.ts @@ -6,7 +6,12 @@ */ export const getImageSha = async (imageUrl: string) => { try { - const response = await fetch(imageUrl); + const response = await fetch(imageUrl, { + // Required to not being blocked by APIs that require a User-Agent + headers: { + "User-Agent": "GovTool/image-sha", + }, + }); if (!response.ok) throw new Error(`Failed to fetch image: ${response.statusText}`); diff --git a/govtool/frontend/src/utils/isValidFormat.ts b/govtool/frontend/src/utils/isValidFormat.ts index 3f49710ef..43a6ef003 100644 --- a/govtool/frontend/src/utils/isValidFormat.ts +++ b/govtool/frontend/src/utils/isValidFormat.ts @@ -48,16 +48,18 @@ export async function isReceivingAddress(address?: string) { if (!address) { return true; } + + const receivingAddress = Address.from_bech32(address); + if (receivingAddress) { + return true; + } const isValidAdaHandle = await adaHandleService.isValidAdaHandle(address); if (isValidAdaHandle) { return true; } - const receivingAddress = Address.from_bech32(address); - return receivingAddress - ? true - : i18n.t("forms.errors.mustBeReceivingAddress"); + return i18n.t("forms.errors.mustBeReceivingAddress"); } catch (e) { return i18n.t("forms.errors.mustBeReceivingAddress"); }