From 90bed25f55bf50e5d8f5f07d779e0d8578d3e92e Mon Sep 17 00:00:00 2001 From: findolor Date: Fri, 4 Oct 2024 17:03:21 +0300 Subject: [PATCH 1/5] refactor: add network name to error message --- tauri-app/src/lib/components/InputWalletConnect.svelte | 4 ++-- tauri-app/src/lib/components/ModalExecute.svelte | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tauri-app/src/lib/components/InputWalletConnect.svelte b/tauri-app/src/lib/components/InputWalletConnect.svelte index 3ba51a2ad..d9ea233d2 100644 --- a/tauri-app/src/lib/components/InputWalletConnect.svelte +++ b/tauri-app/src/lib/components/InputWalletConnect.svelte @@ -12,7 +12,7 @@ walletconnectIsDisconnecting, } from '$lib/stores/walletconnect'; - export let priorityChainIds: number[] = []; + export let priorityChainIds: number[] | undefined = undefined;
@@ -28,7 +28,7 @@ size="lg" pill loading={$walletconnectIsDisconnecting || $walletconnectIsConnecting} - on:click={() => walletconnectConnect(priorityChainIds)} + on:click={() => walletconnectConnect(priorityChainIds ?? [])} > {#if $walletconnectAccount} diff --git a/tauri-app/src/lib/components/ModalExecute.svelte b/tauri-app/src/lib/components/ModalExecute.svelte index 79252b0d9..a4d44b735 100644 --- a/tauri-app/src/lib/components/ModalExecute.svelte +++ b/tauri-app/src/lib/components/ModalExecute.svelte @@ -1,6 +1,7 @@ @@ -99,10 +111,8 @@ {#if $walletconnectAccount && $walletConnectNetwork !== chainId}
- You are connected to {Object.entries($settings?.networks || {}).find( - (entry) => entry[1]['chain-id'] === $walletConnectNetwork, - )?.[0] || 'unknown'} network. Please connect your wallet to {overrideNetwork?.name || - $activeNetworkRef} network. + You are connected to {getNetworkName($walletConnectNetwork)} network. Please connect your wallet + to {overrideNetwork?.name || $activeNetworkRef} network.
{/if}
From aa5965780cef7dbcb94dc7101e4dc7f8c6b2020a Mon Sep 17 00:00:00 2001 From: findolor Date: Wed, 16 Oct 2024 08:17:13 +0300 Subject: [PATCH 4/5] test: add tests --- .../src/lib/components/ModalExecute.svelte | 2 +- .../src/lib/components/ModalExecute.test.ts | 82 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 tauri-app/src/lib/components/ModalExecute.test.ts diff --git a/tauri-app/src/lib/components/ModalExecute.svelte b/tauri-app/src/lib/components/ModalExecute.svelte index 6581e83da..6710ba23b 100644 --- a/tauri-app/src/lib/components/ModalExecute.svelte +++ b/tauri-app/src/lib/components/ModalExecute.svelte @@ -110,7 +110,7 @@ {execButtonLabel} {#if $walletconnectAccount && $walletConnectNetwork !== chainId} -
+
You are connected to {getNetworkName($walletConnectNetwork)} network. Please connect your wallet to {overrideNetwork?.name || $activeNetworkRef} network.
diff --git a/tauri-app/src/lib/components/ModalExecute.test.ts b/tauri-app/src/lib/components/ModalExecute.test.ts new file mode 100644 index 000000000..4de3d68c8 --- /dev/null +++ b/tauri-app/src/lib/components/ModalExecute.test.ts @@ -0,0 +1,82 @@ +import { expect, vi, describe, it } from 'vitest'; +import ModalExecute from './ModalExecute.svelte'; +import { render, screen } from '@testing-library/svelte'; +import { settings } from '$lib/stores/settings'; + +vi.mock('$lib/stores/walletconnect', async () => { + const { writable } = await import('svelte/store'); + return { + walletconnectAccount: writable('0x123'), + walletconnectIsDisconnecting: writable(false), + walletconnectIsConnecting: writable(false), + walletconnectProvider: writable(undefined), + walletConnectNetwork: writable(1), + walletConnectConnect: vi.fn(), + walletconnectDisconnect: vi.fn(), + }; +}); + +vi.mock('$lib/stores/settings', async (importOriginal) => { + return { + ...((await importOriginal()) as object), + }; +}); + +describe('ModalExecute', () => { + describe('should show network connection error if wallet is connected to wrong network', () => { + it('should show unknown network name', () => { + render(ModalExecute, { + props: { + open: true, + title: 'Test', + execButtonLabel: 'Execute', + executeLedger: vi.fn(), + executeWalletconnect: vi.fn(), + isSubmitting: false, + overrideNetwork: { + name: 'test', + rpc: 'https://test.com', + 'chain-id': 2, + }, + }, + }); + + const errorElement = screen.getByTestId('network-connection-error'); + expect(errorElement).toHaveTextContent( + 'You are connected to unknown network. Please connect your wallet to test network.', + ); + }); + + it('should show current connected network name', () => { + settings.set({ + networks: { + mainnet: { + 'chain-id': 1, + rpc: 'https://mainnet.com', + }, + }, + }); + + render(ModalExecute, { + props: { + open: true, + title: 'Test', + execButtonLabel: 'Execute', + executeLedger: vi.fn(), + executeWalletconnect: vi.fn(), + isSubmitting: false, + overrideNetwork: { + name: 'test', + rpc: 'https://test.com', + 'chain-id': 2, + }, + }, + }); + + const errorElement = screen.getByTestId('network-connection-error'); + expect(errorElement).toHaveTextContent( + 'You are connected to mainnet network. Please connect your wallet to test network.', + ); + }); + }); +}); From c43ea82ffd91f51a642cdc8b59e5d16d9ef85083 Mon Sep 17 00:00:00 2001 From: findolor Date: Wed, 16 Oct 2024 16:59:13 +0300 Subject: [PATCH 5/5] refactor: update error text --- tauri-app/src/lib/components/ModalExecute.svelte | 2 +- tauri-app/src/lib/components/ModalExecute.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tauri-app/src/lib/components/ModalExecute.svelte b/tauri-app/src/lib/components/ModalExecute.svelte index 6710ba23b..3cbcf212c 100644 --- a/tauri-app/src/lib/components/ModalExecute.svelte +++ b/tauri-app/src/lib/components/ModalExecute.svelte @@ -42,7 +42,7 @@ return existingNetwork[0]; } - return 'unknown'; + return 'an unknown'; }; diff --git a/tauri-app/src/lib/components/ModalExecute.test.ts b/tauri-app/src/lib/components/ModalExecute.test.ts index 4de3d68c8..a47bdf8d6 100644 --- a/tauri-app/src/lib/components/ModalExecute.test.ts +++ b/tauri-app/src/lib/components/ModalExecute.test.ts @@ -43,7 +43,7 @@ describe('ModalExecute', () => { const errorElement = screen.getByTestId('network-connection-error'); expect(errorElement).toHaveTextContent( - 'You are connected to unknown network. Please connect your wallet to test network.', + 'You are connected to an unknown network. Please connect your wallet to test network.', ); });