diff --git a/tauri-wallet/src/components/NavigationCards.tsx b/tauri-wallet/src/components/NavigationCards.tsx index edd11fd0a0..bfb138930e 100644 --- a/tauri-wallet/src/components/NavigationCards.tsx +++ b/tauri-wallet/src/components/NavigationCards.tsx @@ -12,6 +12,7 @@ import { CheckCircleOutline, FileCopy, Refresh } from '@material-ui/icons' import { NymCard } from './NymCard' import { Alert } from '@material-ui/lab' import { handleCopy } from './CopyToClipboard' +import { truncate } from '../utils' export const BalanceCard = () => { const theme = useTheme() @@ -41,7 +42,7 @@ export const BalanceCard = () => { {balanceError} ) : ( - {balance?.printable_balance} + {balance?.printable_balance} )} @@ -101,7 +102,13 @@ export const AddressCard = () => { } > - {clientDetails?.client_address} + + + {truncate(clientDetails?.client_address!, 35)} + + ) diff --git a/tauri-wallet/src/components/RequestStatus.tsx b/tauri-wallet/src/components/RequestStatus.tsx new file mode 100644 index 0000000000..ec024d1a9b --- /dev/null +++ b/tauri-wallet/src/components/RequestStatus.tsx @@ -0,0 +1,33 @@ +import React from 'react' +import { CircularProgress, Theme } from '@material-ui/core' +import { useTheme } from '@material-ui/styles' + +export enum EnumRequestStatus { + initial, + error, + loading, + success, +} + +export const RequestStatus = ({ + status, + onSuccess, + onError, +}: { + status: EnumRequestStatus + onSuccess: () => void + onError: () => void +}) => { + const theme: Theme = useTheme() + return ( +
+ {status === EnumRequestStatus.loading && ( +
+ +
+ )} + {status === EnumRequestStatus.success && onSuccess()} + {status === EnumRequestStatus.error && onError()} +
+ ) +} diff --git a/tauri-wallet/src/context/main.tsx b/tauri-wallet/src/context/main.tsx index dc869fb581..4ada7969fb 100644 --- a/tauri-wallet/src/context/main.tsx +++ b/tauri-wallet/src/context/main.tsx @@ -42,6 +42,7 @@ export const ClientContextProvider = ({ useEffect(() => { if (clientDetails) getBalance() + !clientDetails ? history.push('/signin') : history.push('/bond') }, [clientDetails, getBalance]) const logIn = (clientDetails: TClientDetails) => @@ -49,10 +50,6 @@ export const ClientContextProvider = ({ const logOut = () => setClientDetails(undefined) - useEffect(() => { - !clientDetails ? history.push('/signin') : history.push('/bond') - }, [clientDetails]) - return ( void -} +import { invoke } from '@tauri-apps/api' type TBondFormFields = { withAdvancedOptions: boolean @@ -59,28 +56,35 @@ const formatData = (data: TBondFormFields) => { host: data.host, version: data.version, mix_port: data.mixPort, + amount: data.amount, } if (data.nodeType === EnumNodeType.Mixnode) { payload.verloc_port = data.verlocPort payload.http_api_port = data.httpApiPort - return payload as MixNode + return payload as MixNode & { amount: number } } if (data.nodeType == EnumNodeType.Gateway) { payload.clients_port = data.clientsPort payload.location = data.location - return payload as Gateway + return payload as Gateway & { amount: number } } } -export const BondForm = () => { +export const BondForm = ({ + onError, + onSuccess, +}: { + onError: (message?: string) => void + onSuccess: (message?: string) => void +}) => { const { register, handleSubmit, setValue, watch, - formState: { errors }, + formState: { errors, isSubmitting }, } = useForm({ resolver: yupResolver(validationSchema), defaultValues, @@ -92,9 +96,18 @@ export const BondForm = () => { defaultValues.withAdvancedOptions ) - const onSubmit = (data: TBondFormFields) => { + const onSubmit = async (data: TBondFormFields) => { const formattedData = formatData(data) - console.log(formattedData) + await invoke('bond_mixnode', { + mixnode: formattedData, + bond: { amount: formattedData?.amount, denom: 'punk' }, + }) + .then((res: any) => { + onSuccess(res) + }) + .catch((e) => { + onError(e) + }) } const theme: Theme = useTheme() @@ -315,13 +328,14 @@ export const BondForm = () => { }} > diff --git a/tauri-wallet/src/routes/bond/index.tsx b/tauri-wallet/src/routes/bond/index.tsx index d34a4cd90a..e93b241947 100644 --- a/tauri-wallet/src/routes/bond/index.tsx +++ b/tauri-wallet/src/routes/bond/index.tsx @@ -1,13 +1,71 @@ -import React from 'react' +import React, { useState } from 'react' +import { Button, Theme } from '@material-ui/core' +import { Alert } from '@material-ui/lab' +import { useTheme } from '@material-ui/styles' import { NymCard } from '../../components' +import { + EnumRequestStatus, + RequestStatus, +} from '../../components/RequestStatus' import { Layout } from '../../layouts' import { BondForm } from './BondForm' export const Bond = () => { + const [status, setStatus] = useState(EnumRequestStatus.initial) + const [message, setMessage] = useState() + + const theme: Theme = useTheme() + return ( - + <> + {status === EnumRequestStatus.initial && ( + { + setMessage(e) + setStatus(EnumRequestStatus.error) + }} + onSuccess={(message?: string) => { + setMessage(message) + setStatus(EnumRequestStatus.success) + }} + /> + )} + {status !== EnumRequestStatus.initial && ( + <> + ( + Successfully bonded node + )} + onError={() => ( + + An error occurred with the request: {message} + + )} + /> +
+ +
+ + )} +
) diff --git a/tauri-wallet/src/routes/sign-in.tsx b/tauri-wallet/src/routes/sign-in.tsx index 2e557ab1ab..2d2c630276 100644 --- a/tauri-wallet/src/routes/sign-in.tsx +++ b/tauri-wallet/src/routes/sign-in.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useState } from 'react' +import React, { useContext, useEffect, useState } from 'react' import { TextField, CircularProgress, @@ -31,15 +31,15 @@ export const SignIn = () => { setIsLoading(true) setInputError(undefined) - await invoke('connect_with_mnemonic', { mnemonic }) + invoke('connect_with_mnemonic', { mnemonic }) .then((res) => { + setIsLoading(false) logIn(res as TClientDetails) }) .catch((e) => { + setIsLoading(false) setInputError(e) }) - - setIsLoading(false) } return ( diff --git a/tauri-wallet/src/types/rust/index.ts b/tauri-wallet/src/types/rust/index.ts index 092ba45973..090e6b088a 100644 --- a/tauri-wallet/src/types/rust/index.ts +++ b/tauri-wallet/src/types/rust/index.ts @@ -1,3 +1,5 @@ export * from './balance' export * from './coin' export * from './mixnode' +export * from './gateway' +export * from './mixnode' diff --git a/tauri-wallet/src/utils/index.ts b/tauri-wallet/src/utils/index.ts index 01f25fb333..d4faac1a60 100644 --- a/tauri-wallet/src/utils/index.ts +++ b/tauri-wallet/src/utils/index.ts @@ -87,3 +87,6 @@ export const validateLocation = (location: string): boolean => { export const validateRawPort = (rawPort: number): boolean => !isNaN(rawPort) && rawPort >= 1 && rawPort <= 65535 + +export const truncate = (text: string, trim: number) => + text.substring(0, trim) + '...'