From 668c0430c204c1233fc266b723ed1be308d5f3f1 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Wed, 24 Nov 2021 09:52:58 -0300
Subject: fix exchange selection

---
 .../taler-wallet-webextension/src/cta/Withdraw.tsx | 28 +++++++++++++++-------
 1 file changed, 19 insertions(+), 9 deletions(-)

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

diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
index eead51690..4703492cf 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
@@ -79,9 +79,11 @@ export function View({
 }: ViewProps): VNode {
   const needsReview = terms.status === "changed" || terms.status === "new";
 
-  const [switchingExchange, setSwitchingExchange] = useState<
-    string | undefined
-  >(undefined);
+  const [switchingExchange, setSwitchingExchange] = useState(false);
+  const [nextExchange, setNextExchange] = useState<string | undefined>(
+    undefined,
+  );
+
   const exchanges = knownExchanges.reduce(
     (prev, ex) => ({ ...prev, [ex.exchangeBaseUrl]: ex.exchangeBaseUrl }),
     {},
@@ -117,25 +119,33 @@ export function View({
       </section>
       {!reviewing && (
         <section>
-          {switchingExchange !== undefined ? (
+          {switchingExchange ? (
             <Fragment>
               <div>
                 <SelectList
                   label="Known exchanges"
                   list={exchanges}
-                  name=""
-                  onChange={onSwitchExchange}
+                  value={nextExchange}
+                  name="switchingExchange"
+                  onChange={setNextExchange}
                 />
               </div>
               <LinkSuccess
                 upperCased
-                onClick={() => onSwitchExchange(switchingExchange)}
+                onClick={() => {
+                  if (nextExchange !== undefined) {
+                    onSwitchExchange(nextExchange);
+                  }
+                  setSwitchingExchange(false);
+                }}
               >
-                {i18n.str`Confirm exchange selection`}
+                {nextExchange === undefined
+                  ? i18n.str`Cancel exchange selection`
+                  : i18n.str`Confirm exchange selection`}
               </LinkSuccess>
             </Fragment>
           ) : (
-            <LinkSuccess upperCased onClick={() => setSwitchingExchange("")}>
+            <LinkSuccess upperCased onClick={() => setSwitchingExchange(true)}>
               {i18n.str`Switch exchange`}
             </LinkSuccess>
           )}
-- 
cgit v1.2.3

