diff --git a/nym-wallet/src/components/CopyToClipboard.tsx b/nym-wallet/src/components/CopyToClipboard.tsx index 6a3dd16cd3..30493ef44f 100644 --- a/nym-wallet/src/components/CopyToClipboard.tsx +++ b/nym-wallet/src/components/CopyToClipboard.tsx @@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react'; import { Button, IconButton, Tooltip } from '@mui/material'; import { Check, ContentCopy } from '@mui/icons-material'; import { clipboard } from '@tauri-apps/api'; +import { Console } from '../utils/console'; export const CopyToClipboard = ({ text = '', @@ -19,7 +20,7 @@ export const CopyToClipboard = ({ await clipboard.writeText(_text); setCopied(true); } catch (e) { - console.log(`failed to copy: ${e}`); + Console.error(`failed to copy: ${e}`); } }; diff --git a/nym-wallet/src/context/main.tsx b/nym-wallet/src/context/main.tsx index dd3e9e5671..0209364494 100644 --- a/nym-wallet/src/context/main.tsx +++ b/nym-wallet/src/context/main.tsx @@ -6,6 +6,7 @@ import { TUseuserBalance, useGetBalance } from '../hooks/useGetBalance'; import { config } from '../../config'; import { getMixnodeBondDetails, selectNetwork, signInWithMnemonic, signOut } from '../requests'; import { currencyMap } from '../utils'; +import { Console } from '../utils/console'; export const { ADMIN_ADDRESS, IS_DEV_MODE } = config; @@ -62,7 +63,7 @@ export const ClientContextProvider = ({ children }: { children: React.ReactNode setClientDetails(client); } catch (e) { enqueueSnackbar('Error loading account', { variant: 'error' }); - console.error(e); + Console.error(e as string); } finally { setCurrency(currencyMap(n)); } @@ -74,7 +75,7 @@ export const ClientContextProvider = ({ children }: { children: React.ReactNode const mixnode = await getMixnodeBondDetails(); setMixnodeDetails(mixnode); } catch (e) { - console.log(e); + Console.error(e as string); } }; diff --git a/nym-wallet/src/hooks/useGetBalance.ts b/nym-wallet/src/hooks/useGetBalance.ts index cd70d9d749..7c43c433f1 100644 --- a/nym-wallet/src/hooks/useGetBalance.ts +++ b/nym-wallet/src/hooks/useGetBalance.ts @@ -11,6 +11,7 @@ import { getCurrentVestingPeriod, getVestingAccountInfo, } from '../requests'; +import { Console } from '../utils/console'; type TTokenAllocation = { [key in 'vesting' | 'vested' | 'locked' | 'spendable']: Coin['amount']; @@ -76,7 +77,7 @@ export const useGetBalance = (address?: string): TUseuserBalance => { } catch (e) { clearTokenAllocation(); clearOriginalVesting(); - console.error(e); + Console.error(e as string); } } setIsLoading(false); diff --git a/nym-wallet/src/pages/Admin/index.tsx b/nym-wallet/src/pages/Admin/index.tsx index 2139671b09..a0646c8579 100644 --- a/nym-wallet/src/pages/Admin/index.tsx +++ b/nym-wallet/src/pages/Admin/index.tsx @@ -19,7 +19,6 @@ const AdminForm: React.FC<{ const onSubmit = async (data: TauriContractStateParams) => { await setContractParams(data); - console.log(data); onCancel(); }; diff --git a/nym-wallet/src/pages/balance/vesting.tsx b/nym-wallet/src/pages/balance/vesting.tsx index 5bfb70bff6..222989c905 100644 --- a/nym-wallet/src/pages/balance/vesting.tsx +++ b/nym-wallet/src/pages/balance/vesting.tsx @@ -20,6 +20,7 @@ import { ClientContext } from '../../context/main'; import { withdrawVestedCoins } from '../../requests'; import { Period } from '../../types'; import { VestingTimeline } from './components/vesting-timeline'; +import { Console } from '../../utils/console'; const columnsHeaders: Array<{ title: string; align: TableCellProps['align'] }> = [ { title: 'Locked', align: 'left' }, @@ -165,7 +166,7 @@ export const VestingCard = () => { preventDuplicate: true, }); } catch (e) { - console.log(e); + Console.error(e as string); enqueueSnackbar('Token transfer failed. You may not have any transferable tokens at this time', { variant: 'error', preventDuplicate: true, diff --git a/nym-wallet/src/pages/delegate/DelegateForm.tsx b/nym-wallet/src/pages/delegate/DelegateForm.tsx index a3d1cd369a..288e521cbf 100644 --- a/nym-wallet/src/pages/delegate/DelegateForm.tsx +++ b/nym-wallet/src/pages/delegate/DelegateForm.tsx @@ -7,6 +7,7 @@ import { validationSchema } from './validationSchema'; import { ClientContext } from '../../context/main'; import { delegate, majorToMinor, vestingDelegateToMixnode } from '../../requests'; import { Fee, TokenPoolSelector } from '../../components'; +import { Console } from '../../utils/console'; type TDelegateForm = { identity: string; @@ -63,7 +64,7 @@ export const DelegateForm = ({ onSuccess({ amount: data.amount, address: res.target_address }); }) .catch((e) => { - console.log(e); + Console.error(e as string); onError(e); }); }; diff --git a/nym-wallet/src/pages/send/SendWizard.tsx b/nym-wallet/src/pages/send/SendWizard.tsx index c70c729df1..9f8470bed5 100644 --- a/nym-wallet/src/pages/send/SendWizard.tsx +++ b/nym-wallet/src/pages/send/SendWizard.tsx @@ -11,6 +11,7 @@ import { validationSchema } from './validationSchema'; import { TauriTxResult, TransactionDetails } from '../../types'; import { getGasFee, majorToMinor, send } from '../../requests'; import { checkHasEnoughFunds } from '../../utils'; +import { Console } from '../../utils/console'; const defaultValues = { amount: '', @@ -98,7 +99,7 @@ export const SendWizard = () => { .catch((e) => { setRequestError(e); setIsLoading(false); - console.error(e); + Console.error(e); }); }; diff --git a/nym-wallet/src/pages/settings/system-variables.tsx b/nym-wallet/src/pages/settings/system-variables.tsx index b8d594d458..11bf6c0218 100644 --- a/nym-wallet/src/pages/settings/system-variables.tsx +++ b/nym-wallet/src/pages/settings/system-variables.tsx @@ -10,6 +10,7 @@ import { InclusionProbabilityResponse } from '../../types'; import { useCheckOwnership } from '../../hooks/useCheckOwnership'; import { updateMixnode, vestingUpdateMixnode } from '../../requests'; import { ClientContext } from '../../context/main'; +import { Console } from '../../utils/console'; const DataField = ({ title, info, Indicator }: { title: string; info: string; Indicator: React.ReactElement }) => ( @@ -78,7 +79,7 @@ export const SystemVariables = ({ setNodeUpdateResponse('success'); } catch (e) { setNodeUpdateResponse('failed'); - console.log(e); + Console.log(e as string); } } }; diff --git a/nym-wallet/src/requests/actions.ts b/nym-wallet/src/requests/actions.ts index 42bf5ef4ae..c1a0caf7b1 100644 --- a/nym-wallet/src/requests/actions.ts +++ b/nym-wallet/src/requests/actions.ts @@ -1,4 +1,5 @@ import { invoke } from '@tauri-apps/api'; +import { Console } from '../utils/console'; import { Coin, DelegationResult, EnumNodeType, TauriTxResult, TBondArgs } from '../types'; export const bond = async ({ type, data, pledge, ownerSignature }: TBondArgs): Promise => { @@ -33,7 +34,7 @@ export const undelegate = async ({ const res: DelegationResult = await invoke(`undelegate_from_${type}`, { identity }); return res; } catch (e) { - console.log(e); + Console.log(e as string); return undefined; } }; diff --git a/nym-wallet/src/utils/console.ts b/nym-wallet/src/utils/console.ts new file mode 100644 index 0000000000..cbb864a4c9 --- /dev/null +++ b/nym-wallet/src/utils/console.ts @@ -0,0 +1,8 @@ +/* eslint-disable no-console */ +import { config } from '../../config'; + +export const Console = { + log: (output: string) => (config.IS_DEV_MODE ? console.log(output) : undefined), + warn: (output: string) => (config.IS_DEV_MODE ? console.warn(output) : undefined), + error: (output: string) => console.error(output), +}; diff --git a/nym-wallet/src/utils/index.ts b/nym-wallet/src/utils/index.ts index 3ce65075f3..c62dc896b1 100644 --- a/nym-wallet/src/utils/index.ts +++ b/nym-wallet/src/utils/index.ts @@ -4,6 +4,7 @@ import bs58 from 'bs58'; import { minor, valid } from 'semver'; import { userBalance, majorToMinor, getLockedCoins, getSpendableCoins } from '../requests'; import { Coin, Network, TCurrency } from '../types'; +import { Console } from './console'; export const validateKey = (key: string, bytesLength: number): boolean => { // it must be a valid base58 key @@ -12,7 +13,7 @@ export const validateKey = (key: string, bytesLength: number): boolean => { // of length 32 return bytes.length === bytesLength; } catch (e) { - console.error(e); + Console.error(e as string); return false; } }; @@ -53,7 +54,7 @@ export const validateAmount = async (amount: string, minimum: string): Promise= parseInt(minimum, Number(10)); } catch (e) { - console.error(e); + Console.error(e as string); return false; } @@ -95,7 +96,7 @@ export const checkHasEnoughFunds = async (allocationValue: string): Promise= 0; } catch (e) { - console.log(e); + Console.log(e as string); } return false; }; @@ -107,7 +108,7 @@ export const checkHasEnoughLockedTokens = async (allocationValue: string) => { const remainingBalance = +lockedTokens.amount + +spendableTokens.amount - +allocationValue; return remainingBalance >= 0; } catch (e) { - console.error(e); + Console.error(e as string); } return false; };