diff --git a/govtool/frontend/.eslintrc.cjs b/govtool/frontend/.eslintrc.cjs index 89a5aff94..07d27ff79 100644 --- a/govtool/frontend/.eslintrc.cjs +++ b/govtool/frontend/.eslintrc.cjs @@ -51,6 +51,7 @@ module.exports = { "operator-linebreak": "off", "implicit-arrow-linebreak": "off", "consistent-return": "off", + "no-console": ["error", { allow: ["warn", "error"] }], "no-shadow": "off", "function-paren-newline": "off", "object-curly-newline": "off", diff --git a/govtool/frontend/src/context/getUtxos.ts b/govtool/frontend/src/context/getUtxos.ts index 23fc0a198..6888846a8 100644 --- a/govtool/frontend/src/context/getUtxos.ts +++ b/govtool/frontend/src/context/getUtxos.ts @@ -77,7 +77,6 @@ export const getUtxos = async ( return utxos; } catch (err) { Sentry.captureException(err); - // eslint-disable-next-line no-console console.error(err); } }; diff --git a/govtool/frontend/src/context/wallet.tsx b/govtool/frontend/src/context/wallet.tsx index 21d00ac21..b675835f4 100644 --- a/govtool/frontend/src/context/wallet.tsx +++ b/govtool/frontend/src/context/wallet.tsx @@ -1,5 +1,3 @@ -// TODO: enable eslint and fix all the errors with wallet refactor -/* eslint-disable */ import { createContext, useCallback, @@ -107,7 +105,7 @@ type BuildSignSubmitConwayCertTxArgs = { | Pick ); -interface CardanoContext { +interface CardanoContextType { address?: string; disconnectWallet: () => Promise; enable: (walletName: string) => Promise; @@ -160,7 +158,7 @@ interface CardanoContext { } type Utxos = { - txid: any; + txid: unknown; txindx: number; amount: string; str: string; @@ -170,7 +168,7 @@ type Utxos = { const NETWORK = import.meta.env.VITE_NETWORK_FLAG; -const CardanoContext = createContext({} as CardanoContext); +const CardanoContext = createContext({} as CardanoContextType); CardanoContext.displayName = 'CardanoContext'; const CardanoProvider = (props: Props) => { @@ -248,7 +246,7 @@ const CardanoProvider = (props: Props) => { throw new Error(t('errors.walletNoCIP30Nor90Support')); } // Enable wallet connection - const enabledApi = await window.cardano[walletName] + const enabledApi: CardanoApiWallet = await window.cardano[walletName] .enable({ extensions: [{ cip: 95 }], }) @@ -266,15 +264,15 @@ const CardanoProvider = (props: Props) => { throw new Error(t('errors.walletNoCIP90FunctionsEnabled')); } const network = await enabledApi.getNetworkId(); - if (network != NETWORK) { + if (network !== NETWORK) { throw new Error( t('errors.tryingConnectTo', { - networkFrom: network == 1 ? 'mainnet' : 'testnet', - networkTo: network != 1 ? 'mainnet' : 'testnet', + networkFrom: network === 1 ? 'mainnet' : 'testnet', + networkTo: network !== 1 ? 'mainnet' : 'testnet', }), ); } - setIsMainnet(network == 1); + setIsMainnet(network === 1); // Check and set wallet address const usedAddresses = await enabledApi.getUsedAddresses(); const unusedAddresses = await enabledApi.getUnusedAddresses(); @@ -296,8 +294,8 @@ const CardanoProvider = (props: Props) => { let stakeKeysList; if (registeredStakeKeysList.length > 0) { - stakeKeysList = registeredStakeKeysList.map((stakeKey) => { - const stakeKeyHash = PublicKey.from_hex(stakeKey).hash(); + stakeKeysList = registeredStakeKeysList.map((key) => { + const stakeKeyHash = PublicKey.from_hex(key).hash(); const stakeCredential = Credential.from_keyhash(stakeKeyHash); if (network === 1) { return RewardAddress.new(1, stakeCredential) @@ -310,8 +308,8 @@ const CardanoProvider = (props: Props) => { }); } else { console.warn(t('warnings.usingUnregisteredStakeKeys')); - stakeKeysList = unregisteredStakeKeysList.map((stakeKey) => { - const stakeKeyHash = PublicKey.from_hex(stakeKey).hash(); + stakeKeysList = unregisteredStakeKeysList.map((key) => { + const stakeKeyHash = PublicKey.from_hex(key).hash(); const stakeCredential = Credential.from_keyhash(stakeKeyHash); if (network === 1) { return RewardAddress.new(1, stakeCredential) @@ -361,14 +359,16 @@ const CardanoProvider = (props: Props) => { setPubDRepKey(''); setStakeKey(undefined); setIsEnabled(false); + // eslint-disable-next-line no-throw-literal throw { status: 'ERROR', - error: `${e == undefined ? t('errors.somethingWentWrong') : e}`, + error: `${e ?? t('errors.somethingWentWrong')}`, }; } finally { setIsEnableLoading(null); } } + // eslint-disable-next-line no-throw-literal throw { status: 'ERROR', error: t('errors.somethingWentWrong') }; }, [isEnabled, stakeKeys], @@ -414,6 +414,7 @@ const CardanoProvider = (props: Props) => { const getTxUnspentOutputs = async (utxos: Utxos) => { const txOutputs = TransactionUnspentOutputs.new(); + // eslint-disable-next-line no-restricted-syntax for (const utxo of utxos) { txOutputs.add(utxo.TransactionUnspentOutput); } @@ -531,9 +532,11 @@ const CardanoProvider = (props: Props) => { resourceId, }); + // eslint-disable-next-line no-console console.log(signedTx.to_hex(), 'signed tx cbor'); return resultHash; - // TODO: type error + // TODO: type error + // eslint-disable-next-line @typescript-eslint/no-shadow, @typescript-eslint/no-explicit-any } catch (error: any) { const walletName = getItemFromLocalStorage(`${WALLET_LS_KEY}_name`); const isWalletConnected = await window.cardano[walletName].isEnabled(); @@ -589,7 +592,7 @@ const CardanoProvider = (props: Props) => { return certBuilder; } catch (e) { Sentry.captureException(e); - console.log(e); + console.error(e); throw e; } }, @@ -621,7 +624,7 @@ const CardanoProvider = (props: Props) => { anchor, ); } else { - console.log(t('errors.notUsingAnchor')); + console.error(t('errors.notUsingAnchor')); dRepRegCert = DrepRegistration.new( dRepCred, BigNum.from_str(`${epochParams.drep_deposit}`), @@ -667,7 +670,7 @@ const CardanoProvider = (props: Props) => { return certBuilder; } catch (e) { Sentry.captureException(e); - console.log(e); + console.error(e); throw e; } }, @@ -695,7 +698,7 @@ const CardanoProvider = (props: Props) => { return certBuilder; } catch (e) { Sentry.captureException(e); - console.log(e); + console.error(e); throw e; } }, @@ -748,7 +751,7 @@ const CardanoProvider = (props: Props) => { return votingBuilder; } catch (e) { Sentry.captureException(e); - console.log(e); + console.error(e); throw e; } }, @@ -955,6 +958,8 @@ function useCardano() { } return result; } + // TODO: type error + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (e: any) { Sentry.captureException(e); await context.disconnectWallet(); diff --git a/govtool/frontend/src/hooks/forms/useCreateGovernanceActionForm.ts b/govtool/frontend/src/hooks/forms/useCreateGovernanceActionForm.ts index 22843aba7..ff0d505b6 100644 --- a/govtool/frontend/src/hooks/forms/useCreateGovernanceActionForm.ts +++ b/govtool/frontend/src/hooks/forms/useCreateGovernanceActionForm.ts @@ -183,7 +183,6 @@ export const useCreateGovernanceActionForm = ( } // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { - // eslint-disable-next-line no-console console.error(error); throw error; } diff --git a/govtool/frontend/src/hooks/forms/useRegisterAsdRepForm.tsx b/govtool/frontend/src/hooks/forms/useRegisterAsdRepForm.tsx index 7afe6084a..9f7ac6e37 100644 --- a/govtool/frontend/src/hooks/forms/useRegisterAsdRepForm.tsx +++ b/govtool/frontend/src/hooks/forms/useRegisterAsdRepForm.tsx @@ -37,7 +37,6 @@ export const useRegisterAsdRepForm = () => { console.log(values); // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (e: any) { - // eslint-disable-next-line no-console console.error(e); } finally { setIsLoading(false); diff --git a/govtool/frontend/src/utils/getDRepID.ts b/govtool/frontend/src/utils/getDRepID.ts index ccc23d8bd..05561eaf5 100644 --- a/govtool/frontend/src/utils/getDRepID.ts +++ b/govtool/frontend/src/utils/getDRepID.ts @@ -28,7 +28,6 @@ export const getPubDRepID = async (walletApi: CardanoApiWallet) => { dRepIDBech32, }; } catch (err) { - // eslint-disable-next-line no-console console.error(err); return { dRepKey: undefined,