feat(provider): Enhance provider setup with meaningful logging

- Introduced detailed system-level logging for provider initialization and configuration stages.
- Adjusted path references for accurate message sourcing.
- Abstracted walletConnectId for improved modularity.
This commit is contained in:
Samuel Andert 2023-07-24 10:36:55 +02:00
parent a572099312
commit 3f024283ef
4 changed files with 104 additions and 74 deletions

View File

@ -1,69 +0,0 @@
<script>
import { configureChains, createConfig } from '@wagmi/core';
import { gnosis } from '@wagmi/core/chains';
import { publicProvider } from '@wagmi/core/providers/public';
import { InjectedConnector } from '@wagmi/core/connectors/injected';
import { WalletConnectConnector } from '@wagmi/core/connectors/walletConnect';
import { jsonRpcProvider } from '@wagmi/core/providers/jsonRpc';
import { onMount } from 'svelte';
const chronicleChain = {
id: 175177,
name: 'Chronicle',
network: 'chronicle',
nativeCurrency: {
decimals: 18,
name: 'Chronicle - Lit Protocol Testnet',
symbol: 'LIT'
},
rpcUrls: {
default: {
http: ['https://chain-rpc.litprotocol.com/http']
},
public: {
http: ['https://chain-rpc.litprotocol.com/http']
}
},
blockExplorers: {
default: {
name: 'Chronicle - Lit Protocol Testnet',
url: 'https://chain.litprotocol.com'
}
},
testnet: true
};
const { chains, publicClient } = configureChains(
[chronicleChain, gnosis],
[
jsonRpcProvider({
rpc: (chain) => ({ http: chain.rpcUrls.default.http[0] })
}),
jsonRpcProvider({
rpc: () => ({
http: `https://rpc.gnosischain.com/`,
wss: `wss://rpc.gnosischain.com/wss`
})
}),
publicProvider()
]
);
onMount(() => {
createConfig({
autoConnect: true,
connectors: [
new InjectedConnector({ chains }),
new WalletConnectConnector({
chains,
options: {
projectId: '7db8ca514b865088d90cebec1bf28318'
}
})
],
publicClient
});
});
</script>

View File

@ -1,5 +1,5 @@
<script>
import { messages, createMessage } from '$lib/services/messages';
import { messages } from '$lib/services/messages';
import { onMount, afterUpdate } from 'svelte';
import Composite from './Composite.svelte';

View File

@ -0,0 +1,91 @@
import { configureChains, createConfig } from '@wagmi/core';
import { gnosis } from '@wagmi/core/chains';
import { publicProvider } from '@wagmi/core/providers/public';
import { InjectedConnector } from '@wagmi/core/connectors/injected';
import { WalletConnectConnector } from '@wagmi/core/connectors/walletConnect';
import { jsonRpcProvider } from '@wagmi/core/providers/jsonRpc';
import { createMessage } from '$lib/services/messages';
export interface ProviderData {
walletConnectId: string;
}
const chronicleChain = {
id: 175177,
name: 'Chronicle',
network: 'chronicle',
nativeCurrency: {
decimals: 18,
name: 'Chronicle - Lit Protocol Testnet',
symbol: 'LIT'
},
rpcUrls: {
default: {
http: ['https://chain-rpc.litprotocol.com/http']
},
public: {
http: ['https://chain-rpc.litprotocol.com/http']
}
},
blockExplorers: {
default: {
name: 'Chronicle - Lit Protocol Testnet',
url: 'https://chain.litprotocol.com'
}
},
testnet: true
};
export function initProvider(data: ProviderData) {
createMessage({
text: 'Provider setup initialization started...',
sender: '$lib/services/provider.ts',
type: 'SYSTEM'
});
const { chains, publicClient } = configureChains(
[chronicleChain, gnosis],
[
jsonRpcProvider({
rpc: (chain) => ({ http: chain.rpcUrls.default.http[0] })
}),
jsonRpcProvider({
rpc: () => ({
http: `https://rpc.gnosischain.com/`,
wss: `wss://rpc.gnosischain.com/wss`
})
}),
publicProvider()
]
);
createMessage({
text: 'Chains configured successfully...',
sender: '$lib/services/provider.ts',
type: 'SYSTEM'
});
createConfig({
autoConnect: true,
connectors: [
new InjectedConnector({ chains }),
new WalletConnectConnector({
chains,
options: {
projectId: data.walletConnectId
}
})
],
publicClient
});
createMessage({
text: 'Provider configuration created and autoConnect enabled...',
sender: '$lib/services/provider.ts',
type: 'SYSTEM'
});
}

View File

@ -1,10 +1,18 @@
<script>
import '../app.css';
import Provider from '$lib/Provider.svelte';
import { initProvider } from '$lib/services/provider.ts';
import { onMount } from 'svelte';
/** @type {import('$lib/services/provider.ts').ProviderData} */
const providerData = {
walletConnectId: import.meta.env.VITE_WALLETCONNECT_ID
};
onMount(() => {
initProvider(providerData);
});
</script>
<Provider />
<div class="w-screen h-screen overflow-hidden relative">
<div class="relative w-screen h-screen overflow-hidden">
<slot />
</div>