From 5ee59cb8202175a3b9c3817508f6a0d645791c48 Mon Sep 17 00:00:00 2001 From: Samuel Andert Date: Mon, 24 Jul 2023 11:11:51 +0200 Subject: [PATCH] docs(provider.ts): Add README documentation, +cleanup --- src/lib/services/provider/README.md | 85 +++++++++++++++++++++ src/lib/services/{ => provider}/provider.ts | 2 - src/routes/+layout.svelte | 4 +- tests/test.ts | 6 -- tsconfig.json | 11 ++- 5 files changed, 96 insertions(+), 12 deletions(-) create mode 100644 src/lib/services/provider/README.md rename src/lib/services/{ => provider}/provider.ts (99%) delete mode 100644 tests/test.ts diff --git a/src/lib/services/provider/README.md b/src/lib/services/provider/README.md new file mode 100644 index 0000000..396173c --- /dev/null +++ b/src/lib/services/provider/README.md @@ -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); diff --git a/src/lib/services/provider.ts b/src/lib/services/provider/provider.ts similarity index 99% rename from src/lib/services/provider.ts rename to src/lib/services/provider/provider.ts index fd6cf97..9cbf09a 100644 --- a/src/lib/services/provider.ts +++ b/src/lib/services/provider/provider.ts @@ -10,8 +10,6 @@ export interface ProviderData { walletConnectId: string; } - - const chronicleChain = { id: 175177, name: 'Chronicle', diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 19647b5..fa57d15 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,9 +1,9 @@