From e39b49c7810ffe5549740001f7422bda0bff353f Mon Sep 17 00:00:00 2001 From: Pedro Rezende Date: Sun, 2 Jun 2024 14:51:48 +0200 Subject: [PATCH] feat(namadillo): first version of the gas usage selection modal --- .../namadillo/src/App/Common/GasFeeOption.tsx | 45 +++++++++++++ .../src/App/Common/GasUsageModal.tsx | 63 +++++++++++++++++++ .../src/App/Common/TransactionFees.tsx | 26 +++++--- .../src/App/Staking/IncrementBonding.tsx | 8 +-- apps/namadillo/src/slices/settings.ts | 8 +++ apps/namadillo/src/types/fees.ts | 2 + 6 files changed, 140 insertions(+), 12 deletions(-) create mode 100644 apps/namadillo/src/App/Common/GasFeeOption.tsx create mode 100644 apps/namadillo/src/App/Common/GasUsageModal.tsx diff --git a/apps/namadillo/src/App/Common/GasFeeOption.tsx b/apps/namadillo/src/App/Common/GasFeeOption.tsx new file mode 100644 index 000000000..4c3fec9fa --- /dev/null +++ b/apps/namadillo/src/App/Common/GasFeeOption.tsx @@ -0,0 +1,45 @@ +import BigNumber from "bignumber.js"; +import clsx from "clsx"; +import { FiatCurrency } from "./FiatCurrency"; +import { NamCurrency } from "./NamCurrency"; + +type GasFeeOptionProps = { + title: string; + priceInNam: BigNumber; +} & React.ComponentPropsWithoutRef<"input">; + +export const GasFeeOption = ({ + title, + priceInNam, + ...props +}: GasFeeOptionProps): JSX.Element => { + return ( + + ); +}; diff --git a/apps/namadillo/src/App/Common/GasUsageModal.tsx b/apps/namadillo/src/App/Common/GasUsageModal.tsx new file mode 100644 index 000000000..0a6690c9d --- /dev/null +++ b/apps/namadillo/src/App/Common/GasUsageModal.tsx @@ -0,0 +1,63 @@ +import { Modal, Stack } from "@namada/components"; +import clsx from "clsx"; +import { useAtom, useAtomValue } from "jotai"; +import { minimumGasPriceAtom } from "slices/fees"; +import { gasUsageOptionAtom } from "slices/settings"; +import { GasFeeOption } from "./GasFeeOption"; + +type GasUsageModalProps = { + onClose: () => void; +}; + +export const GasUsageModal = ({ onClose }: GasUsageModalProps): JSX.Element => { + const minimumGasFee = useAtomValue(minimumGasPriceAtom); + + const [gasUsageOption, setGasUsageOption] = useAtom(gasUsageOptionAtom); + + if (!minimumGasFee.isSuccess) { + return <>; + } + + return ( + +
+

Fee Options

+ +
+
    +
  • + setGasUsageOption("low")} + /> +
  • +
  • + setGasUsageOption("average")} + /> +
  • +
  • + setGasUsageOption("high")} + /> +
  • +
+
+
+
+
+ ); +}; diff --git a/apps/namadillo/src/App/Common/TransactionFees.tsx b/apps/namadillo/src/App/Common/TransactionFees.tsx index 98c196a7a..5517aa7c7 100644 --- a/apps/namadillo/src/App/Common/TransactionFees.tsx +++ b/apps/namadillo/src/App/Common/TransactionFees.tsx @@ -1,6 +1,9 @@ import clsx from "clsx"; import { useGasEstimate } from "hooks/useGasEstimate"; +import { useState } from "react"; +import { GasUsageModal } from "./GasUsageModal"; import { NamCurrency } from "./NamCurrency"; + type TransactionFeesProps = { numberOfTransactions: number; className?: string; @@ -10,18 +13,25 @@ export const TransactionFees = ({ numberOfTransactions, className, }: TransactionFeesProps): JSX.Element => { + const [modalOpen, setModalOpen] = useState(false); const { calculateMinGasRequired } = useGasEstimate(); const minimumGas = calculateMinGasRequired(numberOfTransactions); if (!minimumGas || minimumGas.eq(0)) return <>; return ( -
- Transaction fee:{" "} - -
+ <> +
setModalOpen(true)} + > + Transaction fee:{" "} + +
+ {modalOpen && setModalOpen(false)} />} + ); }; diff --git a/apps/namadillo/src/App/Staking/IncrementBonding.tsx b/apps/namadillo/src/App/Staking/IncrementBonding.tsx index 2953be988..3c3053701 100644 --- a/apps/namadillo/src/App/Staking/IncrementBonding.tsx +++ b/apps/namadillo/src/App/Staking/IncrementBonding.tsx @@ -228,12 +228,12 @@ const IncrementBonding = (): JSX.Element => { > {isPerformingBond ? "Processing..." : errorMessage || "Stake"} - + ); diff --git a/apps/namadillo/src/slices/settings.ts b/apps/namadillo/src/slices/settings.ts index 1390efcab..38edac786 100644 --- a/apps/namadillo/src/slices/settings.ts +++ b/apps/namadillo/src/slices/settings.ts @@ -1,6 +1,7 @@ import { CurrencyType } from "@namada/utils"; import { Getter, Setter, atom } from "jotai"; import { atomWithStorage } from "jotai/utils"; +import { GasRangeOption } from "types/fees"; type SettingsStorage = { fiat: CurrencyType; @@ -8,6 +9,7 @@ type SettingsStorage = { rpcUrl: string; chainId: string; signArbitraryEnabled: boolean; + gasUsageOption: GasRangeOption; }; export const namadaExtensionConnectedAtom = atom(false); @@ -20,6 +22,7 @@ export const namadilloSettingsAtom = atomWithStorage( rpcUrl: process.env.NAMADA_INTERFACE_NAMADA_URL || "", chainId: process.env.NAMADA_INTERFACE_NAMADA_CHAIN_ID || "", signArbitraryEnabled: false, + gasUsageOption: "average", } ); @@ -50,6 +53,11 @@ export const chainIdAtom = atom( changeSettings("chainId") ); +export const gasUsageOptionAtom = atom( + (get) => get(namadilloSettingsAtom).gasUsageOption, + changeSettings("gasUsageOption") +); + export const signArbitraryEnabledAtom = atom( (get) => get(namadilloSettingsAtom).signArbitraryEnabled, changeSettings("signArbitraryEnabled") diff --git a/apps/namadillo/src/types/fees.ts b/apps/namadillo/src/types/fees.ts index d6754df09..becf25088 100644 --- a/apps/namadillo/src/types/fees.ts +++ b/apps/namadillo/src/types/fees.ts @@ -4,3 +4,5 @@ export type GasConfig = { gasLimit: BigNumber; gasPrice: BigNumber; }; + +export type GasRangeOption = "low" | "average" | "high";