diff --git a/tauri-wallet/src/routes/bond/index.tsx b/tauri-wallet/src/routes/bond/index.tsx index 3fe22c1c6e..7aee7ce80f 100644 --- a/tauri-wallet/src/routes/bond/index.tsx +++ b/tauri-wallet/src/routes/bond/index.tsx @@ -10,16 +10,15 @@ import { } from '../../components/RequestStatus' import { Layout } from '../../layouts' import { getGasFee } from '../../requests' -import { Coin, EnumNodeType } from '../../types' +import { TFee } from '../../types' export const Bond = () => { const [status, setStatus] = useState(EnumRequestStatus.loading) const [message, setMessage] = useState() + const [fees, setFees] = useState() const theme: Theme = useTheme() - const [fees, setFees] = useState<{ [key in EnumNodeType]: Coin }>() - useEffect(() => { const getFees = async () => { const mixnode = await getGasFee('BondMixnode') diff --git a/tauri-wallet/src/routes/delegate/DelegateForm.tsx b/tauri-wallet/src/routes/delegate/DelegateForm.tsx index ec2bd41e2b..de598ac268 100644 --- a/tauri-wallet/src/routes/delegate/DelegateForm.tsx +++ b/tauri-wallet/src/routes/delegate/DelegateForm.tsx @@ -11,10 +11,11 @@ import { } from '@material-ui/core' import { useForm } from 'react-hook-form' import { NodeTypeSelector } from '../../components/NodeTypeSelector' -import { EnumNodeType } from '../../types/global' +import { EnumNodeType, TFee } from '../../types' import { yupResolver } from '@hookform/resolvers/yup' import { validationSchema } from './validationSchema' import { invoke } from '@tauri-apps/api' +import { Alert } from '@material-ui/lab' type TDelegateForm = { nodeType: EnumNodeType @@ -29,9 +30,11 @@ const defaultValues: TDelegateForm = { } export const DelegateForm = ({ + fees, onError, onSuccess, }: { + fees: TFee onError: (message?: string) => void onSuccess: (message?: string) => void }) => { @@ -68,11 +71,22 @@ export const DelegateForm = ({
- - setValue('nodeType', nodeType)} - /> + + + setValue('nodeType', nodeType)} + /> + + + + {`A fee of ${ + watchNodeType === EnumNodeType.mixnode + ? fees.mixnode.amount + : fees.gateway.amount + } PUNK will apply to this transaction`} + + { const [status, setStatus] = useState( EnumRequestStatus.initial ) const [message, setMessage] = useState() + const [isLoading, setIsLoading] = useState(true) + const [fees, setFees] = useState() + + useEffect(() => { + const getFees = async () => { + const mixnode = await getGasFee('DelegateToMixnode') + const gateway = await getGasFee('DelegateToGateway') + setFees({ + mixnode: mixnode, + gateway: gateway, + }) + setIsLoading(false) + } + + getFees() + }, []) const theme: Theme = useTheme() return ( @@ -24,9 +42,21 @@ export const Delegate = () => { subheader="Delegate to mixnode or gateway" noPadding > + {isLoading && ( + + + + )} <> - {status === EnumRequestStatus.initial && ( + {status === EnumRequestStatus.initial && fees && ( { setStatus(EnumRequestStatus.error) setMessage(message) diff --git a/tauri-wallet/src/routes/undelegate/UndelegateForm.tsx b/tauri-wallet/src/routes/undelegate/UndelegateForm.tsx index aa7b73b471..70d04c197b 100644 --- a/tauri-wallet/src/routes/undelegate/UndelegateForm.tsx +++ b/tauri-wallet/src/routes/undelegate/UndelegateForm.tsx @@ -8,12 +8,13 @@ import { TextField, Theme, } from '@material-ui/core' +import { Alert } from '@material-ui/lab' import { useTheme } from '@material-ui/styles' import { invoke } from '@tauri-apps/api' import { yupResolver } from '@hookform/resolvers/yup' import { validationSchema } from './validationSchema' import { NodeTypeSelector } from '../../components/NodeTypeSelector' -import { EnumNodeType } from '../../types/global' +import { EnumNodeType, TFee } from '../../types' type TFormData = { nodeType: EnumNodeType @@ -26,9 +27,11 @@ const defaultValues = { } export const UndelegateForm = ({ + fees, onError, onSuccess, }: { + fees: TFee onError: (message?: string) => void onSuccess: (message?: string) => void }) => { @@ -52,38 +55,26 @@ export const UndelegateForm = ({ const theme: Theme = useTheme() - const handleAmountChange = (event: any) => { - // don't ask me about that. javascript works in mysterious ways - // and this is apparently a good way of checking if string - // is purely made of numeric characters - // const parsed = +event.target.value - // if (isNaN(parsed)) { - // setIsValidAmount(false) - // } else { - // try { - // const allocationCheck = { error: undefined, message: '' } - // if (allocationCheck.error) { - // setAllocationWarning(allocationCheck.message) - // setIsValidAmount(false) - // } else { - // setAllocationWarning(allocationCheck.message) - // setIsValidAmount(true) - // } - // } catch { - // setIsValidAmount(false) - // } - // } - } - return (
- - setValue('nodeType', nodeType)} - /> + + + setValue('nodeType', nodeType)} + /> + + + + {`A fee of ${ + watchNodeType === EnumNodeType.mixnode + ? fees.mixnode.amount + : fees.gateway.amount + } PUNK will apply to this transaction`} + + { const [message, setMessage] = useState() const [status, setStaus] = useState( EnumRequestStatus.initial ) + const [isLoading, setIsLoading] = useState(true) + const [fees, setFees] = useState() + + useEffect(() => { + const getFees = async () => { + const mixnode = await getGasFee('UndelegateFromMixnode') + const gateway = await getGasFee('UndelegateFromGateway') + setFees({ + mixnode: mixnode, + gateway: gateway, + }) + setIsLoading(false) + } + + getFees() + }, []) + + const theme: Theme = useTheme() return ( @@ -21,9 +43,21 @@ export const Undelegate = () => { subheader="Undelegate from a mixnode or gateway" noPadding > + {isLoading && ( + + + + )} <> - {status === EnumRequestStatus.initial && ( + {status === EnumRequestStatus.initial && fees && ( { setMessage(message) setStaus(EnumRequestStatus.error) diff --git a/tauri-wallet/src/types/global.ts b/tauri-wallet/src/types/global.ts index 2f5573204b..cfb41568f2 100644 --- a/tauri-wallet/src/types/global.ts +++ b/tauri-wallet/src/types/global.ts @@ -1,3 +1,5 @@ +import { Coin } from '.' + export enum EnumNodeType { mixnode = 'mixnode', gateway = 'gateway', @@ -20,3 +22,5 @@ export type TSignInWithMnemonic = { export type TCreateAccount = { mnemonic: string } & TSignInWithMnemonic + +export type TFee = { [key in EnumNodeType]: Coin }