docs(provider.ts): Add README documentation, +cleanup

This commit is contained in:
Samuel Andert 2023-07-24 11:11:51 +02:00
parent 3f024283ef
commit 5ee59cb820
5 changed files with 96 additions and 12 deletions

View File

@ -0,0 +1,85 @@
# Provider Service Documentation
This documentation provides an overview of the `provider.ts` file in the `$lib/services` directory. This module deals with the configuration and initialization of blockchain providers.
## Table of Contents
- [Provider Service Documentation](#provider-service-documentation)
- [Table of Contents](#table-of-contents)
- [Imports](#imports)
- [Interfaces](#interfaces)
- [ProviderData](#providerdata)
- [ProviderData Interface](#providerdata-interface)
- [Constants](#constants)
- [chronicleChain](#chroniclechain)
- [Functions](#functions)
- [initProvider(data: ProviderData)](#initproviderdata-providerdata)
- [Usage](#usage)
---
## Imports
The file has several important imports:
- **@wagmi/core**: Core utilities for blockchain operations.
- `configureChains`
- `createConfig`
- **@wagmi/core/chains**: Chain-specific configurations.
- `gnosis`
- **@wagmi/core/providers**: Providers for the blockchain networks.
- `publicProvider`
- **@wagmi/core/connectors**: Connectors for blockchain wallets.
- `InjectedConnector`
- `WalletConnectConnector`
- **@wagmi/core/providers/jsonRpc**: Provider for sending JSON RPC requests.
- `jsonRpcProvider`
- **$lib/services/messages**: Service for creating messages.
- `createMessage`
---
## Interfaces
### ProviderData
```typescript
export interface ProviderData {
walletConnectId: string;
}
### ProviderData Interface
This interface represents the data structure required for the provider configuration, which currently only includes the `walletConnectId`.
### Constants
#### chronicleChain
This constant provides the configuration for the Chronicle chain. It includes the chain's ID, name, network information, native currency details, RPC URLs, block explorers, and testnet flag.
### Functions
#### initProvider(data: ProviderData)
This function is responsible for initializing the blockchain provider setup. It takes in a `ProviderData` object as a parameter.
The function performs the following steps:
1. Logs the start of the provider setup process.
2. Configures the chains using the `configureChains` utility.
3. Logs successful chain configuration.
4. Creates a configuration for blockchain connectivity, setting up connectors for different wallet types, and enabling auto connection.
5. Logs the successful creation of the provider configuration.
### Usage
To utilize this module, you would typically import and call the `initProvider` function, passing in the required data:
```typescript
import { initProvider, ProviderData } from '$lib/services/provider.ts';
const data: ProviderData = {
walletConnectId: 'YOUR_WALLET_CONNECT_ID'
};
initProvider(data);

View File

@ -10,8 +10,6 @@ export interface ProviderData {
walletConnectId: string;
}
const chronicleChain = {
id: 175177,
name: 'Chronicle',

View File

@ -1,9 +1,9 @@
<script>
import '../app.css';
import { initProvider } from '$lib/services/provider.ts';
import { initProvider } from '$lib/services/provider/provider';
import { onMount } from 'svelte';
/** @type {import('$lib/services/provider.ts').ProviderData} */
/** @type {import('$lib/services/provider/provider').ProviderData} */
const providerData = {
walletConnectId: import.meta.env.VITE_WALLETCONNECT_ID
};

View File

@ -1,6 +0,0 @@
import { expect, test } from '@playwright/test';
test('index page has expected h1', async ({ page }) => {
await page.goto('/');
await expect(page.getByRole('heading', { name: 'Welcome to SvelteKit' })).toBeVisible();
});

View File

@ -8,8 +8,15 @@
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true
}
"strict": true,
"types": ["jest", "node"]
},
"include": [
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.svelte",
"tests/**/*.ts"
, "tests/provider.test.js" ]
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes