commit 61a456c21ee1e15e88bd1215e5afe69d7027d3a7
parent ab5f1771a65b39a61a8e8c4e8ed08f574507f059
Author: Sebastian <sebasjm@gmail.com>
Date: Tue, 6 May 2025 16:14:04 -0300
fix error reporting and http client
Diffstat:
2 files changed, 42 insertions(+), 15 deletions(-)
diff --git a/packages/taler-wallet-webextension/src/wallet/AddExchange/state.ts b/packages/taler-wallet-webextension/src/wallet/AddExchange/state.ts
@@ -81,7 +81,9 @@ export function useComponentState({ onBack, currency, noDebounce }: Props): Recu
* │ Types have separate declarations of a private property '_isCancelled'.
*
*/
- const api = new TalerExchangeHttpClient(baseUrl.href, new BrowserFetchHttpLib() as any);
+ const api = new TalerExchangeHttpClient(baseUrl.href, {
+ httpClient: new BrowserFetchHttpLib(),
+ });
const config = await api.getConfig()
if (config.type === "fail") {
return opKnownFailure("not-found" as const)
diff --git a/packages/taler-wallet-webextension/src/wallet/QrReader.tsx b/packages/taler-wallet-webextension/src/wallet/QrReader.tsx
@@ -250,9 +250,22 @@ export function QrReaderPage({ onDetected }: Props): VNode {
if (str) {
const uri = parseTalerUri(str.toLowerCase());
if (!uri) {
- setError(
- i18n.str`URI is not valid. Taler URI should start with "taler://"`,
- );
+ const lstr = str.toLowerCase();
+ if (lstr.startsWith("taler://")) {
+ if (lstr.length > 8) {
+ const withoutTaler = lstr.substring(8);
+ const idx = withoutTaler.indexOf("/");
+ const action =
+ idx === -1 ? withoutTaler : withoutTaler.substring(0, idx);
+ setError(
+ i18n.str`URI is not valid. Unsupported Taler-action "${action}"`,
+ );
+ }
+ } else {
+ setError(
+ i18n.str`URI is not valid. Taler URI should start with "taler://"`,
+ );
+ }
setValue(str);
return;
}
@@ -274,11 +287,24 @@ export function QrReaderPage({ onDetected }: Props): VNode {
function onChange(str: string) {
if (str) {
- const uri = parseTalerUri(str.toLowerCase());
+ const uri = parseTalerUri(str);
if (!uri) {
- setError(
- i18n.str`URI is not valid. Taler URI should start with "taler://"`,
- );
+ const lstr = str.toLowerCase();
+ if (lstr.startsWith("taler://")) {
+ if (lstr.length > 8) {
+ const withoutTaler = lstr.substring(8);
+ const idx = withoutTaler.indexOf("/");
+ const action =
+ idx === -1 ? withoutTaler : withoutTaler.substring(0, idx);
+ setError(
+ i18n.str`URI is not valid. Unsupported Taler-action "${action}"`,
+ );
+ }
+ } else {
+ setError(
+ i18n.str`URI is not valid. Taler URI should start with "taler://"`,
+ );
+ }
setValue(str);
} else {
setError(i18n.str`checking...`);
@@ -449,7 +475,7 @@ export function QrReaderPage({ onDetected }: Props): VNode {
</Container>
);
}
-const httpFetch: any = new BrowserFetchHttpLib();
+const httpClient = new BrowserFetchHttpLib();
async function testValidUri(
uri: TalerUri,
@@ -541,10 +567,9 @@ async function checkExchangeUrl(
return i18n.str`The exchange URL should end with '/'`;
}
try {
- const config = await new TalerExchangeHttpClient(
- url.href,
- httpFetch,
- ).getConfig();
+ const config = await new TalerExchangeHttpClient(url.href, {
+ httpClient,
+ }).getConfig();
if (config.type === "ok") {
return undefined;
} else {
@@ -581,7 +606,7 @@ async function checkMerchantUrl(
try {
const config = await new TalerMerchantInstanceHttpClient(
url.href,
- httpFetch,
+ httpClient,
).getConfig();
if (config.type === "ok") {
return undefined;
@@ -619,7 +644,7 @@ async function checkBankUrl(
try {
const config = await new TalerCoreBankHttpClient(
url.href,
- httpFetch,
+ httpClient,
).getConfig();
if (config.type === "ok") {
return undefined;