Skip to content

Commit

Permalink
feat(ui): create enum for action type
Browse files Browse the repository at this point in the history
  • Loading branch information
Vu Van Duc authored and Vu Van Duc committed May 7, 2024
1 parent 503066e commit e9c3c2a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
23 changes: 15 additions & 8 deletions src/ui/pages/Menu/components/ConnectWallet/ConnectWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { i18n } from "../../../../../i18n";
import { CardsPlaceholder } from "../../../../components/CardsPlaceholder";
import "./ConnectWallet.scss";
import { ConnectWalletActions } from "../ConnectWalletActions";
import { ActionInfo, ConnectWalletOptionRef } from "./ConnectWallet.types";
import {
ActionInfo,
ActionType,
ConnectWalletOptionRef,
} from "./ConnectWallet.types";
import { CardItem, CardList } from "../../../../components/CardList";
import { IonCheckbox, IonItemOption } from "@ionic/react";
import { Alert } from "../../../../components/Alert";
Expand Down Expand Up @@ -37,7 +41,7 @@ const ConnectWallet = forwardRef<ConnectWalletOptionRef, object>(
const pageId = "connect-wallet-placeholder";
const stateCache = useAppSelector(getStateCache);
const actionInfo = useRef<ActionInfo>({
type: "none",
type: ActionType.None,
});

const [openConnectWallet, setOpenConnectWallet] = useState(false);
Expand Down Expand Up @@ -83,7 +87,7 @@ const ConnectWallet = forwardRef<ConnectWalletOptionRef, object>(

const handleOpenDeleteAlert = (data: ConnectionData) => {
actionInfo.current = {
type: "delete",
type: ActionType.Delete,
data,
};

Expand All @@ -92,15 +96,15 @@ const ConnectWallet = forwardRef<ConnectWalletOptionRef, object>(

const handleOpenConfirmConnectModal = (data: ConnectionData) => {
actionInfo.current = {
type: "connect",
type: ActionType.Connect,
data,
};
setOpenConfirmConnectModal(true);
};

const closeDeleteAlert = () => {
actionInfo.current = {
type: "none",
type: ActionType.None,
};
setOpenDeleteAlert(false);
};
Expand All @@ -112,7 +116,7 @@ const ConnectWallet = forwardRef<ConnectWalletOptionRef, object>(

const handleDeleteConnection = (data: ConnectionData) => {
actionInfo.current = {
type: "none",
type: ActionType.None,
};

// TODO: Implement delete wallet connection logic
Expand Down Expand Up @@ -141,11 +145,14 @@ const ConnectWallet = forwardRef<ConnectWalletOptionRef, object>(
setVerifyPasscodeIsOpen(false);
setVerifyPasswordIsOpen(false);

if (actionInfo.current.type === "delete" && actionInfo.current.data) {
if (
actionInfo.current.type === ActionType.Delete &&
actionInfo.current.data
) {
handleDeleteConnection(actionInfo.current.data);
}

if ("connect" === actionInfo.current.type) {
if (ActionType.Connect === actionInfo.current.type) {
handleConnectWallet();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ interface ConnectWalletOptionRef {
}

type ActionInfo = {
type: "add" | "delete" | "connect" | "none";
type: ActionType;
data?: ConnectionData;
};

enum ActionType {
Add = "add",
Delete = "delete",
Connect = "connect",
None = "none",
}

export { ActionType };

export type { ConnectWalletOptionRef, ActionInfo };

0 comments on commit e9c3c2a

Please sign in to comment.