use wrapper functions for send and delegate
This commit is contained in:
@@ -1,5 +1,13 @@
|
|||||||
import { invoke } from '@tauri-apps/api'
|
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<TCreateAccount> =>
|
export const createAccount = async (): Promise<TCreateAccount> =>
|
||||||
await invoke('create_new_account')
|
await invoke('create_new_account')
|
||||||
@@ -17,3 +25,20 @@ export const majorToMinor = async (amount: string): Promise<Coin> =>
|
|||||||
|
|
||||||
export const getGasFee = async (operation: Operation): Promise<Coin> =>
|
export const getGasFee = async (operation: Operation): Promise<Coin> =>
|
||||||
await invoke('get_fee', { operation })
|
await invoke('get_fee', { operation })
|
||||||
|
|
||||||
|
export const delegatedToMixnode = async ({
|
||||||
|
type,
|
||||||
|
identity,
|
||||||
|
amount,
|
||||||
|
}: {
|
||||||
|
type: EnumNodeType
|
||||||
|
identity: string
|
||||||
|
amount: Coin
|
||||||
|
}): Promise<DelegationResult> =>
|
||||||
|
await invoke(`delegate_to_${type}`, { identity, amount })
|
||||||
|
|
||||||
|
export const send = async (args: {
|
||||||
|
amount: Coin
|
||||||
|
address: string
|
||||||
|
memo: string
|
||||||
|
}): Promise<TauriTxResult> => await invoke('send', args)
|
||||||
|
|||||||
@@ -11,13 +11,12 @@ import {
|
|||||||
} from '@material-ui/core'
|
} from '@material-ui/core'
|
||||||
import { useForm } from 'react-hook-form'
|
import { useForm } from 'react-hook-form'
|
||||||
import { NodeTypeSelector } from '../../components/NodeTypeSelector'
|
import { NodeTypeSelector } from '../../components/NodeTypeSelector'
|
||||||
import { EnumNodeType, TFee } from '../../types'
|
import { DelegationResult, EnumNodeType, TFee } from '../../types'
|
||||||
import { yupResolver } from '@hookform/resolvers/yup'
|
import { yupResolver } from '@hookform/resolvers/yup'
|
||||||
import { validationSchema } from './validationSchema'
|
import { validationSchema } from './validationSchema'
|
||||||
import { invoke } from '@tauri-apps/api'
|
|
||||||
import { Alert } from '@material-ui/lab'
|
import { Alert } from '@material-ui/lab'
|
||||||
import { ClientContext } from '../../context/main'
|
import { ClientContext } from '../../context/main'
|
||||||
import { majorToMinor } from '../../requests'
|
import { delegatedToMixnode, majorToMinor } from '../../requests'
|
||||||
|
|
||||||
type TDelegateForm = {
|
type TDelegateForm = {
|
||||||
nodeType: EnumNodeType
|
nodeType: EnumNodeType
|
||||||
@@ -58,14 +57,22 @@ export const DelegateForm = ({
|
|||||||
|
|
||||||
const onSubmit = async (data: TDelegateForm) => {
|
const onSubmit = async (data: TDelegateForm) => {
|
||||||
const amount = await majorToMinor(data.amount)
|
const amount = await majorToMinor(data.amount)
|
||||||
|
console.log({
|
||||||
await invoke(`delegate_to_${data.nodeType}`, {
|
type: data.nodeType,
|
||||||
identity: data.identity,
|
identity: data.identity,
|
||||||
amount,
|
amount,
|
||||||
})
|
})
|
||||||
.then((res: any) => {
|
delegatedToMixnode({
|
||||||
console.log(res)
|
type: data.nodeType,
|
||||||
onSuccess(res)
|
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()
|
getBalance.fetchBalance()
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
|
|||||||
@@ -3,14 +3,13 @@ import { useForm, FormProvider } from 'react-hook-form'
|
|||||||
import { yupResolver } from '@hookform/resolvers/yup'
|
import { yupResolver } from '@hookform/resolvers/yup'
|
||||||
import { Button, Step, StepLabel, Stepper, Theme } from '@material-ui/core'
|
import { Button, Step, StepLabel, Stepper, Theme } from '@material-ui/core'
|
||||||
import { useTheme } from '@material-ui/styles'
|
import { useTheme } from '@material-ui/styles'
|
||||||
import { invoke } from '@tauri-apps/api'
|
|
||||||
import { SendForm } from './SendForm'
|
import { SendForm } from './SendForm'
|
||||||
import { SendReview } from './SendReview'
|
import { SendReview } from './SendReview'
|
||||||
import { SendConfirmation } from './SendConfirmation'
|
import { SendConfirmation } from './SendConfirmation'
|
||||||
import { ClientContext } from '../../context/main'
|
import { ClientContext } from '../../context/main'
|
||||||
import { validationSchema } from './validationSchema'
|
import { validationSchema } from './validationSchema'
|
||||||
import { TauriTxResult } from '../../types/rust/tauritxresult'
|
import { TauriTxResult } from '../../types'
|
||||||
import { majorToMinor } from '../../requests'
|
import { majorToMinor, send } from '../../requests'
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
amount: '',
|
amount: '',
|
||||||
@@ -64,7 +63,7 @@ export const SendWizard = () => {
|
|||||||
const formState = methods.getValues()
|
const formState = methods.getValues()
|
||||||
const amount = await majorToMinor(formState.amount)
|
const amount = await majorToMinor(formState.amount)
|
||||||
|
|
||||||
invoke('send', {
|
send({
|
||||||
amount,
|
amount,
|
||||||
address: formState.to,
|
address: formState.to,
|
||||||
memo: formState.memo,
|
memo: formState.memo,
|
||||||
@@ -74,7 +73,7 @@ export const SendWizard = () => {
|
|||||||
setActiveStep((s) => s + 1)
|
setActiveStep((s) => s + 1)
|
||||||
setConfirmedData({
|
setConfirmedData({
|
||||||
...details,
|
...details,
|
||||||
amount: { denom: 'punk', amount: formState.amount },
|
amount: { denom: 'Major', amount: formState.amount },
|
||||||
})
|
})
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
getBalance.fetchBalance()
|
getBalance.fetchBalance()
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
export * from './balance'
|
export * from './balance'
|
||||||
export * from './coin'
|
export * from './coin'
|
||||||
export * from './mixnode'
|
export * from './delegationresult'
|
||||||
|
export * from './denom'
|
||||||
export * from './gateway'
|
export * from './gateway'
|
||||||
export * from './mixnode'
|
export * from './mixnode'
|
||||||
|
export * from './operation'
|
||||||
export * from './tauritxresult'
|
export * from './tauritxresult'
|
||||||
export * from './transactiondetails'
|
export * from './transactiondetails'
|
||||||
export * from './operation'
|
|
||||||
|
|||||||
Reference in New Issue
Block a user