From 829a59e1a24d6a99ce7554d28acfd05f21baeaf8 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Mon, 22 Nov 2021 17:34:27 -0300
Subject: add exchange feature

---
 .../src/wallet/ProviderAddPage.tsx                 | 31 +++-------------------
 1 file changed, 3 insertions(+), 28 deletions(-)

(limited to 'packages/taler-wallet-webextension/src/wallet/ProviderAddPage.tsx')

diff --git a/packages/taler-wallet-webextension/src/wallet/ProviderAddPage.tsx b/packages/taler-wallet-webextension/src/wallet/ProviderAddPage.tsx
index 41852e38c..16f239674 100644
--- a/packages/taler-wallet-webextension/src/wallet/ProviderAddPage.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/ProviderAddPage.tsx
@@ -31,6 +31,7 @@ import {
   LightText,
   SmallLightText,
 } from "../components/styled/index";
+import { queryToSlashConfig } from "../utils";
 import * as wxApi from "../wxApi";
 
 interface Props {
@@ -38,45 +39,19 @@ interface Props {
   onBack: () => void;
 }
 
-function getJsonIfOk(r: Response) {
-  if (r.ok) {
-    return r.json();
-  } else {
-    if (r.status >= 400 && r.status < 500) {
-      throw new Error(`URL may not be right: (${r.status}) ${r.statusText}`);
-    } else {
-      throw new Error(
-        `Try another server: (${r.status}) ${
-          r.statusText || "internal server error"
-        }`,
-      );
-    }
-  }
-}
-
 export function ProviderAddPage({ onBack }: Props): VNode {
   const [verifying, setVerifying] = useState<
     | { url: string; name: string; provider: BackupBackupProviderTerms }
     | undefined
   >(undefined);
 
-  async function getProviderInfo(
-    url: string,
-  ): Promise<BackupBackupProviderTerms> {
-    return fetch(new URL("config", url).href)
-      .catch((e) => {
-        throw new Error(`Network error`);
-      })
-      .then(getJsonIfOk);
-  }
-
   if (!verifying) {
     return (
       <SetUrlView
         onCancel={onBack}
-        onVerify={(url) => getProviderInfo(url)}
+        onVerify={(url) => queryToSlashConfig(url)}
         onConfirm={(url, name) =>
-          getProviderInfo(url)
+          queryToSlashConfig<BackupBackupProviderTerms>(url)
             .then((provider) => {
               setVerifying({ url, name, provider });
             })
-- 
cgit v1.2.3

