From 5afb2edcf85fcfd6b4885cb86b1b7a62c4a57b53 Mon Sep 17 00:00:00 2001 From: Florian Bouron Date: Sun, 16 Jun 2024 19:01:07 +0200 Subject: [PATCH 1/2] Fix some linting issues --- packages/extension/cypress.config.ts | 2 +- .../NetworkIndicator/NetworkIndicator.tsx | 4 +- .../ImportSecretNumbers.tsx | 16 ++--- .../SecretNumbers/SecretNumbers.tsx | 48 +++---------- .../components/pages/ShareNFT/ShareNFT.tsx | 4 +- .../extension/src/utils/NFTDataResolver.ts | 12 +++- packages/extension/src/utils/network.ts | 68 +++++++------------ packages/extension/src/utils/trustedApps.ts | 20 ++---- packages/extension/src/utils/wallet.ts | 12 +--- 9 files changed, 63 insertions(+), 123 deletions(-) diff --git a/packages/extension/cypress.config.ts b/packages/extension/cypress.config.ts index d5774069e..a9aca5b8b 100644 --- a/packages/extension/cypress.config.ts +++ b/packages/extension/cypress.config.ts @@ -3,7 +3,7 @@ import { defineConfig } from 'cypress'; export default defineConfig({ e2e: { video: false, - setupNodeEvents(on, config) { + setupNodeEvents() { // implement node event listeners here } } diff --git a/packages/extension/src/components/molecules/NetworkIndicator/NetworkIndicator.tsx b/packages/extension/src/components/molecules/NetworkIndicator/NetworkIndicator.tsx index 2a9792597..c55e0ef72 100644 --- a/packages/extension/src/components/molecules/NetworkIndicator/NetworkIndicator.tsx +++ b/packages/extension/src/components/molecules/NetworkIndicator/NetworkIndicator.tsx @@ -74,7 +74,9 @@ export const NetworkIndicator: FC = () => { customNetworkServer: currentNetwork.server }); setCurrentNetworkName(currentNetwork.name); - } catch (error) {} + } catch (error) { + /* empty */ + } // Show the error dialog setErrorDialogOpen(true); } diff --git a/packages/extension/src/components/pages/AddNewWallet/ImportNewWallet/ImportSecretNumbers/ImportSecretNumbers.tsx b/packages/extension/src/components/pages/AddNewWallet/ImportNewWallet/ImportSecretNumbers/ImportSecretNumbers.tsx index 4d9e2ba18..0075637c5 100644 --- a/packages/extension/src/components/pages/AddNewWallet/ImportNewWallet/ImportSecretNumbers/ImportSecretNumbers.tsx +++ b/packages/extension/src/components/pages/AddNewWallet/ImportNewWallet/ImportSecretNumbers/ImportSecretNumbers.tsx @@ -111,7 +111,7 @@ export const ImportSecretNumbers: FC = ({ helperText={inputErrors.numbersA} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersA) ? '0px' : '20px', + marginBottom: inputErrors.numbersA ? '0px' : '20px', width: '110px' }} className={styles.textField} @@ -129,7 +129,7 @@ export const ImportSecretNumbers: FC = ({ helperText={inputErrors.numbersB} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersB) ? '0px' : '20px', + marginBottom: inputErrors.numbersB ? '0px' : '20px', width: '110px' }} className={styles.textField} @@ -147,7 +147,7 @@ export const ImportSecretNumbers: FC = ({ helperText={inputErrors.numbersC} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersC) ? '0px' : '20px', + marginBottom: inputErrors.numbersC ? '0px' : '20px', width: '110px' }} className={styles.textField} @@ -165,7 +165,7 @@ export const ImportSecretNumbers: FC = ({ helperText={inputErrors.numbersD} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersD) ? '0px' : '20px', + marginBottom: inputErrors.numbersD ? '0px' : '20px', width: '110px' }} className={styles.textField} @@ -183,7 +183,7 @@ export const ImportSecretNumbers: FC = ({ helperText={inputErrors.numbersE} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersE) ? '0px' : '20px', + marginBottom: inputErrors.numbersE ? '0px' : '20px', width: '110px' }} className={styles.textField} @@ -201,7 +201,7 @@ export const ImportSecretNumbers: FC = ({ helperText={inputErrors.numbersF} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersF) ? '0px' : '20px', + marginBottom: inputErrors.numbersF ? '0px' : '20px', width: '110px' }} className={styles.textField} @@ -219,7 +219,7 @@ export const ImportSecretNumbers: FC = ({ helperText={inputErrors.numbersG} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersG) ? '0px' : '20px', + marginBottom: inputErrors.numbersG ? '0px' : '20px', width: '110px' }} className={styles.textField} @@ -237,7 +237,7 @@ export const ImportSecretNumbers: FC = ({ helperText={inputErrors.numbersH} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersH) ? '0px' : '20px', + marginBottom: inputErrors.numbersH ? '0px' : '20px', width: '110px' }} className={styles.textField} diff --git a/packages/extension/src/components/pages/ImportSecretNumbers/SecretNumbers/SecretNumbers.tsx b/packages/extension/src/components/pages/ImportSecretNumbers/SecretNumbers/SecretNumbers.tsx index 3828b541e..c3febbf6c 100644 --- a/packages/extension/src/components/pages/ImportSecretNumbers/SecretNumbers/SecretNumbers.tsx +++ b/packages/extension/src/components/pages/ImportSecretNumbers/SecretNumbers/SecretNumbers.tsx @@ -108,11 +108,7 @@ export const SecretNumbers: FC = ({ activeStep, steps, onBac helperText={inputErrors.numbersA} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersA) - ? '0px' - : hasOfflineBanner - ? '10px' - : '20px', + marginBottom: inputErrors.numbersA ? '0px' : hasOfflineBanner ? '10px' : '20px', width: '110px' }} className={styles.textField} @@ -130,11 +126,7 @@ export const SecretNumbers: FC = ({ activeStep, steps, onBac helperText={inputErrors.numbersB} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersB) - ? '0px' - : hasOfflineBanner - ? '10px' - : '20px', + marginBottom: inputErrors.numbersB ? '0px' : hasOfflineBanner ? '10px' : '20px', width: '110px' }} className={styles.textField} @@ -152,11 +144,7 @@ export const SecretNumbers: FC = ({ activeStep, steps, onBac helperText={inputErrors.numbersC} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersC) - ? '0px' - : hasOfflineBanner - ? '10px' - : '20px', + marginBottom: inputErrors.numbersC ? '0px' : hasOfflineBanner ? '10px' : '20px', width: '110px' }} className={styles.textField} @@ -174,11 +162,7 @@ export const SecretNumbers: FC = ({ activeStep, steps, onBac helperText={inputErrors.numbersD} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersD) - ? '0px' - : hasOfflineBanner - ? '10px' - : '20px', + marginBottom: inputErrors.numbersD ? '0px' : hasOfflineBanner ? '10px' : '20px', width: '110px' }} className={styles.textField} @@ -196,11 +180,7 @@ export const SecretNumbers: FC = ({ activeStep, steps, onBac helperText={inputErrors.numbersE} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersE) - ? '0px' - : hasOfflineBanner - ? '10px' - : '20px', + marginBottom: inputErrors.numbersE ? '0px' : hasOfflineBanner ? '10px' : '20px', width: '110px' }} className={styles.textField} @@ -218,11 +198,7 @@ export const SecretNumbers: FC = ({ activeStep, steps, onBac helperText={inputErrors.numbersF} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersF) - ? '0px' - : hasOfflineBanner - ? '10px' - : '20px', + marginBottom: inputErrors.numbersF ? '0px' : hasOfflineBanner ? '10px' : '20px', width: '110px' }} className={styles.textField} @@ -240,11 +216,7 @@ export const SecretNumbers: FC = ({ activeStep, steps, onBac helperText={inputErrors.numbersG} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersG) - ? '0px' - : hasOfflineBanner - ? '10px' - : '20px', + marginBottom: inputErrors.numbersG ? '0px' : hasOfflineBanner ? '10px' : '20px', width: '110px' }} className={styles.textField} @@ -262,11 +234,7 @@ export const SecretNumbers: FC = ({ activeStep, steps, onBac helperText={inputErrors.numbersH} style={{ marginTop: '15px', - marginBottom: Boolean(inputErrors.numbersH) - ? '0px' - : hasOfflineBanner - ? '10px' - : '20px', + marginBottom: inputErrors.numbersH ? '0px' : hasOfflineBanner ? '10px' : '20px', width: '110px' }} className={styles.textField} diff --git a/packages/extension/src/components/pages/ShareNFT/ShareNFT.tsx b/packages/extension/src/components/pages/ShareNFT/ShareNFT.tsx index 9e8d19523..138e8e424 100644 --- a/packages/extension/src/components/pages/ShareNFT/ShareNFT.tsx +++ b/packages/extension/src/components/pages/ShareNFT/ShareNFT.tsx @@ -63,7 +63,7 @@ export const ShareNFT: FC = () => { type: 'RECEIVE_NFT', payload: { id, - nfts: !!messagePayload ? messagePayload.nfts : messagePayload + nfts: messagePayload ? messagePayload.nfts : messagePayload } }; @@ -74,7 +74,7 @@ export const ShareNFT: FC = () => { payload: { id, type: ResponseType.Response, - result: !!messagePayload + result: messagePayload ? { account_nfts: messagePayload.nfts, marker: messagePayload.marker diff --git a/packages/extension/src/utils/NFTDataResolver.ts b/packages/extension/src/utils/NFTDataResolver.ts index 8c90e885d..57c860cbc 100644 --- a/packages/extension/src/utils/NFTDataResolver.ts +++ b/packages/extension/src/utils/NFTDataResolver.ts @@ -61,7 +61,9 @@ export const resolveNFTData = async ( NFTokenID, image: URL }; - } catch (e) {} + } catch (e) { + /* empty */ + } } } else { // Case 2 - JSON URL @@ -70,7 +72,9 @@ export const resolveNFTData = async ( // Case 2.1 - The URL is directly a JSON // If it follows the XLS-24 standard, it will be automatically parsed return parseJSON(URL, NFTokenID); - } catch (e) {} + } catch (e) { + /* empty */ + } // Case 2.2 - The URL is an IPFS hash if (!URL.startsWith(IPFSResolverPrefix) && !URL.startsWith('http')) { try { @@ -89,7 +93,9 @@ export const resolveNFTData = async ( image: resourceURL }; } - } catch (e) {} + } catch (e) { + /* empty */ + } } } // Case 3 - Return the raw NFT attributes diff --git a/packages/extension/src/utils/network.ts b/packages/extension/src/utils/network.ts index 761e3c4ad..181137ded 100644 --- a/packages/extension/src/utils/network.ts +++ b/packages/extension/src/utils/network.ts @@ -19,59 +19,39 @@ export const saveNetwork = ( customNetworkServer?: string ) => { if (customNetworkName && customNetworkServer) { - try { - saveData( - STORAGE_NETWORK, - JSON.stringify({ chain, name: customNetworkName, server: customNetworkServer }) - ); - } catch (e) { - throw e; - } + saveData( + STORAGE_NETWORK, + JSON.stringify({ chain, name: customNetworkName, server: customNetworkServer }) + ); } else { - try { - saveData( - STORAGE_NETWORK, - JSON.stringify({ chain, name: network, server: getNetwork(chain, network).server }) - ); - } catch (e) { - throw e; - } + saveData( + STORAGE_NETWORK, + JSON.stringify({ chain, name: network, server: getNetwork(chain, network).server }) + ); } }; export const loadCustomNetworks = (): Record => { - try { - const data = loadData(STORAGE_CUSTOM_NETWORKS); - if (data) { - return JSON.parse(data); - } - return {}; - } catch (error) { - throw error; + const data = loadData(STORAGE_CUSTOM_NETWORKS); + if (data) { + return JSON.parse(data); } + return {}; }; -export const replaceCustomNetworks = (networks: Record) => { - try { - saveData(STORAGE_CUSTOM_NETWORKS, JSON.stringify(networks)); - } catch (error) { - throw error; - } +export const replaceCustomNetworks = (networks: Record) => { + saveData(STORAGE_CUSTOM_NETWORKS, JSON.stringify(networks)); }; export const saveCustomNetwork = (networkData: NetworkData) => { - try { - // Read existing custom networks from storage - let existingCustomNetworks = loadCustomNetworks(); + // Read existing custom networks from storage + const existingCustomNetworks = loadCustomNetworks(); - // Add new custom network to existing custom networks - existingCustomNetworks[networkData.name] = networkData; + // Add new custom network to existing custom networks + existingCustomNetworks[networkData.name] = networkData; - // Save custom networks to storage - replaceCustomNetworks(existingCustomNetworks); - } catch (e) { - throw e; - } + // Save custom networks to storage + replaceCustomNetworks(existingCustomNetworks); }; export const loadNetwork = () => { @@ -84,7 +64,9 @@ export const loadNetwork = () => { const parsedData: NetworkNode = JSON.parse(data); try { return getNetwork(parsedData.chain as Chain, parsedData.name as Network); - } catch (error) {} + } catch (error) { + /* empty */ + } if ('chain' in parsedData && 'name' in parsedData && 'server' in parsedData) { return { @@ -95,7 +77,9 @@ export const loadNetwork = () => { description: 'Custom network' }; } - } catch (error) {} + } catch (error) { + /* empty */ + } return getNetwork(Chain.XRPL, XRPLNetwork.MAINNET); }; diff --git a/packages/extension/src/utils/trustedApps.ts b/packages/extension/src/utils/trustedApps.ts index 18d741a3b..64223cff5 100644 --- a/packages/extension/src/utils/trustedApps.ts +++ b/packages/extension/src/utils/trustedApps.ts @@ -46,11 +46,7 @@ export const saveTrustedApp = (trustedApp: TrustedApp, walletIndex: number): voi const stringifiedNewTrustedApps = JSON.stringify(trustedApps); - try { - saveData(STORAGE_TRUSTED_APPS, stringifiedNewTrustedApps); - } catch (e) { - throw e; - } + saveData(STORAGE_TRUSTED_APPS, stringifiedNewTrustedApps); }; export const loadTrustedApps = (walletIndex: number): TrustedApp[] => { @@ -66,7 +62,7 @@ export const loadTrustedApps = (walletIndex: number): TrustedApp[] => { }; export const removeTrustedApp = (url: string, walletIndex: number): TrustedApp[] => { - let trustedApps: TrustedApp[][] = JSON.parse(loadData(STORAGE_TRUSTED_APPS) || '[[]]'); + const trustedApps: TrustedApp[][] = JSON.parse(loadData(STORAGE_TRUSTED_APPS) || '[[]]'); if (!trustedApps[walletIndex]) { throw new Error("Couldn't find the wallet while removing the trusted app"); @@ -79,11 +75,7 @@ export const removeTrustedApp = (url: string, walletIndex: number): TrustedApp[] removeData(STORAGE_TRUSTED_APPS); } else { const stringifiedTrustedApps = JSON.stringify(trustedApps); - try { - saveData(STORAGE_TRUSTED_APPS, stringifiedTrustedApps); - } catch (e) { - throw e; - } + saveData(STORAGE_TRUSTED_APPS, stringifiedTrustedApps); } return trustedApps[walletIndex]; @@ -96,11 +88,7 @@ export const removeWalletFromTrustedApp = (walletIndex: number): void => { trustedApps.splice(walletIndex, 1); } - try { - saveData(STORAGE_TRUSTED_APPS, JSON.stringify(trustedApps)); - } catch (e) { - throw e; - } + saveData(STORAGE_TRUSTED_APPS, JSON.stringify(trustedApps)); }; // Checks if the trustedApp includes all the permissions diff --git a/packages/extension/src/utils/wallet.ts b/packages/extension/src/utils/wallet.ts index f7570bc70..2034c5f43 100644 --- a/packages/extension/src/utils/wallet.ts +++ b/packages/extension/src/utils/wallet.ts @@ -16,11 +16,7 @@ export const saveWallet = (wallet: WalletToSave, password: string) => { wallets.push(wallet as Wallet); - try { - saveData(STORAGE_WALLETS, encrypt(JSON.stringify(wallets), password)); - } catch (e) { - throw e; - } + saveData(STORAGE_WALLETS, encrypt(JSON.stringify(wallets), password)); }; export const loadWallets = (password: string): Wallet[] => { @@ -45,11 +41,7 @@ export const removeWallets = () => { }; export const saveSelectedWallet = (index: number): void => { - try { - saveData(STORAGE_SELECTED_WALLET, String(index)); - } catch (e) { - throw e; - } + saveData(STORAGE_SELECTED_WALLET, String(index)); }; export const loadSelectedWallet = (): number => { From d90fae3627c86cc8f0fef3756bcc05589ecaf1b3 Mon Sep 17 00:00:00 2001 From: Florian Bouron Date: Sat, 6 Jul 2024 15:28:20 +0200 Subject: [PATCH 2/2] Fix some more linting issues --- packages/extension/src/utils/storageLocal.ts | 26 ++------------------ packages/extension/src/utils/transaction.ts | 4 ++- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/packages/extension/src/utils/storageLocal.ts b/packages/extension/src/utils/storageLocal.ts index d32264908..245390a2a 100644 --- a/packages/extension/src/utils/storageLocal.ts +++ b/packages/extension/src/utils/storageLocal.ts @@ -3,19 +3,7 @@ */ export const saveData = (key: string, value: string) => { - try { - localStorage.setItem(key, value); - } catch (e) { - /* - * If localStorage is disabled or blocked by the browser, - * a SecurityError exception will be thrown when trying to access localStorage. - * If the key or value argument passed to localStorage.setItem() is not a string, - * a TypeError exception will be thrown. - * If the user has exceeded the storage quota for localStorage, - * a QuotaExceededError exception will be thrown. - */ - throw e; - } + localStorage.setItem(key, value); }; export const loadData = (key: string) => { @@ -35,15 +23,5 @@ export const loadData = (key: string) => { }; export const removeData = (key: string) => { - try { - localStorage.removeItem(key); - } catch (e) { - /* - * If localStorage is disabled or blocked by the browser, - * a SecurityError exception will be thrown when trying to access localStorage. - * If the key argument passed to localStorage.removeItem() is not a string, - * a TypeError exception will be thrown. - */ - throw e; - } + localStorage.removeItem(key); }; diff --git a/packages/extension/src/utils/transaction.ts b/packages/extension/src/utils/transaction.ts index d28e3ee78..b96aa353a 100644 --- a/packages/extension/src/utils/transaction.ts +++ b/packages/extension/src/utils/transaction.ts @@ -95,7 +95,9 @@ export const checkFee = (fee: string | null) => { if (Number(fee) && dropsToXrp(fee)) { return fee; } - } catch (e) {} + } catch (e) { + /* empty */ + } } return null; };