({
defaultValues,
resolver: yupResolver(validationSchema),
@@ -48,8 +49,8 @@ export const DelegateForm = ({
const watchNodeType = watch('nodeType', defaultValues.nodeType)
- const onSubmit = (data: TDelegateForm) => {
- invoke('delegate_to_mixnode', {
+ const onSubmit = async (data: TDelegateForm) => {
+ await invoke('delegate_to_mixnode', {
identity: data.identity,
amount: { denom: 'punk', amount: data.amount },
})
@@ -119,10 +120,12 @@ export const DelegateForm = ({
>
}
>
Delegate stake
diff --git a/tauri-wallet/src/routes/delegate/index.tsx b/tauri-wallet/src/routes/delegate/index.tsx
index eda107e422..0945fd5883 100644
--- a/tauri-wallet/src/routes/delegate/index.tsx
+++ b/tauri-wallet/src/routes/delegate/index.tsx
@@ -31,8 +31,9 @@ export const Delegate = () => {
setStatus(EnumRequestStatus.error)
setMessage(message)
}}
- onSuccess={() => {
+ onSuccess={(message?: string) => {
setStatus(EnumRequestStatus.success)
+ setMessage(message)
}}
/>
)}
@@ -40,12 +41,12 @@ export const Delegate = () => {
<>
(
+ Error={
An error occurred with the request: {message}
- )}
- onSuccess={() => {}}
+ }
+ Success={{message}}
/>
{
- 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/routes/undelegate/UndelegateForm.tsx b/tauri-wallet/src/routes/undelegate/UndelegateForm.tsx
index ca2c8e9557..2a5357cf08 100644
--- a/tauri-wallet/src/routes/undelegate/UndelegateForm.tsx
+++ b/tauri-wallet/src/routes/undelegate/UndelegateForm.tsx
@@ -1,78 +1,111 @@
-import React, { useState } from 'react'
-import { Alert } from '@material-ui/lab'
-import { Button, Grid, TextField, Theme } from '@material-ui/core'
-import { useGetBalance } from '../../hooks/useGetBalance'
+import React from 'react'
+import { useForm } from 'react-hook-form'
+import {
+ Button,
+ CircularProgress,
+ FormControl,
+ Grid,
+ TextField,
+ Theme,
+} from '@material-ui/core'
+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 { useTheme } from '@material-ui/styles'
-export const UndelegateForm = () => {
- const [isValidAmount, setIsValidAmount] = useState(true)
- const [validIdentity, setValidIdentity] = useState(true)
- const [allocationWarning, setAllocationWarning] = useState()
- const [nodeType, setNodeType] = useState(EnumNodeType.Mixnode)
+type TFormData = {
+ nodeType: EnumNodeType
+ identity: string
+}
+
+const defaultValues = {
+ nodeType: EnumNodeType.Mixnode,
+ identity: '',
+}
+
+export const UndelegateForm = ({
+ onError,
+ onSuccess,
+}: {
+ onError: (message?: string) => void
+ onSuccess: (message?: string) => void
+}) => {
+ const {
+ handleSubmit,
+ register,
+ setValue,
+ watch,
+ formState: { errors, isSubmitting },
+ } = useForm({
+ defaultValues,
+ resolver: yupResolver(validationSchema),
+ })
+ const watchNodeType = watch('nodeType')
+
+ const onSubmit = async (data: TFormData) => {
+ await invoke('undelegate_from_mixnode', { identity: data.identity })
+ .then((res: any) => onSuccess(res))
+ .catch((e) => onError(e))
+ }
- const { getBalance, accountBalance } = useGetBalance()
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)
- }
- }
+ // 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 (
-
+
)
}
diff --git a/tauri-wallet/src/routes/undelegate/index.tsx b/tauri-wallet/src/routes/undelegate/index.tsx
index 479554d89b..3a2fce7b13 100644
--- a/tauri-wallet/src/routes/undelegate/index.tsx
+++ b/tauri-wallet/src/routes/undelegate/index.tsx
@@ -1,9 +1,19 @@
-import React from 'react'
+import React, { useState } from 'react'
import { NymCard } from '../../components'
import { UndelegateForm } from './UndelegateForm'
import { Layout } from '../../layouts'
+import {
+ EnumRequestStatus,
+ RequestStatus,
+} from '../../components/RequestStatus'
+import { Alert } from '@material-ui/lab'
export const Undelegate = () => {
+ const [message, setMessage] = useState()
+ const [status, setStaus] = useState(
+ EnumRequestStatus.initial
+ )
+
return (
{
subheader="Undelegate from a mixnode or gateway"
noPadding
>
-
+ <>
+ {status === EnumRequestStatus.initial && (
+ {
+ setMessage(message)
+ setStaus(EnumRequestStatus.error)
+ }}
+ onSuccess={(message) => {
+ setMessage(message)
+ setStaus(EnumRequestStatus.success)
+ }}
+ />
+ )}
+ {status !== EnumRequestStatus.initial && (
+
+ An error occurred with the request: {message}
+
+ }
+ Success={{message}}
+ />
+ )}
+ >
)
diff --git a/tauri-wallet/src/routes/undelegate/validationSchema.ts b/tauri-wallet/src/routes/undelegate/validationSchema.ts
new file mode 100644
index 0000000000..659df6bcef
--- /dev/null
+++ b/tauri-wallet/src/routes/undelegate/validationSchema.ts
@@ -0,0 +1,10 @@
+import * as Yup from 'yup'
+import { validateKey } from '../../utils'
+
+export const validationSchema = Yup.object().shape({
+ identity: Yup.string()
+ .required()
+ .test('valid-id-key', 'A valid identity key is required', function (value) {
+ return validateKey(value || '')
+ }),
+})