From 66ec2cd576f62178081b7c51f9986df16535621f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Sworze=C5=84?= Date: Mon, 26 Feb 2024 15:20:54 +0100 Subject: [PATCH 01/40] [#265] make button disabled when tries to connect --- CHANGELOG.md | 1 + .../src/components/molecules/WalletOption.tsx | 81 ++++++++++++------- govtool/frontend/src/context/wallet.tsx | 7 ++ 3 files changed, 61 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90954bacd..b80f9c5f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ changes. - i18next library added to FE [Issue 80](https://github.com/IntersectMBO/govtool/issues/80) ### Fixed +- Fix make button disble when wallet tries connect [Issue 265](https://github.com/IntersectMBO/govtool/issues/265) - Fix drep voting power calculation [Issue 231](https://github.com/IntersectMBO/govtool/issues/231) - Fix proposal/list and network/metrics bug that appeared when noone has delegated their funds either to drep_always_abstain or drep_always_no_confidence [Issue 231](https://github.com/IntersectMBO/govtool/issues/231) - Fix GA details [Issue 272](https://github.com/IntersectMBO/govtool/issues/272) diff --git a/govtool/frontend/src/components/molecules/WalletOption.tsx b/govtool/frontend/src/components/molecules/WalletOption.tsx index 94c5f9ed7..a1a14dd69 100644 --- a/govtool/frontend/src/components/molecules/WalletOption.tsx +++ b/govtool/frontend/src/components/molecules/WalletOption.tsx @@ -1,10 +1,10 @@ -import { Box, Typography } from "@mui/material"; -import { FC } from "react"; +import { FC, useCallback } from "react"; +import { useNavigate } from "react-router-dom"; +import { Box, CircularProgress, Typography } from "@mui/material"; +import { PATHS } from "@consts"; import { useCardano } from "@context"; import { theme } from "@/theme"; -import { useNavigate } from "react-router-dom"; -import { PATHS } from "@/consts"; export interface WalletOption { icon: string; @@ -15,7 +15,7 @@ export interface WalletOption { } export const WalletOptionButton: FC = ({ ...props }) => { - const { enable } = useCardano(); + const { enable, isEnableLoading } = useCardano(); const { palette: { lightBlue }, } = theme; @@ -23,52 +23,77 @@ export const WalletOptionButton: FC = ({ ...props }) => { const { dataTestId, icon, label, name, cip95Available } = props; + const enableByWalletName = useCallback(async() => { + if(isEnableLoading) return; + const result = await enable(name); + if (result?.stakeKey) { + navigate(PATHS.dashboard); + return; + } + navigate(PATHS.stakeKeys); + }, [enable, isEnableLoading]) + return ( { - const result = await enable(name); - if (result?.stakeKey) { - navigate(PATHS.dashboard); - return; - } - navigate(PATHS.stakeKeys); - }} + onClick={enableByWalletName} > {`${name} {name ?? label} - {`${name} +
+ {isEnableLoading === name && ( + + + + )} ); }; diff --git a/govtool/frontend/src/context/wallet.tsx b/govtool/frontend/src/context/wallet.tsx index 3d49f7a25..765e24226 100644 --- a/govtool/frontend/src/context/wallet.tsx +++ b/govtool/frontend/src/context/wallet.tsx @@ -97,6 +97,7 @@ interface CardanoContext { address?: string; disconnectWallet: () => Promise; enable: (walletName: string) => Promise; + isEnableLoading: string | null; error?: string; dRep: DRepInfo | undefined; isEnabled: boolean; @@ -165,6 +166,7 @@ CardanoContext.displayName = "CardanoContext"; function CardanoProvider(props: Props) { const [isEnabled, setIsEnabled] = useState(false); + const [isEnableLoading, setIsEnableLoading] = useState(null); const [dRep, setDRep] = useState(undefined); const [walletApi, setWalletApi] = useState( undefined @@ -517,6 +519,7 @@ function CardanoProvider(props: Props) { const enable = useCallback( async (walletName: string) => { + setIsEnableLoading(walletName); await checkIsMaintenanceOn(); // todo: use .getSupportedExtensions() to check if wallet supports CIP-95 @@ -650,6 +653,8 @@ function CardanoProvider(props: Props) { status: "ERROR", error: `${e == undefined ? t("errors.somethingWentWrong") : e}`, }; + } finally { + setIsEnableLoading(null); } } throw { status: "ERROR", error: t("errors.somethingWentWrong") }; @@ -1141,6 +1146,7 @@ function CardanoProvider(props: Props) { isPendingTransaction, isDrepLoading, setIsDrepLoading, + isEnableLoading, }), [ address, @@ -1173,6 +1179,7 @@ function CardanoProvider(props: Props) { isPendingTransaction, isDrepLoading, setIsDrepLoading, + isEnableLoading, ] ); From b1c73cf18e905551f802d6ad72d1d9016f3ac67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Placzy=C5=84ski?= Date: Mon, 26 Feb 2024 14:36:25 +0100 Subject: [PATCH 02/40] =?UTF-8?q?[#301]=20Add=20Micha=C5=82=20Sza=C5=82ows?= =?UTF-8?q?ki=20to=20SSH=20access=20list=20for=20environment=20management?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates the user_data.sh script within the Terraform modules for govtool-EC2 instances. It adds Michał Szałowski to the list of users authorized for SSH access, thereby expanding the secure access management system to include a team leader. This change is a step towards fulfilling the secure credential sharing acceptance criterion by ensuring new team members like Michał have the necessary access to sensitive environments. --- infra/terraform/modules/govtool-ec2/main.tf | 2 +- infra/terraform/modules/govtool-ec2/user_data.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/infra/terraform/modules/govtool-ec2/main.tf b/infra/terraform/modules/govtool-ec2/main.tf index f71417f05..40ad6f6cd 100644 --- a/infra/terraform/modules/govtool-ec2/main.tf +++ b/infra/terraform/modules/govtool-ec2/main.tf @@ -153,7 +153,7 @@ resource "aws_instance" "govtool" { } user_data = file("${path.module}/user_data.sh") - # user_data_replace_on_change = true + user_data_replace_on_change = false credit_specification { cpu_credits = "unlimited" diff --git a/infra/terraform/modules/govtool-ec2/user_data.sh b/infra/terraform/modules/govtool-ec2/user_data.sh index 6f9708ffe..79a7f1a06 100644 --- a/infra/terraform/modules/govtool-ec2/user_data.sh +++ b/infra/terraform/modules/govtool-ec2/user_data.sh @@ -2,7 +2,7 @@ # setup ssh access mkdir -p /home/ubuntu/.ssh -users="a.guderski,michal.jankun,p.placzynski" +users="a.guderski,michal.jankun,p.placzynski,michal.szalowski" curl --retry 5 --retry-delay 5 -L keys.binarapps.com/ssh/{$users} | tee -a /home/ubuntu/.ssh/authorized_keys echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKeM0HOF9szWhOfbQM8XkIfznORTtTaCJJStALYjQuy6 (voltaire-era-github-actions)" | tee -a /home/ubuntu/.ssh/authorized_keys chmod 700 /home/ubuntu/.ssh From 4f67d31a11df019e15cabcb377966c9f9f4ce67f Mon Sep 17 00:00:00 2001 From: Jan Jaroszczak Date: Wed, 14 Feb 2024 09:37:03 +0100 Subject: [PATCH 03/40] Sole voter information page, without footer --- govtool/frontend/src/App.tsx | 5 + .../components/organisms/SoleVoterInfo.tsx | 108 +++++++++++++++++ govtool/frontend/src/consts/paths.ts | 1 + govtool/frontend/src/i18n/locales/en.ts | 8 ++ .../src/pages/RegisterAsSoleVoter.tsx | 110 ++++++++++++++++++ 5 files changed, 232 insertions(+) create mode 100644 govtool/frontend/src/components/organisms/SoleVoterInfo.tsx create mode 100644 govtool/frontend/src/pages/RegisterAsSoleVoter.tsx diff --git a/govtool/frontend/src/App.tsx b/govtool/frontend/src/App.tsx index 91dab6356..d48e4d55a 100644 --- a/govtool/frontend/src/App.tsx +++ b/govtool/frontend/src/App.tsx @@ -30,6 +30,7 @@ import { } from "@utils"; import { SetupInterceptors } from "./services"; import { useGetDRepInfo, useWalletConnectionListener } from "./hooks"; +import { RegisterAsSoleVoter } from "./pages/RegisterAsSoleVoter"; export default function App() { const { enable, setDRep, setIsDrepLoading } = useCardano(); @@ -115,6 +116,10 @@ export default function App() { } /> } /> + } + /> } /> } /> } /> diff --git a/govtool/frontend/src/components/organisms/SoleVoterInfo.tsx b/govtool/frontend/src/components/organisms/SoleVoterInfo.tsx new file mode 100644 index 000000000..4eb34dafe --- /dev/null +++ b/govtool/frontend/src/components/organisms/SoleVoterInfo.tsx @@ -0,0 +1,108 @@ +import { useMemo } from "react"; +import { Box, Link } from "@mui/material"; + +import { LoadingButton, Button, Typography } from "@atoms"; +import { theme } from "@/theme"; +import { useScreenDimension, useTranslation } from "@hooks"; +import { Trans } from "react-i18next"; +import { openInNewTab } from "@/utils"; +import { useNavigate } from "react-router-dom"; +import { PATHS } from "@consts"; + +export const SoleVoterInfo = () => { + const { + palette: { boxShadow2 }, + } = theme; + const { isMobile, pagePadding, screenWidth } = useScreenDimension(); + const navigate = useNavigate(); + const { t } = useTranslation(); + + const renderBackButton = useMemo(() => { + return ( + + ); + }, [isMobile]); + + const renderRegisterButton = useMemo(() => { + return ( + {}} + sx={{ + borderRadius: 50, + textTransform: "none", + px: 6, + width: isMobile ? "100%" : "auto", + height: 48, + }} + variant="contained" + > + {t("soleVoter.continueToRegister")} + + ); + }, [ + // isLoading, + isMobile, + ]); + + return ( + + + + {t("soleVoter.heading")} + + + openInNewTab("https://sancho.network/")} + sx={{ cursor: "pointer" }} + key="0" + />, + ]} + /> + + + + {isMobile ? renderRegisterButton : renderBackButton} + + {isMobile ? renderBackButton : renderRegisterButton} + + + ); +}; diff --git a/govtool/frontend/src/consts/paths.ts b/govtool/frontend/src/consts/paths.ts index 645f4e695..8af3a6381 100644 --- a/govtool/frontend/src/consts/paths.ts +++ b/govtool/frontend/src/consts/paths.ts @@ -16,6 +16,7 @@ export const PATHS = { faqs: "/faqs", delegateTodRep: "/delegate", registerAsdRep: "/register", + registerAsSoleVoter: "/register_sole_voter", stakeKeys: "/stake_keys", updateMetadata: "/update_metadata", }; diff --git a/govtool/frontend/src/i18n/locales/en.ts b/govtool/frontend/src/i18n/locales/en.ts index 9204175a4..68cd48743 100644 --- a/govtool/frontend/src/i18n/locales/en.ts +++ b/govtool/frontend/src/i18n/locales/en.ts @@ -286,6 +286,13 @@ export const en = { showAll: "Show all", viewAll: "View all", }, + soleVoter: { + becomeSoleVoter: "Become a Sole Voter", + continueToRegister: "Continue to register", + description: + "A Sole Voter is someone that can vote on any Governance Action with their own Voting Power, which is equal to the balance of ADA in their connected wallet. <0>Learn More about Sole Voter.\n\nBecoming a Sole Voter will require a refundable deposit of ₳2.\n\nYour deposit will be refunded if you either retire or delegate your voting power to someone else (a DRep)", + heading: "What this Means", + }, system: { sanchoNet: "SanchoNet", sanchoNetIsBeta: @@ -360,6 +367,7 @@ export const en = { back: "Back", backToDashboard: "Back to dashboard", backToList: "Back to the list", + backToDashboard: "Back to dashboard", cancel: "Cancel", clear: "Clear", confirm: "Confirm", diff --git a/govtool/frontend/src/pages/RegisterAsSoleVoter.tsx b/govtool/frontend/src/pages/RegisterAsSoleVoter.tsx new file mode 100644 index 000000000..370a5fefc --- /dev/null +++ b/govtool/frontend/src/pages/RegisterAsSoleVoter.tsx @@ -0,0 +1,110 @@ +import { useEffect } from "react"; +import { Box, Link } from "@mui/material"; + +import { Background, Typography } from "@atoms"; +import { ICONS, PATHS } from "@consts"; +import { DashboardTopNav, Footer } from "@organisms"; +import { useScreenDimension, useTranslation } from "@hooks"; +import { useNavigate } from "react-router-dom"; +import { WALLET_LS_KEY, getItemFromLocalStorage } from "@/utils/localStorage"; +import { SoleVoterInfo } from "@/components/organisms/SoleVoterInfo"; + +export const RegisterAsSoleVoter = () => { + const { isMobile, screenWidth } = useScreenDimension(); + const navigate = useNavigate(); + const { t } = useTranslation(); + + useEffect(() => { + if ( + !getItemFromLocalStorage(`${WALLET_LS_KEY}_stake_key`) || + !getItemFromLocalStorage(`${WALLET_LS_KEY}_name`) + ) { + navigate(PATHS.home); + } + }, []); + + return ( + + + + + + {isMobile && ( + + + {t("soleVoter.becomeSoleVoter")} + + + )} + navigate(PATHS.dashboard)} + > + arrow + + {t("backToDashboard")} + + + + + {isMobile &&