form updates
This commit is contained in:
@@ -11,6 +11,7 @@ export const signInWithMnemonic = async (
|
||||
|
||||
export const minorToMajor = async (amount: string): Promise<Coin> =>
|
||||
await invoke('minor_to_major', { amount })
|
||||
|
||||
export const majorToMinor = async (amount: string): Promise<Coin> =>
|
||||
await invoke('major_to_minor', { amount })
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from 'react'
|
||||
import React, { useContext } from 'react'
|
||||
import {
|
||||
Button,
|
||||
CircularProgress,
|
||||
@@ -16,6 +16,8 @@ import { yupResolver } from '@hookform/resolvers/yup'
|
||||
import { validationSchema } from './validationSchema'
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { Alert } from '@material-ui/lab'
|
||||
import { ClientContext } from '../../context/main'
|
||||
import { majorToMinor } from '../../requests'
|
||||
|
||||
type TDelegateForm = {
|
||||
nodeType: EnumNodeType
|
||||
@@ -52,14 +54,19 @@ export const DelegateForm = ({
|
||||
|
||||
const watchNodeType = watch('nodeType', defaultValues.nodeType)
|
||||
|
||||
const { getBalance } = useContext(ClientContext)
|
||||
|
||||
const onSubmit = async (data: TDelegateForm) => {
|
||||
const amount = await majorToMinor(data.amount)
|
||||
|
||||
await invoke(`delegate_to_${data.nodeType}`, {
|
||||
identity: data.identity,
|
||||
amount: { denom: 'punk', amount: data.amount },
|
||||
amount,
|
||||
})
|
||||
.then((res: any) => {
|
||||
console.log(res)
|
||||
onSuccess(res)
|
||||
getBalance.fetchBalance()
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e)
|
||||
|
||||
@@ -10,6 +10,7 @@ import { SendConfirmation } from './SendConfirmation'
|
||||
import { ClientContext } from '../../context/main'
|
||||
import { validationSchema } from './validationSchema'
|
||||
import { TauriTxResult } from '../../types/rust/tauritxresult'
|
||||
import { majorToMinor } from '../../requests'
|
||||
|
||||
const defaultValues = {
|
||||
amount: '',
|
||||
@@ -57,19 +58,24 @@ export const SendWizard = () => {
|
||||
setActiveStep(0)
|
||||
}
|
||||
|
||||
const handleSend = () => {
|
||||
const handleSend = async () => {
|
||||
setIsLoading(true)
|
||||
setActiveStep((s) => s + 1)
|
||||
const formState = methods.getValues()
|
||||
const amount = await majorToMinor(formState.amount)
|
||||
|
||||
invoke('send', {
|
||||
amount,
|
||||
address: formState.to,
|
||||
amount: { denom: 'punk', amount: formState.amount },
|
||||
memo: formState.memo,
|
||||
})
|
||||
.then((res: any) => {
|
||||
const { details } = res as TauriTxResult
|
||||
setActiveStep((s) => s + 1)
|
||||
setConfirmedData(details)
|
||||
setConfirmedData({
|
||||
...details,
|
||||
amount: { denom: 'punk', amount: formState.amount },
|
||||
})
|
||||
setIsLoading(false)
|
||||
getBalance.fetchBalance()
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from 'react'
|
||||
import React, { useContext } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import {
|
||||
Button,
|
||||
@@ -15,6 +15,7 @@ import { yupResolver } from '@hookform/resolvers/yup'
|
||||
import { validationSchema } from './validationSchema'
|
||||
import { NodeTypeSelector } from '../../components/NodeTypeSelector'
|
||||
import { EnumNodeType, TFee } from '../../types'
|
||||
import { ClientContext } from '../../context/main'
|
||||
|
||||
type TFormData = {
|
||||
nodeType: EnumNodeType
|
||||
@@ -46,10 +47,16 @@ export const UndelegateForm = ({
|
||||
resolver: yupResolver(validationSchema),
|
||||
})
|
||||
const watchNodeType = watch('nodeType')
|
||||
const { getBalance } = useContext(ClientContext)
|
||||
|
||||
const onSubmit = async (data: TFormData) => {
|
||||
await invoke('undelegate_from_mixnode', { identity: data.identity })
|
||||
.then((res: any) => onSuccess(res))
|
||||
await invoke(`undelegate_from_${data.nodeType}`, {
|
||||
identity: data.identity,
|
||||
})
|
||||
.then((res: any) => {
|
||||
onSuccess(res)
|
||||
getBalance.fetchBalance()
|
||||
})
|
||||
.catch((e) => onError(e))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user