diff --git a/tauri-wallet/src/requests/index.ts b/tauri-wallet/src/requests/index.ts index 62629f72c0..df82000330 100644 --- a/tauri-wallet/src/requests/index.ts +++ b/tauri-wallet/src/requests/index.ts @@ -1,5 +1,13 @@ import { invoke } from '@tauri-apps/api' -import { Coin, Operation, TCreateAccount, TSignInWithMnemonic } from '../types' +import { + Coin, + DelegationResult, + EnumNodeType, + Operation, + TauriTxResult, + TCreateAccount, + TSignInWithMnemonic, +} from '../types' export const createAccount = async (): Promise => await invoke('create_new_account') @@ -17,3 +25,20 @@ export const majorToMinor = async (amount: string): Promise => export const getGasFee = async (operation: Operation): Promise => await invoke('get_fee', { operation }) + +export const delegatedToMixnode = async ({ + type, + identity, + amount, +}: { + type: EnumNodeType + identity: string + amount: Coin +}): Promise => + await invoke(`delegate_to_${type}`, { identity, amount }) + +export const send = async (args: { + amount: Coin + address: string + memo: string +}): Promise => await invoke('send', args) diff --git a/tauri-wallet/src/routes/delegate/DelegateForm.tsx b/tauri-wallet/src/routes/delegate/DelegateForm.tsx index 5b415b00c2..179b85533d 100644 --- a/tauri-wallet/src/routes/delegate/DelegateForm.tsx +++ b/tauri-wallet/src/routes/delegate/DelegateForm.tsx @@ -11,13 +11,12 @@ import { } from '@material-ui/core' import { useForm } from 'react-hook-form' import { NodeTypeSelector } from '../../components/NodeTypeSelector' -import { EnumNodeType, TFee } from '../../types' +import { DelegationResult, EnumNodeType, TFee } from '../../types' 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' +import { delegatedToMixnode, majorToMinor } from '../../requests' type TDelegateForm = { nodeType: EnumNodeType @@ -58,14 +57,22 @@ export const DelegateForm = ({ const onSubmit = async (data: TDelegateForm) => { const amount = await majorToMinor(data.amount) - - await invoke(`delegate_to_${data.nodeType}`, { + console.log({ + type: data.nodeType, identity: data.identity, amount, }) - .then((res: any) => { - console.log(res) - onSuccess(res) + delegatedToMixnode({ + type: data.nodeType, + identity: data.identity, + amount, + }) + .then((res) => { + const successResponse = res as DelegationResult + console.log(successResponse) + onSuccess( + `Successfully delated ${data.amount} punk to ${successResponse.source_address}` + ) getBalance.fetchBalance() }) .catch((e) => { diff --git a/tauri-wallet/src/routes/send/SendWizard.tsx b/tauri-wallet/src/routes/send/SendWizard.tsx index 11468a7e5d..8438f9ad95 100644 --- a/tauri-wallet/src/routes/send/SendWizard.tsx +++ b/tauri-wallet/src/routes/send/SendWizard.tsx @@ -3,14 +3,13 @@ import { useForm, FormProvider } from 'react-hook-form' import { yupResolver } from '@hookform/resolvers/yup' import { Button, Step, StepLabel, Stepper, Theme } from '@material-ui/core' import { useTheme } from '@material-ui/styles' -import { invoke } from '@tauri-apps/api' import { SendForm } from './SendForm' import { SendReview } from './SendReview' import { SendConfirmation } from './SendConfirmation' import { ClientContext } from '../../context/main' import { validationSchema } from './validationSchema' -import { TauriTxResult } from '../../types/rust/tauritxresult' -import { majorToMinor } from '../../requests' +import { TauriTxResult } from '../../types' +import { majorToMinor, send } from '../../requests' const defaultValues = { amount: '', @@ -64,7 +63,7 @@ export const SendWizard = () => { const formState = methods.getValues() const amount = await majorToMinor(formState.amount) - invoke('send', { + send({ amount, address: formState.to, memo: formState.memo, @@ -74,7 +73,7 @@ export const SendWizard = () => { setActiveStep((s) => s + 1) setConfirmedData({ ...details, - amount: { denom: 'punk', amount: formState.amount }, + amount: { denom: 'Major', amount: formState.amount }, }) setIsLoading(false) getBalance.fetchBalance() diff --git a/tauri-wallet/src/types/rust/index.ts b/tauri-wallet/src/types/rust/index.ts index 5d2ff697fc..74ca39a7df 100644 --- a/tauri-wallet/src/types/rust/index.ts +++ b/tauri-wallet/src/types/rust/index.ts @@ -1,8 +1,9 @@ export * from './balance' export * from './coin' -export * from './mixnode' +export * from './delegationresult' +export * from './denom' export * from './gateway' export * from './mixnode' +export * from './operation' export * from './tauritxresult' export * from './transactiondetails' -export * from './operation'