From 38d62d5bdf88d3e22ce7af7051c3ce2682e54ae0 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Thu, 13 Apr 2023 13:25:03 +0200 Subject: [PATCH] Simplify conditional rendering --- pages/multi/[address]/index.tsx | 144 +++++++++++++++----------------- 1 file changed, 66 insertions(+), 78 deletions(-) diff --git a/pages/multi/[address]/index.tsx b/pages/multi/[address]/index.tsx index ab1108b..4b8e0ab 100644 --- a/pages/multi/[address]/index.tsx +++ b/pages/multi/[address]/index.tsx @@ -18,6 +18,8 @@ import StackableContainer from "../../../components/layout/StackableContainer"; import { useAppContext } from "../../../context/AppContext"; import { getMultisigAccount } from "../../../lib/multisigHelpers"; +type TxView = "select" | "send" | "delegate" | "undelegate" | "redelegate" | "claimRewards"; + function participantPubkeysFromMultisig( multisig: MultisigThresholdPubkey, ): readonly SinglePubkey[] { @@ -26,11 +28,7 @@ function participantPubkeysFromMultisig( const Multipage = () => { const { state } = useAppContext(); - const [showSendTxForm, setShowSendTxForm] = useState(false); - const [showDelegateTxForm, setShowDelegateTxForm] = useState(false); - const [showUnDelegateTxForm, setShowUnDelegateTxForm] = useState(false); - const [showReDelegateTxForm, setShowReDelegateTxForm] = useState(false); - const [showRewardsTxForm, setShowRewardsTxForm] = useState(false); + const [txView, setTxView] = useState("select"); const [holdings, setHoldings] = useState(null); const [multisigAddress, setMultisigAddress] = useState(""); const [accountOnChain, setAccountOnChain] = useState(null); @@ -38,6 +36,10 @@ const Multipage = () => { const [accountError, setAccountError] = useState(null); const router = useRouter(); + const closeForm = () => { + setTxView("select"); + }; + const fetchMultisig = useCallback( async (address: string) => { setAccountError(null); @@ -104,101 +106,87 @@ const Multipage = () => { )} - {showSendTxForm && ( + {txView === "send" && ( { - setShowSendTxForm(false); - }} + closeForm={closeForm} /> )} - {showDelegateTxForm && ( + {txView === "delegate" && ( { - setShowDelegateTxForm(false); - }} + closeForm={closeForm} /> )} - {showUnDelegateTxForm && ( + {txView === "undelegate" && ( { - setShowUnDelegateTxForm(false); - }} + closeForm={closeForm} /> )} - {showReDelegateTxForm && ( + {txView === "redelegate" && ( { - setShowReDelegateTxForm(false); - }} + closeForm={closeForm} /> )} - {showRewardsTxForm && ( + {txView === "claimRewards" && ( { - setShowRewardsTxForm(false); - }} + closeForm={closeForm} /> )} - {!showSendTxForm && - !showDelegateTxForm && - !showUnDelegateTxForm && - !showRewardsTxForm && - !showReDelegateTxForm && ( -
-
- -
-
- -

New transaction

-

- Once a transaction is created, it can be signed by the multisig members, and - then broadcast. -

-
+ {txView === "select" && ( +
+
+
- )} +
+ +

New transaction

+

+ Once a transaction is created, it can be signed by the multisig members, and then + broadcast. +

+
+
+ )}