From d656871eb8020f350bf436f0ed6d7549f8ed51a8 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Thu, 25 Jan 2024 09:07:06 -0700 Subject: [PATCH 01/12] chore: run eslint on saving js,ts,svelte, run cargo fmt on save rust --- .vscode/settings.json | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 1243722c4..6f5476ca6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,25 @@ { - "editor.rulers": [80], - "svelte.enable-ts-plugin": true -} \ No newline at end of file + "editor.rulers": [80], + "svelte.enable-ts-plugin": true, + + "[rust]": { + "editor.defaultFormatter": "rust-lang.rust-analyzer", + "editor.formatOnSave": true, + "editor.formatOnSaveMode": "file" + }, + "[javascript]": { + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + } + }, + "[typescript]": { + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + } + }, + "[svelte]": { + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + } + } +} From 58937fe714174a58588011ce357197ce8f965e9b Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Thu, 25 Jan 2024 09:25:57 -0700 Subject: [PATCH 02/12] chore: vscode settings - lint on save, eslint validate --- .vscode/settings.json | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 6f5476ca6..dbc763357 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,17 +9,30 @@ }, "[javascript]": { "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": true, + "eslint.lintTask.enable": true } }, "[typescript]": { "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": true, + "eslint.lintTask.enable": true } }, "[svelte]": { "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": true, + "eslint.lintTask.enable": true } - } + }, + "[javascript][svelte][typescript]": { + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit" + } + }, + "eslint.validate": [ + "svelte", + "javascript", + "typescript" + ] } From e291aab5cf598ab5f05e5c5453d38e774b1d66b3 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Thu, 25 Jan 2024 09:26:31 -0700 Subject: [PATCH 03/12] chore: lint on ui builds --- .vscode/settings.json | 28 ++++++---------------------- tauri-app/package.json | 4 +--- tauri-app/vite.config.ts | 3 +++ 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index dbc763357..7ac93f7f7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,38 +1,22 @@ { "editor.rulers": [80], "svelte.enable-ts-plugin": true, - "[rust]": { "editor.defaultFormatter": "rust-lang.rust-analyzer", "editor.formatOnSave": true, "editor.formatOnSaveMode": "file" }, - "[javascript]": { - "editor.codeActionsOnSave": { - "source.fixAll.eslint": true, - "eslint.lintTask.enable": true - } - }, - "[typescript]": { - "editor.codeActionsOnSave": { - "source.fixAll.eslint": true, - "eslint.lintTask.enable": true - } - }, - "[svelte]": { - "editor.codeActionsOnSave": { - "source.fixAll.eslint": true, - "eslint.lintTask.enable": true - } - }, "[javascript][svelte][typescript]": { "editor.codeActionsOnSave": { - "source.fixAll.eslint": "explicit" + "source.fixAll.eslint": "explicit", + "eslint.lintTask.enable": true } }, "eslint.validate": [ - "svelte", "javascript", - "typescript" + "javascriptreact", + "typescript", + "typescriptreact", + "svelte" ] } diff --git a/tauri-app/package.json b/tauri-app/package.json index 74b30bae2..eab8e303d 100644 --- a/tauri-app/package.json +++ b/tauri-app/package.json @@ -7,9 +7,7 @@ "build": "vite build", "preview": "vite preview", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", - "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", - "lint": "prettier --check . && eslint .", - "format": "prettier --write ." + "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch" }, "devDependencies": { "@sveltejs/adapter-auto": "^3.0.0", diff --git a/tauri-app/vite.config.ts b/tauri-app/vite.config.ts index e73b21d45..464a5ddc5 100644 --- a/tauri-app/vite.config.ts +++ b/tauri-app/vite.config.ts @@ -5,6 +5,9 @@ import checker from 'vite-plugin-checker'; export default defineConfig({ plugins: [sveltekit(), checker({ typescript: true, + eslint: { + lintCommand: 'eslint src', + }, })], From 7735cbb47f8b32b5d7f958b5e8b94d721846b365 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Thu, 25 Jan 2024 09:46:43 -0700 Subject: [PATCH 04/12] chore: add eslint rules no-console, no-trailing-spaces --- tauri-app/.eslintrc.cjs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tauri-app/.eslintrc.cjs b/tauri-app/.eslintrc.cjs index 2a77cf7bf..b805d8ba8 100644 --- a/tauri-app/.eslintrc.cjs +++ b/tauri-app/.eslintrc.cjs @@ -12,7 +12,7 @@ module.exports = { parserOptions: { sourceType: 'module', ecmaVersion: 2020, - extraFileExtensions: ['.svelte'] + extraFileExtensions: ['.svelte', '.ts'] }, env: { browser: true, @@ -27,5 +27,9 @@ module.exports = { parser: '@typescript-eslint/parser' } } - ] + ], + rules: { + 'no-console': 'error', + 'no-trailing-spaces': 'error' + } }; From 04ccbdfbfb76ece3071077e7b0c2ac9d1376a3af Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Thu, 25 Jan 2024 09:56:25 -0700 Subject: [PATCH 05/12] chore(tauri/ui): fix all eslint complaints --- tauri-app/src/lib/InputLedgerWallet.svelte | 4 ++-- tauri-app/src/lib/InputTokenAmount.svelte | 1 + tauri-app/src/lib/ModalVaultDeposit.svelte | 6 ++---- tauri-app/src/lib/ModalVaultWithdraw.svelte | 12 +++--------- tauri-app/src/lib/stores/chain.ts | 2 +- tauri-app/src/lib/stores/vaultDetail.ts | 2 +- tauri-app/src/lib/stores/vaultsList.ts | 2 +- tauri-app/src/lib/utils/vaultDeposit.ts | 21 +++++++++++++++------ tauri-app/src/lib/utils/vaultWithdraw.ts | 11 ++++++++++- tauri-app/src/routes/settings/+page.svelte | 2 +- 10 files changed, 37 insertions(+), 26 deletions(-) diff --git a/tauri-app/src/lib/InputLedgerWallet.svelte b/tauri-app/src/lib/InputLedgerWallet.svelte index de18621ad..1ff2b07ac 100644 --- a/tauri-app/src/lib/InputLedgerWallet.svelte +++ b/tauri-app/src/lib/InputLedgerWallet.svelte @@ -7,6 +7,7 @@ import { invoke } from '@tauri-apps/api'; import { isAddress } from 'viem'; import { toasts } from '$lib/stores/toasts'; + import { ToastMessageType } from './typeshare/toast'; const maskOptions = { mask: Number, @@ -38,9 +39,8 @@ }); walletAddress = res; } catch (error) { - console.error(error); toasts.add({ - message_type: 'Error', + message_type: ToastMessageType.Error, text: `Ledger error: ${error}`, }); } diff --git a/tauri-app/src/lib/InputTokenAmount.svelte b/tauri-app/src/lib/InputTokenAmount.svelte index 0ebd84a4f..b5d7239ea 100644 --- a/tauri-app/src/lib/InputTokenAmount.svelte +++ b/tauri-app/src/lib/InputTokenAmount.svelte @@ -24,6 +24,7 @@ value = detail.value; try { valueRaw = parseUnits(detail.unmaskedValue, decimals); + // eslint-disable-next-line no-empty } catch (e) {} } diff --git a/tauri-app/src/lib/ModalVaultDeposit.svelte b/tauri-app/src/lib/ModalVaultDeposit.svelte index 95bda5ec3..374f1d791 100644 --- a/tauri-app/src/lib/ModalVaultDeposit.svelte +++ b/tauri-app/src/lib/ModalVaultDeposit.svelte @@ -19,10 +19,8 @@ async function execute() { isSubmitting = true; - try { - await vaultDeposit(vault.vault.vault_id, vault.token.id, amountRaw); - reset(); - } catch (e) {} + await vaultDeposit(vault.vault.vault_id, vault.token.id, amountRaw); + reset(); isSubmitting = false; } diff --git a/tauri-app/src/lib/ModalVaultWithdraw.svelte b/tauri-app/src/lib/ModalVaultWithdraw.svelte index 6610a3c56..3f875d705 100644 --- a/tauri-app/src/lib/ModalVaultWithdraw.svelte +++ b/tauri-app/src/lib/ModalVaultWithdraw.svelte @@ -11,11 +11,7 @@ let amountGTBalance: boolean; let isSubmitting = false; - $: { - try { - amountGTBalance = amountRaw > vault.balance; - } catch (e) {} - } + $: amountGTBalance = amountRaw > vault.balance; function reset() { amount = ''; @@ -25,10 +21,8 @@ async function execute() { isSubmitting = true; - try { - await vaultWithdraw(vault.vault.vault_id, vault.token.id, amountRaw); - reset(); - } catch (e) {} + await vaultWithdraw(vault.vault.vault_id, vault.token.id, amountRaw); + reset(); isSubmitting = false; } diff --git a/tauri-app/src/lib/stores/chain.ts b/tauri-app/src/lib/stores/chain.ts index e9f15009b..bb3941fe8 100644 --- a/tauri-app/src/lib/stores/chain.ts +++ b/tauri-app/src/lib/stores/chain.ts @@ -24,7 +24,7 @@ export async function updateChainId() { } } -export const activeChain = derived(chainId, (val) => { +export const activeChain = derived(chainId, (val) => { return find(Object.values(chains), (c) => c.id === val); }); diff --git a/tauri-app/src/lib/stores/vaultDetail.ts b/tauri-app/src/lib/stores/vaultDetail.ts index 586db844d..4d4acca76 100644 --- a/tauri-app/src/lib/stores/vaultDetail.ts +++ b/tauri-app/src/lib/stores/vaultDetail.ts @@ -15,7 +15,7 @@ function useVaultDetailStore() { localStorage.setItem(STORAGE_KEY, JSON.stringify({})); } }); - + async function refetch(id: string) { const res: VaultDetail = await invoke("vault_detail", {id, subgraphArgs: { url: get(subgraphUrl)} }); update((value) => { diff --git a/tauri-app/src/lib/stores/vaultsList.ts b/tauri-app/src/lib/stores/vaultsList.ts index 244fd07bd..82d13518e 100644 --- a/tauri-app/src/lib/stores/vaultsList.ts +++ b/tauri-app/src/lib/stores/vaultsList.ts @@ -15,7 +15,7 @@ function useVaultsListStore() { localStorage.setItem(STORAGE_KEY, JSON.stringify([])); } }); - + async function refetch() { const res: Array = await invoke("vaults_list", {subgraphArgs: { url: get(subgraphUrl)} }); set(res); diff --git a/tauri-app/src/lib/utils/vaultDeposit.ts b/tauri-app/src/lib/utils/vaultDeposit.ts index 56f7c5502..1bbeea06b 100644 --- a/tauri-app/src/lib/utils/vaultDeposit.ts +++ b/tauri-app/src/lib/utils/vaultDeposit.ts @@ -2,21 +2,30 @@ import { get } from 'svelte/store'; import { invoke } from '@tauri-apps/api'; import { rpcUrl, orderbookAddress, walletDerivationIndex } from '../stores/settings'; import { chainId } from '$lib/stores/chain'; +import { toasts } from '$lib/stores/toasts'; +import { ToastMessageType } from '$lib/typeshare/toast'; export async function vaultDeposit(vaultId: bigint, token: string, amount: bigint) { - await invoke("vault_deposit", { - depositArgs: { + try { + await invoke("vault_deposit", { + depositArgs: { vault_id: vaultId.toString(), token, amount: amount.toString(), - }, - transactionArgs: { + }, + transactionArgs: { rpc_url: get(rpcUrl), orderbook_address: get(orderbookAddress), derivation_index: get(walletDerivationIndex), chain_id: get(chainId), max_priority_fee_per_gas: '400000000000', max_fee_per_gas: '400000000000', - } + } }); - } \ No newline at end of file + } catch(e) { + toasts.add({ + message_type: ToastMessageType.Error, + text: e as string + }); + } +}; \ No newline at end of file diff --git a/tauri-app/src/lib/utils/vaultWithdraw.ts b/tauri-app/src/lib/utils/vaultWithdraw.ts index ff9565c66..8e76b9927 100644 --- a/tauri-app/src/lib/utils/vaultWithdraw.ts +++ b/tauri-app/src/lib/utils/vaultWithdraw.ts @@ -2,8 +2,11 @@ import { get } from 'svelte/store'; import { invoke } from '@tauri-apps/api'; import { rpcUrl, orderbookAddress, walletDerivationIndex } from '../stores/settings'; import { chainId } from '$lib/stores/chain'; +import { toasts } from '$lib/stores/toasts'; +import { ToastMessageType } from '$lib/typeshare/toast'; export async function vaultWithdraw(vaultId: bigint, token: string, targetAmount: bigint) { + try { await invoke("vault_withdraw", { withdrawArgs: { vault_id: vaultId.toString(), @@ -19,4 +22,10 @@ export async function vaultWithdraw(vaultId: bigint, token: string, targetAmount max_fee_per_gas: '400000000000', } }); - }; \ No newline at end of file + } catch(e) { + toasts.add({ + message_type: ToastMessageType.Error, + text: e as string + }); + } +}; \ No newline at end of file diff --git a/tauri-app/src/routes/settings/+page.svelte b/tauri-app/src/routes/settings/+page.svelte index 19747839c..dd407c5c5 100644 --- a/tauri-app/src/routes/settings/+page.svelte +++ b/tauri-app/src/routes/settings/+page.svelte @@ -1,5 +1,5 @@