Skip to content

Get connected account address from WalletProvider#1494

Merged
hardingjam merged 37 commits intomainfrom
Wallet-provider
Mar 28, 2025
Merged

Get connected account address from WalletProvider#1494
hardingjam merged 37 commits intomainfrom
Wallet-provider

Conversation

@hardingjam
Copy link
Copy Markdown
Contributor

@hardingjam hardingjam commented Mar 21, 2025

Motivation

  • Implements a WalletProvider wrapper for tauri-app and webapp, which exposes the connected account to descendents.

Solution

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • New Features

    • Enhanced wallet connectivity has been integrated across both web and desktop experiences.
    • A unified wallet support component now manages account interactions more consistently.
    • An updated wallet access utility delivers smoother and more reliable account management.
    • New WalletProvider component facilitates wallet functionality integration.
    • Introduced useAccount hook for accessing wallet account information.
  • Bug Fixes

    • Corrected a typo in the data-testid attribute for testing in the VaultDetail component.
  • Tests

    • Added tests for the WalletProvider component to validate account context handling.
    • Improved test structure and clarity in various test files.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 21, 2025

Walkthrough

This PR introduces new wallet functionality across the application. A new WalletProvider component is added to manage account state via Svelte’s context, along with a corresponding useAccount hook and an Account type definition. The provider is integrated into both the webapp’s and tauri-app’s layout components by wrapping the existing QueryClientProvider. Additionally, wallet-related store types are updated to use a more specific Hex type instead of generic strings, and several test files and the Vite configuration have been modified to support the changes.

Changes

File(s) Change Summary
packages/ui-components/.../index.ts, packages/ui-components/.../providers/wallet/WalletProvider.svelte, packages/ui-components/.../providers/wallet/context.ts, packages/ui-components/.../providers/wallet/useAccount.ts, packages/ui-components/.../types/account.ts, packages/ui-components/.../__tests__/WalletProvider.test.ts Added new WalletProvider component to manage account context, introduced useAccount hook for accessing wallet state, defined the Account type, and updated exports and tests accordingly.
packages/webapp/.../+layout.svelte, tauri-app/.../+layout.svelte Updated layout files to wrap QueryClientProvider with WalletProvider. In tauri-app, a derived account store is computed from ledgerWalletAddress and walletconnectAccount and passed to the provider.
packages/webapp/.../stores/wagmi.ts, tauri-app/.../stores/walletconnect.ts, tauri-app/.../stores/wallets.ts Updated wallet-related store types to use Hex from the viem library, replacing `string
tauri-app/.../components/InputLedgerWallet.svelte Changed the variable type in ledgerConnect from string to Hex and updated ledgerDisconnect to set the wallet address to null instead of undefined.
tauri-app/.../services/wallet.ts Modified getAddressFromLedger to return a Promise<Hex> instead of a Promise<string>, aligning the return type with the new Hex type.
packages/webapp/.../__tests__/Sidebar.test.ts, tauri-app/.../components/ModalExecute.test.ts Refined test mocks and setups, added a new mock for @walletconnect/modal, and updated test descriptions for clarity.
tauri-app/.../vite.config.ts Enhanced test configuration by adding globals, include patterns, a test timeout, and updated the dependency inlining settings.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant L as Layout Component
    participant WP as WalletProvider
    participant CTX as Wallet Context
    participant CC as Child Component (useAccount)
    
    U->>L: Load page
    L->>WP: Initialize WalletProvider (with account prop)
    WP->>CTX: Set account context (using setAccountContext)
    CC->>CTX: Retrieve account (using getAccountContext)
    CTX-->>CC: Return account data
Loading

Possibly related PRs

  • Display truncated eth address if wallet is connected #1455: The changes in the main PR, which introduce new exports for WalletProvider and useAccount, are related to the retrieved PR that modifies the WalletConnect component to include the signerAddress, as both involve the integration of wallet functionality and the management of account-related state.

Suggested reviewers

  • hardyjosh

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 682d7a9 and f046309.

📒 Files selected for processing (2)
  • packages/ui-components/src/__tests__/VaultDetail.test.ts (1 hunks)
  • packages/ui-components/src/lib/components/detail/VaultDetail.svelte (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: git-clean
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (2)
packages/ui-components/src/lib/components/detail/VaultDetail.svelte (1)

179-179: Fixed typo in data-testid attribute.

The corrected attribute name ensures consistency in test identifiers and aligns with other similar elements in the component. This change will help maintain reliable test selection.

packages/ui-components/src/__tests__/VaultDetail.test.ts (1)

120-120: Updated test selector to match component changes.

This change appropriately updates the test to use the corrected data-testid attribute, ensuring the test continues to function correctly after the component fix.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b4f62f and 8c9f68c.

📒 Files selected for processing (4)
  • packages/ui-components/src/__tests__/WalletConnect.test.ts (3 hunks)
  • packages/ui-components/src/__tests__/WalletProvider.test.ts (1 hunks)
  • packages/ui-components/src/lib/providers/wallet/context.ts (1 hunks)
  • packages/ui-components/src/lib/providers/wallet/useAccount.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
packages/ui-components/src/lib/providers/wallet/useAccount.ts (1)
packages/ui-components/src/lib/providers/wallet/context.ts (2) (2)
  • getUseAccountContext (11-14)
  • getAccountContext (19-27)
packages/ui-components/src/lib/providers/wallet/context.ts (1)
packages/ui-components/src/lib/providers/wallet/useAccount.ts (1) (1)
  • useAccount (8-21)
packages/ui-components/src/__tests__/WalletConnect.test.ts (1)
packages/ui-components/src/lib/providers/wallet/useAccount.ts (1) (1)
  • useAccount (8-21)
🪛 Biome (1.9.4)
packages/ui-components/src/__tests__/WalletProvider.test.ts

[error] 42-42: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: git-clean
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (10)
packages/ui-components/src/__tests__/WalletProvider.test.ts (1)

1-46: Well-structured tests for the new WalletProvider component

The tests thoroughly verify three important behaviors of the WalletProvider:

  1. Setting the account store in context
  2. Setting the useAccount function in context
  3. Handling the default case when no account prop is provided

This provides good coverage for the component's core functionality.

🧰 Tools
🪛 Biome (1.9.4)

[error] 42-42: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

packages/ui-components/src/lib/providers/wallet/useAccount.ts (2)

1-21: Well-designed hook with fallback mechanism

The useAccount hook is well-implemented with a clear fallback mechanism:

  1. First tries to get and use the context-provided useAccount function
  2. Falls back to direct account context access if needed

This provides flexibility in how account data can be accessed.


23-73: Comprehensive test coverage

The tests thoroughly verify both code paths:

  1. Using the useAccount function from context when available
  2. Falling back to direct account context when useAccount function is not available

Good job separating the test concerns and including proper mock resets in the beforeEach hook.

packages/ui-components/src/lib/providers/wallet/context.ts (3)

11-14: Good implementation of context accessor

The getUseAccountContext function provides a clean way to access the useAccount function from Svelte's context.


19-27: Helpful error message in context accessor

The getAccountContext function includes a helpful error message that guides developers to the likely solution when an account is not found in context.


29-82: Thorough test coverage with good edge cases

The tests cover important scenarios:

  1. Using useAccount function from context when available
  2. Falling back to direct account context
  3. Throwing an error when account is not in context

This ensures the hook behaves correctly under various conditions.

packages/ui-components/src/__tests__/WalletConnect.test.ts (4)

7-15: Clean transition to useAccount hook

The test has been correctly updated to use the new useAccount hook instead of directly accessing signerAddress. This is in line with the PR's objective of centralizing wallet state management.


33-35: Good mock implementation for disconnected state

The mock correctly simulates the disconnected state by returning a null account.


45-47: Good mock implementation for connected state

The mock correctly simulates the connected state by returning a valid address.


50-55: Props updated to reflect component changes

The component props have been updated to remove signerAddress, which is now obtained through the useAccount hook. This is consistent with the PR's objective of centralizing wallet state management.

Comment thread packages/ui-components/src/__tests__/WalletProvider.test.ts Outdated
Comment thread packages/ui-components/src/lib/providers/wallet/context.ts Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
packages/ui-components/src/__tests__/WalletConnect.test.ts (1)

24-57: 🧹 Nitpick (assertive)

Consider adding edge case tests.

The current tests cover the main scenarios (connected and disconnected), but consider adding tests for edge cases such as when the account is transitioning between states or when the wallet is connected but on an unsupported network.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c9f68c and f86eab2.

📒 Files selected for processing (8)
  • packages/ui-components/src/__tests__/DeploymentSteps.test.ts (1 hunks)
  • packages/ui-components/src/__tests__/WalletConnect.test.ts (3 hunks)
  • packages/ui-components/src/__tests__/WalletProvider.test.ts (1 hunks)
  • packages/ui-components/src/lib/providers/wallet/context.ts (1 hunks)
  • packages/ui-components/src/lib/providers/wallet/useAccount.ts (1 hunks)
  • packages/webapp/src/lib/components/DepositOrWithdrawModal.svelte (1 hunks)
  • packages/webapp/src/lib/components/Sidebar.svelte (2 hunks)
  • tauri-app/src/routes/+layout.svelte (1 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
packages/ui-components/src/lib/providers/wallet/useAccount.ts (1)
packages/ui-components/src/lib/providers/wallet/context.ts (2) (2)
  • getUseAccountContext (10-13)
  • getAccountContext (18-26)
packages/ui-components/src/lib/providers/wallet/context.ts (1)
packages/ui-components/src/lib/providers/wallet/useAccount.ts (1) (1)
  • useAccount (8-21)
packages/ui-components/src/__tests__/WalletConnect.test.ts (2)
packages/ui-components/src/lib/__mocks__/stores.ts (1) (1)
  • mockConnectedStore (116-121)
packages/ui-components/src/lib/providers/wallet/useAccount.ts (1) (1)
  • useAccount (8-21)
🪛 Biome (1.9.4)
packages/ui-components/src/__tests__/WalletProvider.test.ts

[error] 46-46: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: git-clean
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (16)
packages/webapp/src/lib/components/DepositOrWithdrawModal.svelte (1)

164-164: Removed signerAddress prop from WalletConnect component

The removal of the signerAddress prop from the WalletConnect component aligns with the broader wallet management refactoring. This component now likely uses the context-based useAccount hook internally instead of receiving the address as a prop.

packages/ui-components/src/__tests__/WalletProvider.test.ts (2)

1-50: Well-structured tests for the WalletProvider component

The test cases provide good coverage of the component's functionality, including account store context setting, useAccount function context setting, and default account behavior.

🧰 Tools
🪛 Biome (1.9.4)

[error] 46-46: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)


46-46: Avoid non-null assertion operator

The non-null assertion operator (!) bypasses TypeScript's null checks, which could lead to runtime errors if the assumption is incorrect.

-    const defaultAccount = accountCall![1];
+    const defaultAccount = accountCall?.[1];

Alternatively, add a check before accessing the value:

-    const defaultAccount = accountCall![1];
+    if (!accountCall) {
+      throw new Error('Expected setContext to be called with ACCOUNT_KEY');
+    }
+    const defaultAccount = accountCall[1];
🧰 Tools
🪛 Biome (1.9.4)

[error] 46-46: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

packages/ui-components/src/lib/providers/wallet/useAccount.ts (2)

1-21: Well-implemented useAccount hook with clear fallback strategy

The useAccount hook is appropriately implemented with a clear strategy:

  1. First attempt to use the useAccount function from context
  2. Fall back to direct context access if needed
  3. Return a consistent object structure regardless of the path taken

The JSDoc comments also clearly indicate that this hook must be used within a child component of WalletProvider.


23-73: Comprehensive test coverage

The tests thoroughly verify both the primary and fallback behavior paths of the useAccount hook. They confirm that:

  1. When the context function is available, it's properly called and its result is returned
  2. When the context function is not available, it correctly falls back to direct context access

This ensures the hook behaves reliably in all expected scenarios.

tauri-app/src/routes/+layout.svelte (2)

17-27: Well-designed account store derivation

The derived account store elegantly combines multiple account sources with a clear priority:

  1. First use ledgerWalletAddress if available
  2. Then fall back to walletconnectAccount if available
  3. Return null if neither is set

This approach provides a single consistent source of account information throughout the application.


32-58: Appropriate integration of WalletProvider in application layout

The WalletProvider is correctly positioned as the outermost provider, wrapping the QueryClientProvider. This ensures that the wallet context is available throughout the component tree, including to any components that might need it within query-related components.

packages/ui-components/src/lib/providers/wallet/context.ts (2)

10-13: No issues found with getUseAccountContext.
This function is straightforward, returning data from the Svelte context as intended.


60-79: Good test coverage.
The tests thoroughly verify the presence and absence of the context function, ensuring robust functionality.

packages/ui-components/src/__tests__/DeploymentSteps.test.ts (1)

12-12:

Details

✅ Verification successful

Confirm correct usage of vi.hoisted.
vi.hoisted ensures mocks are registered before imports, but double-check any potential concurrency issues with dynamic imports.


🏁 Script executed:

#!/bin/bash
# Locate all references to `vi.hoisted` usage.
rg -A5 "vi\.hoisted"

Length of output: 4936


Action: Confirm Correct vi.hoisted Usage in DeploymentSteps Test

After reviewing its usage across the repository, including in similar tests like OrderDetail and WalletConnect, the dynamic import via vi.hoisted(() => import('../lib/__mocks__/stores')) in packages/ui-components/src/__tests__/DeploymentSteps.test.ts is implemented correctly. The pattern ensures mocks are registered before module imports occur, and there’s no evidence of concurrency issues with the current usage. Please continue to monitor for any potential concurrency concerns should the dynamic import logic change in the future.

packages/webapp/src/lib/components/Sidebar.svelte (2)

68-68: Reordered classes on CloseButton.
This is a minor style tweak with no functional impact. Looks fine.


107-107:

Details

✅ Verification successful

Removed the signerAddress prop.
Confirm that anything depending on signerAddress is now handled via the context-based approach.


🏁 Script executed:

#!/bin/bash
# Check for any remaining references to signerAddress in the codebase.
rg "signerAddress"

Length of output: 5767


Sidebar Prop Removal Verified

  • In packages/webapp/src/lib/components/Sidebar.svelte the <WalletConnect> component is now invoked without the signerAddress prop.
  • The context‐based approach appears to be in place—evidenced by the use of the signerAddress store (e.g. in the WalletProvider in +layout.svelte) and its reactive usage in other components.
  • Ensure that components still accepting a signerAddress prop (as seen in various files and tests) are intentionally handling their dependencies via the centralized store, in line with the overall migration strategy.
packages/ui-components/src/__tests__/WalletConnect.test.ts (4)

7-13: Approval for the wallet provider refactoring approach.

The migration from direct signerAddress usage to the context-based useAccount hook is implemented correctly in these tests. The mock setup is clean and follows best practices by using Vitest's mocking capabilities.


31-33: Test correctly handles disconnected wallet state.

This test setup appropriately mocks the account as null to simulate a disconnected wallet, matching how the actual component would behave in this scenario.


43-45: Test correctly handles connected wallet state.

This test appropriately mocks the account with an Ethereum address to test the connected wallet case, and correctly verifies the truncated address display.


48-52: Props update aligns with the component interface changes.

The removal of the signerAddress prop from the render call is consistent with the refactoring goal of managing wallet connections through the context-based approach instead of passing props.

Comment thread packages/ui-components/src/lib/providers/wallet/context.ts Outdated
Comment thread packages/ui-components/src/lib/providers/wallet/context.ts Outdated
@hardingjam hardingjam requested a review from hardyjosh March 21, 2025 20:17
@hardingjam hardingjam self-assigned this Mar 21, 2025
@hardingjam hardingjam changed the title Wallet provider Get connected account address from WalletProvider Mar 21, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
packages/ui-components/src/__tests__/WalletProvider.test.ts (1)

1-50: 🧹 Nitpick (assertive)

Suggest testing error handling

The test suite could be enhanced by adding tests for error cases or edge conditions, such as when invalid account values are provided.

Consider adding a test case like:

it('should handle invalid account values gracefully', () => {
  // Test with undefined, empty string, or invalid address format
  const invalidAccount = readable('not-an-address');
  
  render(WalletProvider, {
    props: {
      account: invalidAccount
    }
  });
  
  // Verify the component still functions correctly
  expect(vi.mocked(setContext)).toHaveBeenCalledWith(ACCOUNT_KEY, invalidAccount);
  expect(vi.mocked(setContext)).toHaveBeenCalledWith(USE_ACCOUNT_KEY, expect.any(Function));
});
🧰 Tools
🪛 Biome (1.9.4)

[error] 45-45: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 527ac01 and 8773046.

📒 Files selected for processing (1)
  • packages/ui-components/src/__tests__/WalletProvider.test.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/ui-components/src/__tests__/WalletProvider.test.ts

[error] 45-45: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: git-clean
  • GitHub Check: test
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (5)
packages/ui-components/src/__tests__/WalletProvider.test.ts (5)

1-9: Good test setup and imports.

The import statements are well-organized and appropriately import necessary testing utilities, the component being tested, and Svelte utilities.


10-13: Well-structured mock for Svelte context functions.

Good practice mocking the Svelte setContext and getContext functions to isolate tests from actual context implementation.


15-26: Good test for account store context setting.

This test clearly verifies that the component correctly sets the account store in the Svelte context using the appropriate key.


28-38: Appropriate verification of useAccount function.

The test correctly verifies that the useAccount function is set in context, using expect.any(Function) to check the type without being too strict about the implementation.


40-48: Avoid non-null assertion operator

The non-null assertion operator (!) bypasses TypeScript's null checks, which could lead to runtime errors if the assumption is incorrect.

-const defaultAccount = accountCall![1];
+const defaultAccount = accountCall?.[1];

Alternatively, add a check before accessing the value:

-const defaultAccount = accountCall![1];
+if (!accountCall) {
+  throw new Error('Expected setContext to be called with ACCOUNT_KEY');
+}
+const defaultAccount = accountCall[1];
🧰 Tools
🪛 Biome (1.9.4)

[error] 45-45: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

Comment thread packages/ui-components/src/__tests__/WalletProvider.test.ts Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8773046 and ca6fb9f.

📒 Files selected for processing (1)
  • packages/ui-components/src/__tests__/WalletProvider.test.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/ui-components/src/__tests__/WalletProvider.test.ts

[error] 45-45: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: git-clean
  • GitHub Check: test
🔇 Additional comments (4)
packages/ui-components/src/__tests__/WalletProvider.test.ts (4)

1-14: Good test setup with proper mocking.

The test setup is well-structured with appropriate imports and mocking of the setContext and getContext functions, which are essential for testing the context-based functionality of the WalletProvider component.


15-26: Well-implemented test for account context setting.

The test correctly verifies that the account store is properly set in the context when provided as a prop to the WalletProvider component.


28-38: Good verification of the useAccount function in context.

This test appropriately checks that the useAccount function is set in the context, which is a critical part of the WalletProvider's functionality.


40-48: Avoid non-null assertion operator and enhance the default account test.

The non-null assertion operator (!) in line 45 bypasses TypeScript's null checks, which could lead to runtime errors if accountCall is undefined.

-  const defaultAccount = accountCall![1];
+  const defaultAccount = accountCall?.[1];

Also, the test could be more comprehensive by verifying the properties of the default account and checking that the useAccount function is set in context:

 it('should use default null account when no account prop provided', () => {
   render(WalletProvider);

   const setContextCalls = vi.mocked(setContext).mock.calls;
   const accountCall = setContextCalls.find((call) => call[0] === ACCOUNT_KEY);
-  const defaultAccount = accountCall![1];
+  const defaultAccount = accountCall?.[1];
+  const useAccountCall = setContextCalls.find((call) => call[0] === USE_ACCOUNT_KEY);

   expect(defaultAccount).toBeDefined();
+  // Verify the default account store has the expected behavior
+  expect(defaultAccount.subscribe).toBeDefined();
+  
+  // Verify useAccount function is set
+  expect(useAccountCall?.[1]).toEqual(expect.any(Function));
 });
🧰 Tools
🪛 Biome (1.9.4)

[error] 45-45: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

Comment thread packages/ui-components/src/__tests__/WalletProvider.test.ts Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca6fb9f and 1b17762.

📒 Files selected for processing (1)
  • tauri-app/vite.config.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: git-clean
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: test
  • GitHub Check: Deploy-Preview
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (3)
tauri-app/vite.config.ts (3)

54-70: Updated test configuration enhances test setup for new wallet functionality

The test configuration has been properly updated to support testing of the new WalletProvider component. The changes include:

  • Added Jest-like globals for improved test compatibility
  • Specified test file inclusion patterns
  • Added environment variables loading
  • Set appropriate test timeout
  • Updated server dependencies to inline only @tanstack/svelte-query

These changes will facilitate effective testing of the new wallet functionality being introduced in this PR.


56-56:

Details

✅ Verification successful

Verify the purpose of includeSource

The includeSource property appears to be used for specifying source files, but this may not be a standard Vitest property. Confirm if this should be coverage.include instead, which is commonly used to specify which files to include in code coverage reporting.


🌐 Web query:

Is includeSource a valid configuration property in Vitest?

💡 Result:

Yes, includeSource is a valid configuration property in Vitest. It allows you to run in-source tests directly within your codebase by specifying glob patterns for files containing test blocks defined with import.meta.vitest [5][19].

Key Details about includeSource

  • Purpose: Detects test blocks embedded in source files (not just dedicated test files like *.test.ts).
  • Configuration:
    // vitest.config.ts
    import { defineConfig } from 'vitest/config'
    export default defineConfig({
      test: {
        includeSource: ['src/**/*.{js,ts}'] // Checks .js/.ts files in src/
      }
    })
  • Production Build: Requires import.meta.vitest to be set to undefined to exclude tests from bundles:
    define: {
      'import.meta.vitest': 'undefined'
    }

Example Usage

In a source file (math.ts):

export function add(a: number, b: number) {
  return a + b
}

// In-source test
if (import.meta.vitest) {
  const { test, expect } = import.meta.vitest
  test('adds numbers', () => {
    expect(add(2, 3)).toBe(5)
  })
}

This configuration enables Rust-style in-source testing, where tests coexist with implementation code[19].

Citations:


Action: Confirm Correct Use of includeSource in Vitest Configuration

The web query confirms that includeSource is a valid Vitest property and is intended for detecting in-source test blocks (using import.meta.vitest). It is not a mistake in configuration, and there is no need to replace it with coverage.include.


67-67:

Details

❓ Verification inconclusive

Confirm if removing @sveltejs/kit from inline dependencies is intentional

The configuration now only inlines @tanstack/svelte-query, whereas it appears @sveltejs/kit might have been inlined previously. Ensure this change was intentional and won't affect the test environment's ability to properly handle SvelteKit imports.


🏁 Script executed:

#!/bin/bash
# Check for related dependencies in package.json and look for other uses of @sveltejs/kit

echo "Checking package.json for related dependencies..."
cat package.json | grep -A 10 -B 10 "@sveltejs/kit" || echo "No direct references found in package.json"

echo -e "\nChecking for other imports of @sveltejs/kit in source files..."
rg "from '@sveltejs/kit" --type ts

Length of output: 1507


Confirm the Removal of @sveltejs/kit from Inline Dependencies

Our investigation confirms that while the package still exists (as seen in package.json) and is imported in several parts of the codebase (e.g., in multiple vite.config.ts files and SvelteKit-related modules), the inline configuration in tauri-app/vite.config.ts now only inlines @tanstack/svelte-query. Please verify that the removal of @sveltejs/kit from the inline list was a deliberate change and that it won’t adversely affect Vite’s handling of SvelteKit modules during development and testing.

  • File Affected: tauri-app/vite.config.ts (line 67)
  • Observations:
    • The inline configuration now only includes [@tanstack/svelte-query].
    • Other parts of the repository are still importing @sveltejs/kit (e.g., in packages/webapp/vite.config.ts, packages/ui-components/vite.config.ts, etc.).

Please confirm this change is intentional and that any potential impacts on module optimization or test environment behavior have been accounted for.

Comment thread tauri-app/vite.config.ts
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🔭 Outside diff range comments (2)
packages/ui-components/src/lib/providers/wallet/context.ts (1)

27-63: 🧹 Nitpick (assertive)

Extend test coverage to setAccountContext.

Although the tests thoroughly cover getAccountContext, there is no unit test for setAccountContext. Consider adding the following snippet (or something similar) to ensure future refactors do not inadvertently break its functionality:

+ it('should set the account in context', () => {
+   const mockAccount = readable('0x456');
+   setAccountContext(mockAccount);
+   expect(setContext).toHaveBeenCalledWith(ACCOUNT_KEY, mockAccount);
+ });
tauri-app/src/lib/stores/walletconnect.ts (1)

40-42: ⚠️ Potential issue

Update store setter calls to match the new type.

The walletconnectAccount store is now typed as Hex | null, but it's still being set to undefined in these locations. This creates a type mismatch that could lead to runtime issues.

Apply these changes to ensure type consistency with the new store definition:

- walletconnectAccount.set(provider?.accounts?.[0] ?? undefined);
+ walletconnectAccount.set(provider?.accounts?.[0] as Hex ?? null);

- walletconnectAccount.set(undefined);
+ walletconnectAccount.set(null);

- walletconnectAccount.set(accounts?.[0] ?? undefined);
+ walletconnectAccount.set(accounts?.[0] as Hex ?? null);

- walletconnectAccount.set(undefined);
+ walletconnectAccount.set(null);

This ensures the values being set match the defined type and prevents potential type errors.

Also applies to: 43-45, 46-48, 106-106

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80036bf and 6024083.

📒 Files selected for processing (8)
  • packages/ui-components/src/__tests__/WalletProvider.test.ts (1 hunks)
  • packages/ui-components/src/lib/providers/wallet/WalletProvider.svelte (1 hunks)
  • packages/ui-components/src/lib/providers/wallet/context.ts (1 hunks)
  • packages/ui-components/src/lib/providers/wallet/useAccount.ts (1 hunks)
  • packages/ui-components/src/lib/types/account.ts (1 hunks)
  • packages/webapp/src/lib/stores/wagmi.ts (1 hunks)
  • tauri-app/src/lib/stores/walletconnect.ts (2 hunks)
  • tauri-app/src/lib/stores/wallets.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
packages/ui-components/src/__tests__/WalletProvider.test.ts (2)
packages/ui-components/src/lib/types/account.ts (1)
  • Account (4-4)
packages/ui-components/src/lib/providers/wallet/context.ts (1)
  • setAccountContext (23-25)
packages/ui-components/src/lib/providers/wallet/useAccount.ts (1)
packages/ui-components/src/lib/providers/wallet/context.ts (1)
  • getAccountContext (10-18)
packages/ui-components/src/lib/providers/wallet/context.ts (1)
packages/ui-components/src/lib/types/account.ts (1)
  • Account (4-4)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: git-clean
  • GitHub Check: Deploy-Preview
🔇 Additional comments (10)
packages/ui-components/src/lib/types/account.ts (1)

1-4: Clean type definition that provides good flexibility

The Account type is well-defined as a Svelte store that can contain either a hexadecimal address or null, making it perfect for representing both connected and disconnected wallet states.

packages/ui-components/src/lib/providers/wallet/WalletProvider.svelte (1)

1-11: LGTM: Clean implementation of a context provider component

The WalletProvider component follows a good pattern for providing context in Svelte applications. It properly sets a default value for the account (a readable store with null), making it easy to represent an unconnected state when no account is provided.

packages/ui-components/src/__tests__/WalletProvider.test.ts (1)

1-29: Good test implementation with proper mocking

The test correctly verifies that the WalletProvider component calls setAccountContext with the provided account prop. The mocking approach is clean, and including beforeEach to clear mocks between tests is a good practice.

packages/ui-components/src/lib/providers/wallet/useAccount.ts (1)

16-42: Well-structured inline tests

The inline test implementation is clean and thorough, properly mocking dependencies and verifying the expected behavior of the hook.

tauri-app/src/lib/stores/wallets.ts (1)

4-6: Use of Hex | null improves type safety.

Switching from string | undefined to Hex | null is a strong move toward stricter typing for wallet addresses. This change aligns well with the approach used in other wallet-related stores.

packages/webapp/src/lib/stores/wagmi.ts (1)

17-22: Consistent adoption of Hex | null.

Adopting Hex | null for signerAddress harmonizes type usage across the codebase. This improvement also helps reduce potential confusion by explicitly conveying that the address may be null if disconnected.

packages/ui-components/src/lib/providers/wallet/context.ts (2)

1-6: Dedicated context key setup looks good.

Defining ACCOUNT_KEY here clarifies context usage, facilitating maintainability and clear separation of concerns.


7-18: Well-documented context retrieval.

The getAccountContext function provides a straightforward method for retrieving the account store, with a clear and helpful error message prompting proper usage.

tauri-app/src/lib/stores/walletconnect.ts (2)

8-8: Appropriate type import added for Hex addresses.

Adding the Hex type from 'viem' is a good improvement for type safety, ensuring wallet addresses are properly typed. The imports for hexToNumber and isHex are also being used at line 50, keeping imports consistent with usage.


49-52: Existing code is already using the imported viem functions.

This section correctly uses the isHex and hexToNumber functions from viem. The conditional check ensures that chain IDs are properly converted to numbers regardless of their format (hex or decimal).

🧰 Tools
🪛 Biome (1.9.4)

[error] 51-51: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)

Comment thread packages/ui-components/src/lib/providers/wallet/useAccount.ts
Comment thread packages/ui-components/src/lib/providers/wallet/context.ts
Comment thread tauri-app/src/lib/stores/walletconnect.ts
@hardingjam hardingjam requested a review from hardyjosh March 24, 2025 08:36
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65f1d7a and 682d7a9.

📒 Files selected for processing (2)
  • packages/ui-components/src/__tests__/WalletProvider.test.ts (1 hunks)
  • packages/ui-components/src/lib/index.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/ui-components/src/__tests__/WalletProvider.test.ts (2)
packages/ui-components/src/lib/types/account.ts (1)
  • Account (4-4)
packages/ui-components/src/lib/providers/wallet/context.ts (1)
  • setAccountContext (23-25)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: git-clean
  • GitHub Check: Deploy-Preview
🔇 Additional comments (5)
packages/ui-components/src/lib/index.ts (2)

133-133: LGTM: New WalletProvider export added

The addition of the WalletProvider export aligns with the PR's objective of implementing a wrapper to expose connected account information to descendant components. The export is correctly placed in the "Providers" section of the file.


135-137: LGTM: Hook section organized with new useAccount export

Good organization of the "Hooks" section following the "Providers" section. The new useAccount hook export complements the WalletProvider by providing a way for descendant components to access the connected account information from the Svelte context.

packages/ui-components/src/__tests__/WalletProvider.test.ts (3)

1-12: Import structure and mock setup look good

The imports and mock setup are clean and well-organized. You're properly using vitest's mocking capabilities to isolate the component under test.


13-16: Good practice: Using beforeEach to reset mocks

Using beforeEach to clear all mocks before each test is a good practice that helps prevent test interference.


30-42: Well-implemented test for the default case

This test thoroughly checks the default behavior when no account is provided. It properly extracts and verifies the value from the store.

Comment thread packages/ui-components/src/__tests__/WalletProvider.test.ts
Comment thread packages/ui-components/src/__tests__/WalletProvider.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WalletProvider that doesn't require wagmi to exist in the shared lib

2 participants