diff --git a/tauri-wallet/src/components/AdminForm.tsx b/tauri-wallet/src/components/AdminForm.tsx index 9c11370ae0..f3ac868a72 100644 --- a/tauri-wallet/src/components/AdminForm.tsx +++ b/tauri-wallet/src/components/AdminForm.tsx @@ -1,7 +1,8 @@ -import React, { useContext } from 'react' +import React, { useContext, useEffect, useState } from 'react' import { useForm } from 'react-hook-form' import { Backdrop, + Box, Button, CircularProgress, FormControl, @@ -14,20 +15,45 @@ import { import { useTheme } from '@material-ui/styles' import { ClientContext } from '../context/main' import { NymCard } from '.' +import { getContractParams, setContractParams } from '../requests' +import { TauriStateParams } from '../types' export const Admin: React.FC = () => { const { showAdmin, handleShowAdmin } = useContext(ClientContext) + const [isLoading, setIsLoading] = useState(false) + const [params, setParams] = useState() const onCancel = () => { + setParams(undefined) + setIsLoading(false) handleShowAdmin() } + useEffect(() => { + const requestContractParams = async () => { + if (showAdmin) { + setIsLoading(true) + const params = await getContractParams() + setParams(params) + setIsLoading(false) + } + } + requestContractParams() + }, [showAdmin]) + return ( - + {isLoading && ( + + + + )} + {!isLoading && params && ( + + )} @@ -35,14 +61,18 @@ export const Admin: React.FC = () => { ) } -const AdminForm: React.FC<{ onCancel: () => void }> = ({ onCancel }) => { +const AdminForm: React.FC<{ + params: TauriStateParams + onCancel: () => void +}> = ({ params, onCancel }) => { const { register, handleSubmit, formState: { errors, isSubmitting }, - } = useForm() + } = useForm({ defaultValues: { ...params } }) - const onSubmit = (data: any) => { + const onSubmit = async (data: TauriStateParams) => { + await setContractParams(data) console.log(data) onCancel() } @@ -51,110 +81,112 @@ const AdminForm: React.FC<{ onCancel: () => void }> = ({ onCancel }) => { return ( -
+
diff --git a/tauri-wallet/src/requests/index.ts b/tauri-wallet/src/requests/index.ts index ccf86222a6..ed94e7c503 100644 --- a/tauri-wallet/src/requests/index.ts +++ b/tauri-wallet/src/requests/index.ts @@ -7,6 +7,7 @@ import { Gateway, MixNode, Operation, + TauriStateParams, TauriTxResult, TCreateAccount, TSignInWithMnemonic, @@ -75,3 +76,10 @@ export const unbond = async (type: EnumNodeType) => export const getBalance = async (): Promise => await invoke('get_balance') + +export const getContractParams = async (): Promise => + await invoke('get_state_params') + +export const setContractParams = async ( + params: TauriStateParams +): Promise => await invoke('update_state_params', { params }) diff --git a/tauri-wallet/src/types/rust/index.ts b/tauri-wallet/src/types/rust/index.ts index 74ca39a7df..8e22182af6 100644 --- a/tauri-wallet/src/types/rust/index.ts +++ b/tauri-wallet/src/types/rust/index.ts @@ -1,3 +1,4 @@ +export * from './account' export * from './balance' export * from './coin' export * from './delegationresult' @@ -5,5 +6,6 @@ export * from './denom' export * from './gateway' export * from './mixnode' export * from './operation' +export * from './stateparams' export * from './tauritxresult' export * from './transactiondetails'