From d227d20385ab85d69fa4b7100559a412b34f1e0d Mon Sep 17 00:00:00 2001 From: fmtabbara Date: Fri, 10 Sep 2021 17:31:04 +0100 Subject: [PATCH] add gas fees to bond form --- tauri-wallet/src/components/NymCard.tsx | 11 +- tauri-wallet/src/components/RequestStatus.tsx | 8 +- tauri-wallet/src/routes/bond/BondForm.tsx | 34 +++-- tauri-wallet/src/routes/bond/index.tsx | 124 +++++++++++------- tauri-wallet/src/routes/sign-in.tsx | 5 +- tauri-wallet/src/types/rust/index.ts | 1 + 6 files changed, 111 insertions(+), 72 deletions(-) diff --git a/tauri-wallet/src/components/NymCard.tsx b/tauri-wallet/src/components/NymCard.tsx index 3ba0820662..c77fe38359 100644 --- a/tauri-wallet/src/components/NymCard.tsx +++ b/tauri-wallet/src/components/NymCard.tsx @@ -1,19 +1,12 @@ import React from 'react' import { Card, CardContent, CardHeader, useTheme } from '@material-ui/core' -export const NymCard = ({ - title, - subheader, - Action, - noPadding, - children, -}: { +export const NymCard: React.FC<{ title: string subheader?: string Action?: React.ReactNode noPadding?: boolean - children: React.ReactElement -}) => { +}> = ({ title, subheader, Action, noPadding, children }) => { const theme = useTheme() return ( diff --git a/tauri-wallet/src/components/RequestStatus.tsx b/tauri-wallet/src/components/RequestStatus.tsx index 1a809004b1..2650f55400 100644 --- a/tauri-wallet/src/components/RequestStatus.tsx +++ b/tauri-wallet/src/components/RequestStatus.tsx @@ -3,10 +3,10 @@ import { CircularProgress, Theme } from '@material-ui/core' import { useTheme } from '@material-ui/styles' export enum EnumRequestStatus { - initial, - error, - loading, - success, + initial = 'initial', + error = 'error', + loading = 'loading', + success = 'success', } export const RequestStatus = ({ diff --git a/tauri-wallet/src/routes/bond/BondForm.tsx b/tauri-wallet/src/routes/bond/BondForm.tsx index d796585b82..710881b6e1 100644 --- a/tauri-wallet/src/routes/bond/BondForm.tsx +++ b/tauri-wallet/src/routes/bond/BondForm.tsx @@ -16,8 +16,9 @@ import { yupResolver } from '@hookform/resolvers/yup' import { EnumNodeType } from '../../types/global' import { NodeTypeSelector } from '../../components/NodeTypeSelector' import { validationSchema } from './validationSchema' -import { Gateway, MixNode } from '../../types' +import { Coin, Gateway, MixNode } from '../../types' import { invoke } from '@tauri-apps/api' +import { Alert } from '@material-ui/lab' type TBondFormFields = { withAdvancedOptions: boolean @@ -74,9 +75,11 @@ const formatData = (data: TBondFormFields) => { } export const BondForm = ({ + fees, onError, onSuccess, }: { + fees: { [key in EnumNodeType]: Coin } onError: (message?: string) => void onSuccess: (message?: string) => void }) => { @@ -117,15 +120,26 @@ export const BondForm = ({
- - { - setValue('nodeType', nodeType) - if (nodeType === EnumNodeType.mixnode) - setValue('location', undefined) - }} - /> + + + { + setValue('nodeType', nodeType) + if (nodeType === EnumNodeType.mixnode) + setValue('location', undefined) + }} + /> + + + + {`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 [status, setStatus] = useState(EnumRequestStatus.loading) const [message, setMessage] = useState() const theme: Theme = useTheme() + const [fees, setFees] = useState<{ [key in EnumNodeType]: Coin }>() + + useEffect(() => { + const getFees = async () => { + const mixnode = await getGasFee('BondMixnode') + const gateway = await getGasFee('BondGateway') + setFees({ + mixnode: mixnode, + gateway: gateway, + }) + setStatus(EnumRequestStatus.initial) + } + + getFees() + }, []) + + console.log(fees, status, message) return ( - <> - {status === EnumRequestStatus.initial && ( - { - setMessage(e) - setStatus(EnumRequestStatus.error) - }} - onSuccess={(message?: string) => { - setMessage(message) - setStatus(EnumRequestStatus.success) - }} + {status === EnumRequestStatus.loading && ( + + + + )} + {status === EnumRequestStatus.initial && ( + { + setMessage(e) + setStatus(EnumRequestStatus.error) + }} + onSuccess={(message?: string) => { + setMessage(message) + setStatus(EnumRequestStatus.success) + }} + /> + )} + {(status === EnumRequestStatus.error || + status === EnumRequestStatus.success) && ( + <> + Successfully bonded node + } + Error={ + + An error occurred with the request: {message} + + } /> - )} - {status !== EnumRequestStatus.initial && ( - <> - Successfully bonded node - } - Error={ - - An error occurred with the request: {message} - - } - /> -
+ -
- - )} - + Resend? + +
+ + )} ) diff --git a/tauri-wallet/src/routes/sign-in.tsx b/tauri-wallet/src/routes/sign-in.tsx index 8f866c10ab..cc1a60f262 100644 --- a/tauri-wallet/src/routes/sign-in.tsx +++ b/tauri-wallet/src/routes/sign-in.tsx @@ -13,7 +13,6 @@ import { import { Alert } from '@material-ui/lab' import { useTheme } from '@material-ui/styles' import { ArrowBack, CheckCircleOutline } from '@material-ui/icons' -import { invoke } from '@tauri-apps/api' import logo from '../images/logo-background.svg' import logo_alt from '../images/logo.png' import { ClientContext } from '../context/main' @@ -74,7 +73,9 @@ const SignInContent = ({ }: { showCreateAccount: () => void }) => { - const [mnemonic, setMnemonic] = useState() + const [mnemonic, setMnemonic] = useState( + 'alley mutual arrange escape army vacuum cherry ozone frame steel current smile dad subject primary foster lazy want perfect fury general eye cannon motor' + ) const [inputError, setInputError] = useState() const [isLoading, setIsLoading] = useState(false) diff --git a/tauri-wallet/src/types/rust/index.ts b/tauri-wallet/src/types/rust/index.ts index 074f01fc2a..5d2ff697fc 100644 --- a/tauri-wallet/src/types/rust/index.ts +++ b/tauri-wallet/src/types/rust/index.ts @@ -5,3 +5,4 @@ export * from './gateway' export * from './mixnode' export * from './tauritxresult' export * from './transactiondetails' +export * from './operation'