From 47ffdfe496d2bc9608cc884c15aaaa3792aea269 Mon Sep 17 00:00:00 2001 From: fmtabbara Date: Sun, 13 Mar 2022 01:20:46 +0000 Subject: [PATCH] linting, conflict fixes, and general tidy --- .../src/operations/vesting/queries.rs | 3 +- .../src/components/TokenPoolSelector.tsx | 7 +- nym-wallet/src/components/index.ts | 1 - nym-wallet/src/context/main.tsx | 7 +- nym-wallet/src/hooks/useCheckOwnership.ts | 2 +- nym-wallet/src/hooks/useGetBalance.ts | 8 +- nym-wallet/src/index.tsx | 3 +- nym-wallet/src/layouts/AppLayout.tsx | 2 +- .../balance/components/vesting-timeline.tsx | 2 +- nym-wallet/src/pages/balance/vesting.tsx | 2 +- nym-wallet/src/pages/bond/SuccessView.tsx | 2 +- nym-wallet/src/pages/bond/index.tsx | 6 +- nym-wallet/src/pages/bond/validationSchema.ts | 53 +++++-------- .../src/pages/delegate/DelegateForm.tsx | 2 +- .../src/pages/delegate/validationSchema.ts | 20 ++--- nym-wallet/src/pages/send/SendForm.tsx | 2 +- nym-wallet/src/pages/send/SendWizard.tsx | 1 + .../src/pages/settings/system-variables.tsx | 7 +- .../src/pages/undelegate/UndelegateForm.tsx | 2 +- .../pages/welcome/_legacy_create-account.tsx | 4 +- .../src/pages/welcome/_legacy_sign-in.tsx | 2 +- .../welcome/components/password-strength.tsx | 1 + nym-wallet/src/pages/welcome/index.tsx | 2 +- .../pages/welcome/pages/existing-account.tsx | 4 +- nym-wallet/src/requests/account.ts | 15 +++- nym-wallet/src/requests/actions.ts | 26 +++++-- nym-wallet/src/requests/coin.ts | 10 ++- nym-wallet/src/requests/contract.ts | 11 ++- nym-wallet/src/requests/network.ts | 5 +- nym-wallet/src/requests/queries.ts | 62 ++++++++++----- nym-wallet/src/requests/vesting.ts | 75 ++++++++++++------- nym-wallet/src/types/global.ts | 2 +- nym-wallet/src/utils/index.ts | 5 +- 33 files changed, 212 insertions(+), 144 deletions(-) diff --git a/nym-wallet/src-tauri/src/operations/vesting/queries.rs b/nym-wallet/src-tauri/src/operations/vesting/queries.rs index 94b9c09bcf..3903c30601 100644 --- a/nym-wallet/src-tauri/src/operations/vesting/queries.rs +++ b/nym-wallet/src-tauri/src/operations/vesting/queries.rs @@ -29,14 +29,13 @@ pub async fn locked_coins( #[tauri::command] pub async fn spendable_coins( - vesting_account_address: &str, block_time: Option, state: tauri::State<'_, Arc>>, ) -> Result { Ok( nymd_client!(state) .spendable_coins( - vesting_account_address, + &nymd_client!(state).address().to_string(), block_time.map(Timestamp::from_seconds), ) .await? diff --git a/nym-wallet/src/components/TokenPoolSelector.tsx b/nym-wallet/src/components/TokenPoolSelector.tsx index e09c51c10d..bf0a778dfd 100644 --- a/nym-wallet/src/components/TokenPoolSelector.tsx +++ b/nym-wallet/src/components/TokenPoolSelector.tsx @@ -39,7 +39,12 @@ export const TokenPoolSelector: React.FC<{ onSelect: (pool: TPoolOption) => void /> - + {tokenAllocation && ( + + )} diff --git a/nym-wallet/src/components/index.ts b/nym-wallet/src/components/index.ts index a6d1406143..2b04937757 100644 --- a/nym-wallet/src/components/index.ts +++ b/nym-wallet/src/components/index.ts @@ -13,6 +13,5 @@ export * from './AppBar'; export * from './NetworkSelector'; export * from './ClientAddress'; export * from './InfoToolTip'; -export * from './Nav'; export * from './Title'; export * from './TokenPoolSelector'; diff --git a/nym-wallet/src/context/main.tsx b/nym-wallet/src/context/main.tsx index 8f022fdd44..dd3e9e5671 100644 --- a/nym-wallet/src/context/main.tsx +++ b/nym-wallet/src/context/main.tsx @@ -1,12 +1,11 @@ -import React, { createContext, useEffect, useState } from 'react'; +import React, { useMemo, createContext, useEffect, useState } from 'react'; +import { useHistory } from 'react-router-dom'; +import { useSnackbar } from 'notistack'; import { Account, Network, TCurrency, TMixnodeBondDetails } from '../types'; import { TUseuserBalance, useGetBalance } from '../hooks/useGetBalance'; import { config } from '../../config'; import { getMixnodeBondDetails, selectNetwork, signInWithMnemonic, signOut } from '../requests'; import { currencyMap } from '../utils'; -import { useHistory } from 'react-router-dom'; -import { useSnackbar } from 'notistack'; -import { useMemo } from 'react'; export const { ADMIN_ADDRESS, IS_DEV_MODE } = config; diff --git a/nym-wallet/src/hooks/useCheckOwnership.ts b/nym-wallet/src/hooks/useCheckOwnership.ts index bbbafa345a..3612637c24 100644 --- a/nym-wallet/src/hooks/useCheckOwnership.ts +++ b/nym-wallet/src/hooks/useCheckOwnership.ts @@ -1,7 +1,7 @@ import { useCallback, useContext, useEffect, useState } from 'react'; import { ClientContext } from '../context/main'; import { checkGatewayOwnership, checkMixnodeOwnership, getVestingPledgeInfo } from '../requests'; -import { EnumNodeType, TNodeOwnership, PledgeData } from '../types'; +import { EnumNodeType, TNodeOwnership } from '../types'; const initial = { hasOwnership: false, diff --git a/nym-wallet/src/hooks/useGetBalance.ts b/nym-wallet/src/hooks/useGetBalance.ts index e7c7409207..cd70d9d749 100644 --- a/nym-wallet/src/hooks/useGetBalance.ts +++ b/nym-wallet/src/hooks/useGetBalance.ts @@ -60,7 +60,7 @@ export const useGetBalance = (address?: string): TUseuserBalance => { getVestingCoins(address), getVestedCoins(address), getLockedCoins(), - getSpendableCoins(address), + getSpendableCoins(), getCurrentVestingPeriod(address), getVestingAccountInfo(address), ]); @@ -103,10 +103,10 @@ export const useGetBalance = (address?: string): TUseuserBalance => { clearOriginalVesting(); }; - const handleRefresh = (addr?: string) => { + const handleRefresh = async (addr?: string) => { if (addr) { - fetchBalance(); - fetchTokenAllocation(); + await fetchBalance(); + await fetchTokenAllocation(); } else { clearAll(); } diff --git a/nym-wallet/src/index.tsx b/nym-wallet/src/index.tsx index d99afdb70b..f05b529d07 100644 --- a/nym-wallet/src/index.tsx +++ b/nym-wallet/src/index.tsx @@ -6,10 +6,9 @@ import { SnackbarProvider } from 'notistack'; import { Routes } from './routes'; import { ClientContext, ClientContextProvider } from './context/main'; import { ApplicationLayout } from './layouts'; -import { Admin, Welcome } from './pages'; +import { Admin, Welcome, Settings } from './pages'; import { ErrorFallback } from './components'; import { NymWalletTheme, WelcomeTheme } from './theme'; -import { Settings } from './pages'; import { maximizeWindow } from './utils'; const App = () => { diff --git a/nym-wallet/src/layouts/AppLayout.tsx b/nym-wallet/src/layouts/AppLayout.tsx index e0a6bf911e..e7bb19327f 100644 --- a/nym-wallet/src/layouts/AppLayout.tsx +++ b/nym-wallet/src/layouts/AppLayout.tsx @@ -1,7 +1,7 @@ import React from 'react'; +import { NymLogo } from '@nymproject/react'; import { Box, Container } from '@mui/material'; import { AppBar, Nav } from '../components'; -import { NymLogo } from '@nymproject/react'; export const ApplicationLayout: React.FC = ({ children }) => ( = ({ perc tooltipText="End of vesting schedule" /> - {nextPeriod && ( + {!!nextPeriod && ( Next vesting period: {format(new Date(nextPeriod * 1000), 'HH:mm do MMM yyyy')} diff --git a/nym-wallet/src/pages/balance/vesting.tsx b/nym-wallet/src/pages/balance/vesting.tsx index 09a2faa9c1..5bfb70bff6 100644 --- a/nym-wallet/src/pages/balance/vesting.tsx +++ b/nym-wallet/src/pages/balance/vesting.tsx @@ -120,9 +120,9 @@ const TokenTransfer = () => { }; export const VestingCard = () => { - const { userBalance } = useContext(ClientContext); const [isLoading, setIsLoading] = useState(false); + const { userBalance } = useContext(ClientContext); const { enqueueSnackbar, closeSnackbar } = useSnackbar(); const refreshBalances = async () => { diff --git a/nym-wallet/src/pages/bond/SuccessView.tsx b/nym-wallet/src/pages/bond/SuccessView.tsx index 9abbebe118..7d5a509162 100644 --- a/nym-wallet/src/pages/bond/SuccessView.tsx +++ b/nym-wallet/src/pages/bond/SuccessView.tsx @@ -1,5 +1,5 @@ import React, { useContext } from 'react'; -import { Box } from '@mui/system'; +import { Box } from '@mui/material'; import { SuccessReponse, TransactionDetails } from '../../components'; import { ClientContext } from '../../context/main'; import { useCheckOwnership } from '../../hooks/useCheckOwnership'; diff --git a/nym-wallet/src/pages/bond/index.tsx b/nym-wallet/src/pages/bond/index.tsx index b6c4047b7f..c052018ae7 100644 --- a/nym-wallet/src/pages/bond/index.tsx +++ b/nym-wallet/src/pages/bond/index.tsx @@ -1,5 +1,6 @@ import React, { useEffect, useState } from 'react'; import { Alert, Box, Button, CircularProgress } from '@mui/material'; +import { useSnackbar } from 'notistack'; import { BondForm } from './BondForm'; import { SuccessView } from './SuccessView'; import { NymCard } from '../../components'; @@ -7,7 +8,6 @@ import { EnumRequestStatus, RequestStatus } from '../../components/RequestStatus import { unbond, vestingUnbond } from '../../requests'; import { useCheckOwnership } from '../../hooks/useCheckOwnership'; import { PageLayout } from '../../layouts'; -import { useSnackbar } from 'notistack'; export const Bond = () => { const [status, setStatus] = useState(EnumRequestStatus.initial); @@ -19,7 +19,9 @@ export const Bond = () => { useEffect(() => { if (status === EnumRequestStatus.initial) { - const initialiseForm = async () => await checkOwnership(); + const initialiseForm = async () => { + await checkOwnership(); + }; initialiseForm(); } }, [status, checkOwnership]); diff --git a/nym-wallet/src/pages/bond/validationSchema.ts b/nym-wallet/src/pages/bond/validationSchema.ts index db49ce41a9..c4ddf4901d 100644 --- a/nym-wallet/src/pages/bond/validationSchema.ts +++ b/nym-wallet/src/pages/bond/validationSchema.ts @@ -13,21 +13,15 @@ import { export const validationSchema = Yup.object().shape({ identityKey: Yup.string() .required('An indentity key is required') - .test('valid-id-key', 'A valid identity key is required', function (value) { - return validateKey(value || '', 32); - }), + .test('valid-id-key', 'A valid identity key is required', (value) => validateKey(value || '', 32)), sphinxKey: Yup.string() .required('A sphinx key is required') - .test('valid-sphinx-key', 'A valid sphinx key is required', function (value) { - return validateKey(value || '', 32); - }), + .test('valid-sphinx-key', 'A valid sphinx key is required', (value) => validateKey(value || '', 32)), ownerSignature: Yup.string() .required('Signature is required') - .test('valid-signature', 'A valid signature is required', function (value) { - return validateKey(value || '', 64); - }), + .test('valid-signature', 'A valid signature is required', (value) => validateKey(value || '', 64)), profitMarginPercent: Yup.number().required('Profit Percentage is required').min(0).max(100), @@ -37,17 +31,16 @@ export const validationSchema = Yup.object().shape({ const isValid = await validateAmount(value || '', '100000000'); if (!isValid) { - return this.createError({ message: `A valid amount is required (min 100)` }); - } else { - const hasEnoughBalance = await checkHasEnoughFunds(value || ''); - const hasEnoughLocked = await checkHasEnoughLockedTokens(value || ''); - if (this.parent.tokenPool === 'balance' && !hasEnoughBalance) { - return this.createError({ message: 'Not enough funds in wallet' }); - } + return this.createError({ message: 'A valid amount is required (min 100)' }); + } + const hasEnoughBalance = await checkHasEnoughFunds(value || ''); + const hasEnoughLocked = await checkHasEnoughLockedTokens(value || ''); + if (this.parent.tokenPool === 'balance' && !hasEnoughBalance) { + return this.createError({ message: 'Not enough funds in wallet' }); + } - if (this.parent.tokenPool === 'locked' && !hasEnoughLocked) { - return this.createError({ message: 'Not enough locked tokens' }); - } + if (this.parent.tokenPool === 'locked' && !hasEnoughLocked) { + return this.createError({ message: 'Not enough locked tokens' }); } return true; @@ -55,18 +48,14 @@ export const validationSchema = Yup.object().shape({ host: Yup.string() .required('A host is required') - .test('valid-host', 'A valid host is required', function (value) { - return !!value ? isValidHostname(value) : false; - }), + .test('valid-host', 'A valid host is required', (value) => (value ? isValidHostname(value) : false)), version: Yup.string() .required('A version is required') - .test('valid-version', 'A valid version is required', function (value) { - return !!value ? validateVersion(value) : false; - }), + .test('valid-version', 'A valid version is required', (value) => (value ? validateVersion(value) : false)), location: Yup.lazy((value) => { - if (!!value) { + if (value) { return Yup.string() .required('A location is required') .test('valid-location', 'A valid version is required', (locationValueTest) => @@ -78,21 +67,15 @@ export const validationSchema = Yup.object().shape({ mixPort: Yup.number() .required('A mixport is required') - .test('valid-mixport', 'A valid mixport is required', function (value) { - return !!value ? validateRawPort(value) : false; - }), + .test('valid-mixport', 'A valid mixport is required', (value) => (value ? validateRawPort(value) : false)), verlocPort: Yup.number() .required('A verloc port is required') - .test('valid-verloc', 'A valid verloc port is required', function (value) { - return !!value ? validateRawPort(value) : false; - }), + .test('valid-verloc', 'A valid verloc port is required', (value) => (value ? validateRawPort(value) : false)), httpApiPort: Yup.number() .required('A http-api port is required') - .test('valid-http', 'A valid http-api port is required', function (value) { - return !!value ? validateRawPort(value) : false; - }), + .test('valid-http', 'A valid http-api port is required', (value) => (value ? validateRawPort(value) : false)), clientsPort: Yup.number() .required('A clients port is required') diff --git a/nym-wallet/src/pages/delegate/DelegateForm.tsx b/nym-wallet/src/pages/delegate/DelegateForm.tsx index 1670502130..a3d1cd369a 100644 --- a/nym-wallet/src/pages/delegate/DelegateForm.tsx +++ b/nym-wallet/src/pages/delegate/DelegateForm.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useContext } from 'react'; -import { Box, Button, CircularProgress, FormControl, Grid, InputAdornment, TextField, Typography } from '@mui/material'; +import { Box, Button, CircularProgress, FormControl, Grid, InputAdornment, TextField } from '@mui/material'; import { yupResolver } from '@hookform/resolvers/yup'; import { useForm } from 'react-hook-form'; import { DelegationResult, EnumNodeType, TDelegateArgs } from '../../types'; diff --git a/nym-wallet/src/pages/delegate/validationSchema.ts b/nym-wallet/src/pages/delegate/validationSchema.ts index e461086cfd..251b54135b 100644 --- a/nym-wallet/src/pages/delegate/validationSchema.ts +++ b/nym-wallet/src/pages/delegate/validationSchema.ts @@ -16,18 +16,18 @@ export const validationSchema = Yup.object().shape({ const isValid = await validateAmount(value || '', '0'); if (!isValid) { - return this.createError({ message: `A valid amount is required` }); - } else { - const hasEnoughBalance = await checkHasEnoughFunds(value || ''); - const hasEnoughLocked = await checkHasEnoughLockedTokens(value || ''); + return this.createError({ message: 'A valid amount is required' }); + } - if (this.parent.tokenPool === 'balance' && !hasEnoughBalance) { - return this.createError({ message: 'Not enough funds in wallet' }); - } + const hasEnoughBalance = await checkHasEnoughFunds(value || ''); + const hasEnoughLocked = await checkHasEnoughLockedTokens(value || ''); - if (this.parent.tokenPool === 'locked' && !hasEnoughLocked) { - return this.createError({ message: 'Not enough locked tokens' }); - } + if (this.parent.tokenPool === 'balance' && !hasEnoughBalance) { + return this.createError({ message: 'Not enough funds in wallet' }); + } + + if (this.parent.tokenPool === 'locked' && !hasEnoughLocked) { + return this.createError({ message: 'Not enough locked tokens' }); } return true; diff --git a/nym-wallet/src/pages/send/SendForm.tsx b/nym-wallet/src/pages/send/SendForm.tsx index a3e112bd02..7fc635dbb6 100644 --- a/nym-wallet/src/pages/send/SendForm.tsx +++ b/nym-wallet/src/pages/send/SendForm.tsx @@ -2,7 +2,7 @@ import React, { useContext } from 'react'; import { Grid, InputAdornment, TextField } from '@mui/material'; import { useFormContext } from 'react-hook-form'; import { ClientContext } from '../../context/main'; -import { Fee, ClientAddress } from '../../components'; +import { Fee } from '../../components'; export const SendForm = () => { const { diff --git a/nym-wallet/src/pages/send/SendWizard.tsx b/nym-wallet/src/pages/send/SendWizard.tsx index 58271e64c9..c70c729df1 100644 --- a/nym-wallet/src/pages/send/SendWizard.tsx +++ b/nym-wallet/src/pages/send/SendWizard.tsx @@ -1,3 +1,4 @@ +/* eslint-disable no-nested-ternary */ import React, { useEffect, useContext, useState } from 'react'; import { useForm, FormProvider } from 'react-hook-form'; import { yupResolver } from '@hookform/resolvers/yup'; diff --git a/nym-wallet/src/pages/settings/system-variables.tsx b/nym-wallet/src/pages/settings/system-variables.tsx index 22fab23fd2..b8d594d458 100644 --- a/nym-wallet/src/pages/settings/system-variables.tsx +++ b/nym-wallet/src/pages/settings/system-variables.tsx @@ -1,14 +1,15 @@ +/* eslint-disable no-nested-ternary */ import React, { useContext, useState } from 'react'; import { Box, Button, CircularProgress, Grid, LinearProgress, Stack, TextField, Typography } from '@mui/material'; import { PercentOutlined } from '@mui/icons-material'; import { yupResolver } from '@hookform/resolvers/yup'; import { useForm } from 'react-hook-form'; +import { validationSchema } from './validationSchema'; import { Fee, InfoTooltip } from '../../components'; import { InclusionProbabilityResponse } from '../../types'; -import { validationSchema } from './validationSchema'; +import { useCheckOwnership } from '../../hooks/useCheckOwnership'; import { updateMixnode, vestingUpdateMixnode } from '../../requests'; import { ClientContext } from '../../context/main'; -import { useCheckOwnership } from 'src/hooks/useCheckOwnership'; const DataField = ({ title, info, Indicator }: { title: string; info: string; Indicator: React.ReactElement }) => ( @@ -55,7 +56,7 @@ export const SystemVariables = ({ inclusionProbability: InclusionProbabilityResponse; }) => { const [nodeUpdateResponse, setNodeUpdateResponse] = useState<'success' | 'failed'>(); - const { currency, mixnodeDetails, getBondDetails } = useContext(ClientContext); + const { currency, mixnodeDetails } = useContext(ClientContext); const { ownership } = useCheckOwnership(); const { diff --git a/nym-wallet/src/pages/undelegate/UndelegateForm.tsx b/nym-wallet/src/pages/undelegate/UndelegateForm.tsx index 8e2e8f3fd0..c09625bf91 100644 --- a/nym-wallet/src/pages/undelegate/UndelegateForm.tsx +++ b/nym-wallet/src/pages/undelegate/UndelegateForm.tsx @@ -1,4 +1,4 @@ -import React, { useContext } from 'react'; +import React from 'react'; import { useForm, Controller } from 'react-hook-form'; import { Box, Autocomplete, Button, CircularProgress, FormControl, Grid, TextField } from '@mui/material'; import { yupResolver } from '@hookform/resolvers/yup'; diff --git a/nym-wallet/src/pages/welcome/_legacy_create-account.tsx b/nym-wallet/src/pages/welcome/_legacy_create-account.tsx index f11f208873..05df9e4b8a 100644 --- a/nym-wallet/src/pages/welcome/_legacy_create-account.tsx +++ b/nym-wallet/src/pages/welcome/_legacy_create-account.tsx @@ -1,4 +1,4 @@ -/* eslint-disable react/no-unused-prop-types */ +/* eslint-disable no-unused-vars */ import React, { useEffect, useState } from 'react'; import { Alert, Button, Card, CardActions, CardContent, CardHeader, Stack, Typography } from '@mui/material'; import { createAccount } from '../../requests'; @@ -25,7 +25,7 @@ export const CreateAccountContent: React.FC<{ page: TPages; showSignIn: () => vo }, []); return ( - + Congratulations diff --git a/nym-wallet/src/pages/welcome/_legacy_sign-in.tsx b/nym-wallet/src/pages/welcome/_legacy_sign-in.tsx index 6a93cb26d7..8f90b1f1ef 100644 --- a/nym-wallet/src/pages/welcome/_legacy_sign-in.tsx +++ b/nym-wallet/src/pages/welcome/_legacy_sign-in.tsx @@ -1,7 +1,7 @@ import React, { useContext, useState } from 'react'; +import { NymLogo } from '@nymproject/react'; import { Alert, Button, CircularProgress, Grid, Stack, Typography } from '@mui/material'; import { ClientContext } from '../../context/main'; -import { NymLogo } from '@nymproject/react'; export const SignInContent: React.FC = () => { const [mnemonic] = useState(''); diff --git a/nym-wallet/src/pages/welcome/components/password-strength.tsx b/nym-wallet/src/pages/welcome/components/password-strength.tsx index 9eff1aabf4..04e9e5e7cb 100644 --- a/nym-wallet/src/pages/welcome/components/password-strength.tsx +++ b/nym-wallet/src/pages/welcome/components/password-strength.tsx @@ -1,3 +1,4 @@ +/* eslint-disable no-nested-ternary */ import React, { useEffect, useState } from 'react'; import { LockOutlined } from '@mui/icons-material'; import { LinearProgress, Stack, Typography, Box } from '@mui/material'; diff --git a/nym-wallet/src/pages/welcome/index.tsx b/nym-wallet/src/pages/welcome/index.tsx index 4060e72119..c23444dbdf 100644 --- a/nym-wallet/src/pages/welcome/index.tsx +++ b/nym-wallet/src/pages/welcome/index.tsx @@ -1,7 +1,7 @@ import React, { useContext, useState } from 'react'; +import { NymLogo } from '@nymproject/react'; import { CircularProgress, Stack, Box } from '@mui/material'; import { ExistingAccount, WelcomeContent } from './pages'; -import { NymLogo } from '@nymproject/react'; import { TPages } from './types'; import { RenderPage } from './components'; import { CreateAccountContent } from './_legacy_create-account'; diff --git a/nym-wallet/src/pages/welcome/pages/existing-account.tsx b/nym-wallet/src/pages/welcome/pages/existing-account.tsx index 7cf7db9d12..e0a4800cd8 100644 --- a/nym-wallet/src/pages/welcome/pages/existing-account.tsx +++ b/nym-wallet/src/pages/welcome/pages/existing-account.tsx @@ -10,8 +10,8 @@ export const ExistingAccount: React.FC<{ page: TPages; onPrev: () => void }> = ( const { logIn, error } = useContext(ClientContext); - const handleSignIn = async ({ preventDefault }: React.MouseEvent) => { - logIn(mnemonic); + const handleSignIn = async () => { + await logIn(mnemonic); }; const handleSignInOnEnter = ({ key }: React.KeyboardEvent) => { diff --git a/nym-wallet/src/requests/account.ts b/nym-wallet/src/requests/account.ts index d4114de91f..ed1ce4fb38 100644 --- a/nym-wallet/src/requests/account.ts +++ b/nym-wallet/src/requests/account.ts @@ -1,9 +1,16 @@ import { invoke } from '@tauri-apps/api'; import { Account, TCreateAccount } from '../types'; -export const createAccount = async (): Promise => invoke('create_new_account'); +export const createAccount = async (): Promise => { + const res: TCreateAccount = await invoke('create_new_account'); + return res; +}; -export const signInWithMnemonic = async (mnemonic: string): Promise => - invoke('connect_with_mnemonic', { mnemonic }); +export const signInWithMnemonic = async (mnemonic: string): Promise => { + const res: Account = await invoke('connect_with_mnemonic', { mnemonic }); + return res; +}; -export const signOut = async () => invoke('logout'); +export const signOut = async (): Promise => { + await invoke('logout'); +}; diff --git a/nym-wallet/src/requests/actions.ts b/nym-wallet/src/requests/actions.ts index 4e69a89744..42bf5ef4ae 100644 --- a/nym-wallet/src/requests/actions.ts +++ b/nym-wallet/src/requests/actions.ts @@ -1,10 +1,13 @@ import { invoke } from '@tauri-apps/api'; -import { Coin, DelegationResult, EnumNodeType, Gateway, MixNode, TauriTxResult, TBondArgs } from '../types'; +import { Coin, DelegationResult, EnumNodeType, TauriTxResult, TBondArgs } from '../types'; -export const bond = async ({ type, data, pledge, ownerSignature }: TBondArgs): Promise => +export const bond = async ({ type, data, pledge, ownerSignature }: TBondArgs): Promise => { await invoke(`bond_${type}`, { [type]: data, ownerSignature, pledge }); +}; -export const unbond = async (type: EnumNodeType) => invoke(`unbond_${type}`); +export const unbond = async (type: EnumNodeType): Promise => { + await invoke(`unbond_${type}`); +}; export const delegate = async ({ type, @@ -14,7 +17,10 @@ export const delegate = async ({ type: EnumNodeType; identity: string; amount: Coin; -}): Promise => invoke(`delegate_to_${type}`, { identity, amount }); +}): Promise => { + const res: DelegationResult = await invoke(`delegate_to_${type}`, { identity, amount }); + return res; +}; export const undelegate = async ({ type, @@ -24,15 +30,19 @@ export const undelegate = async ({ identity: string; }): Promise => { try { - return await invoke(`undelegate_from_${type}`, { identity }); + const res: DelegationResult = await invoke(`undelegate_from_${type}`, { identity }); + return res; } catch (e) { console.log(e); return undefined; } }; -export const send = async (args: { amount: Coin; address: string; memo: string }): Promise => - invoke('send', args); +export const send = async (args: { amount: Coin; address: string; memo: string }): Promise => { + const res: TauriTxResult = await invoke('send', args); + return res; +}; -export const updateMixnode = async (profitMarginPercent: number) => +export const updateMixnode = async (profitMarginPercent: number): Promise => { await invoke('update_mixnode', { profitMarginPercent }); +}; diff --git a/nym-wallet/src/requests/coin.ts b/nym-wallet/src/requests/coin.ts index de23e2a902..b1cac920bb 100644 --- a/nym-wallet/src/requests/coin.ts +++ b/nym-wallet/src/requests/coin.ts @@ -1,6 +1,12 @@ import { invoke } from '@tauri-apps/api'; import { Coin } from '../types'; -export const minorToMajor = async (amount: string): Promise => invoke('minor_to_major', { amount }); +export const minorToMajor = async (amount: string): Promise => { + const res: Coin = await invoke('minor_to_major', { amount }); + return res; +}; -export const majorToMinor = async (amount: string): Promise => invoke('major_to_minor', { amount }); +export const majorToMinor = async (amount: string): Promise => { + const res: Coin = await invoke('major_to_minor', { amount }); + return res; +}; diff --git a/nym-wallet/src/requests/contract.ts b/nym-wallet/src/requests/contract.ts index 52f79be147..cd72e10c69 100644 --- a/nym-wallet/src/requests/contract.ts +++ b/nym-wallet/src/requests/contract.ts @@ -1,7 +1,12 @@ import { invoke } from '@tauri-apps/api'; import { TauriContractStateParams } from '../types'; -export const getContractParams = async (): Promise => invoke('get_contract_settings'); +export const getContractParams = async (): Promise => { + const res: TauriContractStateParams = await invoke('get_contract_settings'); + return res; +}; -export const setContractParams = async (params: TauriContractStateParams): Promise => - invoke('update_contract_settings', { params }); +export const setContractParams = async (params: TauriContractStateParams): Promise => { + const res: TauriContractStateParams = await invoke('update_contract_settings', { params }); + return res; +}; diff --git a/nym-wallet/src/requests/network.ts b/nym-wallet/src/requests/network.ts index d260c2d923..336bb45712 100644 --- a/nym-wallet/src/requests/network.ts +++ b/nym-wallet/src/requests/network.ts @@ -1,4 +1,7 @@ import { invoke } from '@tauri-apps/api'; import { Account, Network } from '../types'; -export const selectNetwork = async (network: Network): Promise => invoke('switch_network', { network }); +export const selectNetwork = async (network: Network): Promise => { + const res: Account = await invoke('switch_network', { network }); + return res; +}; diff --git a/nym-wallet/src/requests/queries.ts b/nym-wallet/src/requests/queries.ts index d8cf3e54d5..bcd9c40293 100644 --- a/nym-wallet/src/requests/queries.ts +++ b/nym-wallet/src/requests/queries.ts @@ -11,33 +11,59 @@ import { TPagedDelegations, } from '../types'; -export const getReverseMixDelegations = async (): Promise => - invoke('get_reverse_mix_delegations_paged'); +export const getReverseMixDelegations = async (): Promise => { + const res: TPagedDelegations = await invoke('get_reverse_mix_delegations_paged'); + return res; +}; -export const getReverseGatewayDelegations = async (): Promise => - invoke('get_reverse_gateway_delegations_paged'); +export const getReverseGatewayDelegations = async (): Promise => { + const res: TPagedDelegations = await invoke('get_reverse_gateway_delegations_paged'); + return res; +}; -export const getMixnodeBondDetails = async (): Promise => invoke('mixnode_bond_details'); +export const getMixnodeBondDetails = async (): Promise => { + const res: TMixnodeBondDetails = await invoke('mixnode_bond_details'); + return res; +}; -export const getMixnodeStakeSaturation = async (identity: string): Promise => - invoke('mixnode_stake_saturation', { identity }); +export const getMixnodeStakeSaturation = async (identity: string): Promise => { + const res: StakeSaturationResponse = await invoke('mixnode_stake_saturation', { identity }); + return res; +}; -export const getMixnodeRewardEstimation = async (identity: string): Promise => - invoke('mixnode_reward_estimation', { identity }); +export const getMixnodeRewardEstimation = async (identity: string): Promise => { + const res: RewardEstimationResponse = await invoke('mixnode_reward_estimation', { identity }); + return res; +}; -export const getMixnodeStatus = async (identity: string): Promise => - invoke('mixnode_status', { identity }); +export const getMixnodeStatus = async (identity: string): Promise => { + const res: MixnodeStatusResponse = await invoke('mixnode_status', { identity }); + return res; +}; -export const checkMixnodeOwnership = async (): Promise => invoke('owns_mixnode'); +export const checkMixnodeOwnership = async (): Promise => { + const res: boolean = await invoke('owns_mixnode'); + return res; +}; -export const checkGatewayOwnership = async (): Promise => invoke('owns_gateway'); +export const checkGatewayOwnership = async (): Promise => { + const res: boolean = await invoke('owns_gateway'); + return res; +}; // NOTE: this uses OUTDATED defaults that might have no resemblance with the reality // as for the actual transaction, the gas cost is being simulated beforehand -export const getGasFee = async (operation: Operation): Promise => - invoke('outdated_get_approximate_fee', { operation }); +export const getGasFee = async (operation: Operation): Promise => { + const res: Coin = await invoke('outdated_get_approximate_fee', { operation }); + return res; +}; -export const getInclusionProbability = async (identity: string): Promise => - invoke('mixnode_inclusion_probability', { identity }); +export const getInclusionProbability = async (identity: string): Promise => { + const res: InclusionProbabilityResponse = await invoke('mixnode_inclusion_probability', { identity }); + return res; +}; -export const userBalance = async (): Promise => invoke('get_balance'); +export const userBalance = async (): Promise => { + const res: Balance = await invoke('get_balance'); + return res; +}; diff --git a/nym-wallet/src/requests/vesting.ts b/nym-wallet/src/requests/vesting.ts index ac96257776..48ec8cf273 100644 --- a/nym-wallet/src/requests/vesting.ts +++ b/nym-wallet/src/requests/vesting.ts @@ -1,6 +1,6 @@ import { invoke } from '@tauri-apps/api'; import { VestingAccountInfo } from 'src/types/rust/vestingaccountinfo'; -import { majorToMinor, minorToMajor } from '.'; +import { majorToMinor, minorToMajor } from './coin'; import { Coin, DelegationResult, @@ -13,37 +13,44 @@ import { } from '../types'; export const getLockedCoins = async (): Promise => { - const res: Coin = await invoke('locked_coins'); - return await minorToMajor(res.amount); + const coin: Coin = await invoke('locked_coins'); + const major = await minorToMajor(coin.amount); + return major; }; -export const getSpendableCoins = async (vestingAccountAddress?: string): Promise => { - const res: Coin = await invoke('spendable_coins', { vestingAccountAddress }); - return minorToMajor(res.amount); + +export const getSpendableCoins = async (): Promise => { + const coin: Coin = await invoke('spendable_coins'); + const major = await minorToMajor(coin.amount); + return major; }; export const getVestingCoins = async (vestingAccountAddress: string): Promise => { - const res: Coin = await invoke('vesting_coins', { vestingAccountAddress }); - return minorToMajor(res.amount); + const coin: Coin = await invoke('vesting_coins', { vestingAccountAddress }); + const major = await minorToMajor(coin.amount); + return major; }; export const getVestedCoins = async (vestingAccountAddress: string): Promise => { - const res: Coin = await invoke('vested_coins', { vestingAccountAddress }); - return minorToMajor(res.amount); + const coin: Coin = await invoke('vested_coins', { vestingAccountAddress }); + const major = await minorToMajor(coin.amount); + return major; }; export const getOriginalVesting = async (vestingAccountAddress: string): Promise => { const res: OriginalVestingResponse = await invoke('original_vesting', { vestingAccountAddress }); - const majorValue = await minorToMajor(res.amount.amount); - return { ...res, amount: majorValue }; + const major = await minorToMajor(res.amount.amount); + return { ...res, amount: major }; }; -export const withdrawVestedCoins = async (amount: string) => { +export const withdrawVestedCoins = async (amount: string): Promise => { const minor = await majorToMinor(amount); await invoke('withdraw_vested_coins', { amount: { amount: minor.amount, denom: 'Minor' } }); }; -export const getCurrentVestingPeriod = async (address: string): Promise => - invoke('get_current_vesting_period', { address }); +export const getCurrentVestingPeriod = async (address: string): Promise => { + const res: Period = await invoke('get_current_vesting_period', { address }); + return res; +}; export const vestingBond = async ({ type, @@ -55,9 +62,13 @@ export const vestingBond = async ({ data: MixNode | Gateway; pledge: Coin; ownerSignature: string; -}): Promise => await invoke(`vesting_bond_${type}`, { [type]: data, ownerSignature, pledge }); +}): Promise => { + await invoke(`vesting_bond_${type}`, { [type]: data, ownerSignature, pledge }); +}; -export const vestingUnbond = async (type: EnumNodeType) => await invoke(`vesting_unbond_${type}`); +export const vestingUnbond = async (type: EnumNodeType): Promise => { + await invoke(`vesting_unbond_${type}`); +}; export const vestingDelegateToMixnode = async ({ identity, @@ -65,13 +76,20 @@ export const vestingDelegateToMixnode = async ({ }: { identity: string; amount: Coin; -}): Promise => invoke('vesting_delegate_to_mixnode', { identity, amount }); +}): Promise => { + const res: DelegationResult = await invoke('vesting_delegate_to_mixnode', { identity, amount }); + return res; +}; -export const vestingUnelegateFromMixnode = async (identity: string): Promise => - await invoke('vesting_undelegate_from_mixnode', { identity }); +export const vestingUnelegateFromMixnode = async (identity: string): Promise => { + const res: DelegationResult = await invoke('vesting_undelegate_from_mixnode', { identity }); + return res; +}; -export const getVestingAccountInfo = async (address: string): Promise => - await invoke('get_account_info', { address }); +export const getVestingAccountInfo = async (address: string): Promise => { + const res: VestingAccountInfo = await invoke('get_account_info', { address }); + return res; +}; export const getVestingPledgeInfo = async ({ address, @@ -81,15 +99,18 @@ export const getVestingPledgeInfo = async ({ type: EnumNodeType; }): Promise => { try { - return await invoke(`vesting_get_${type}_pledge`, { address }); + const res: PledgeData = await invoke(`vesting_get_${type}_pledge`, { address }); + return res; } catch (e) { return undefined; } }; -export const vestingUpdateMixnode = async (profitMarginPercent: number) => +export const vestingUpdateMixnode = async (profitMarginPercent: number): Promise => { await invoke('vesting_update_mixnode', { profitMarginPercent }); - -export const vestingDelegatedFree = async (vestingAccountAddress: string) => { - await invoke('delegated_free', { vestingAccountAddress }); +}; + +export const vestingDelegatedFree = async (vestingAccountAddress: string): Promise => { + const res: Coin = await invoke('delegated_free', { vestingAccountAddress }); + return res; }; diff --git a/nym-wallet/src/types/global.ts b/nym-wallet/src/types/global.ts index 0fd22f8803..58df3bff09 100644 --- a/nym-wallet/src/types/global.ts +++ b/nym-wallet/src/types/global.ts @@ -1,4 +1,4 @@ -import { Coin, Denom, Gateway, MixNode, PledgeData } from '.'; +import { Coin, Denom, Gateway, MixNode, PledgeData } from './rust'; export enum EnumNodeType { mixnode = 'mixnode', diff --git a/nym-wallet/src/utils/index.ts b/nym-wallet/src/utils/index.ts index 79bac07a25..3ce65075f3 100644 --- a/nym-wallet/src/utils/index.ts +++ b/nym-wallet/src/utils/index.ts @@ -2,7 +2,7 @@ import { invoke } from '@tauri-apps/api'; import { appWindow } from '@tauri-apps/api/window'; import bs58 from 'bs58'; import { minor, valid } from 'semver'; -import { userBalance, majorToMinor, getLockedCoins } from '../requests'; +import { userBalance, majorToMinor, getLockedCoins, getSpendableCoins } from '../requests'; import { Coin, Network, TCurrency } from '../types'; export const validateKey = (key: string, bytesLength: number): boolean => { @@ -103,7 +103,8 @@ export const checkHasEnoughFunds = async (allocationValue: string): Promise { try { const lockedTokens = await getLockedCoins(); - const remainingBalance = +lockedTokens.amount - +allocationValue; + const spendableTokens = await getSpendableCoins(); + const remainingBalance = +lockedTokens.amount + +spendableTokens.amount - +allocationValue; return remainingBalance >= 0; } catch (e) { console.error(e);