use wrapper functions for send and delegate
This commit is contained in:
@@ -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<TCreateAccount> =>
|
||||
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> =>
|
||||
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'
|
||||
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) => {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user