From b77025bfd50099019c5a9155f34231dfe69c4380 Mon Sep 17 00:00:00 2001 From: fmtabbara Date: Sat, 11 Sep 2021 00:10:03 +0100 Subject: [PATCH] form updates --- tauri-wallet/src/requests/index.ts | 1 + tauri-wallet/src/routes/delegate/DelegateForm.tsx | 11 +++++++++-- tauri-wallet/src/routes/send/SendWizard.tsx | 12 +++++++++--- .../src/routes/undelegate/UndelegateForm.tsx | 13 ++++++++++--- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/tauri-wallet/src/requests/index.ts b/tauri-wallet/src/requests/index.ts index aef86bb51e..62629f72c0 100644 --- a/tauri-wallet/src/requests/index.ts +++ b/tauri-wallet/src/requests/index.ts @@ -11,6 +11,7 @@ export const signInWithMnemonic = async ( export const minorToMajor = async (amount: string): Promise => await invoke('minor_to_major', { amount }) + export const majorToMinor = async (amount: string): Promise => await invoke('major_to_minor', { amount }) diff --git a/tauri-wallet/src/routes/delegate/DelegateForm.tsx b/tauri-wallet/src/routes/delegate/DelegateForm.tsx index de598ac268..5b415b00c2 100644 --- a/tauri-wallet/src/routes/delegate/DelegateForm.tsx +++ b/tauri-wallet/src/routes/delegate/DelegateForm.tsx @@ -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) diff --git a/tauri-wallet/src/routes/send/SendWizard.tsx b/tauri-wallet/src/routes/send/SendWizard.tsx index bf83c460f1..11468a7e5d 100644 --- a/tauri-wallet/src/routes/send/SendWizard.tsx +++ b/tauri-wallet/src/routes/send/SendWizard.tsx @@ -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() }) diff --git a/tauri-wallet/src/routes/undelegate/UndelegateForm.tsx b/tauri-wallet/src/routes/undelegate/UndelegateForm.tsx index 70d04c197b..b724bb5586 100644 --- a/tauri-wallet/src/routes/undelegate/UndelegateForm.tsx +++ b/tauri-wallet/src/routes/undelegate/UndelegateForm.tsx @@ -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)) }