From cf999ceb2ce9878752c55749c3f95e4246398e90 Mon Sep 17 00:00:00 2001 From: cor Date: Mon, 2 Oct 2023 04:03:07 +0200 Subject: [PATCH] fix(site): fixes --- site/src/lib/Ethers.svelte | 3 +- site/src/lib/initClients.ts | 50 ------------------- site/src/lib/stores/wallets.ts | 4 +- site/src/lib/transferDemo.ts | 8 ++- .../routes/blog/start-of-the-endgame/+page.md | 3 +- 5 files changed, 12 insertions(+), 56 deletions(-) delete mode 100644 site/src/lib/initClients.ts diff --git a/site/src/lib/Ethers.svelte b/site/src/lib/Ethers.svelte index 809dc4b20d..368da48059 100644 --- a/site/src/lib/Ethers.svelte +++ b/site/src/lib/Ethers.svelte @@ -2,13 +2,12 @@ import { ethers } from "ethers"; import { onMount } from 'svelte'; - let provider; let signer; onMount(async () => { console.log("connecting to ethereum") - provider = new ethers.providers.Web3Provider(window.ethereum, "any") + provider = new ethers.providers.Web3Provider(window.ethereum, "any"); provider.on("network", (newNetwork, oldNetwork) => { // When a Provider makes its initial connection, it emits a "network" // event with a null oldNetwork along with the newNetwork. So, if the diff --git a/site/src/lib/initClients.ts b/site/src/lib/initClients.ts deleted file mode 100644 index 58e2b766e9..0000000000 --- a/site/src/lib/initClients.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { tendermintClient, stargateClient, unionAccount, unionBalance } from '$lib/stores/wallets'; -import { get } from 'svelte/store'; - -export default async function initClients(): void { - let { CosmjsOfflineSigner } = await import('@leapwallet/cosmos-snap-provider'); - let { getSnap, connectSnap, suggestChain, getKey } = await import( - '@leapwallet/cosmos-snap-provider' - ); - let { GasPrice, SigningStargateClient } = await import('@cosmjs/stargate'); - let { Tendermint37Client } = await import('@cosmjs/tendermint-rpc'); - - const snapInstalled = await getSnap(); - if (!snapInstalled) { - connectSnap(); // Initiates installation if not already present - } - - const chainId = 'union-testnet-3'; - - await suggestChain( - { - chainId: 'union-testnet-3', - chainName: 'union-testnet', - bip44: { coinType: 118 }, - bech32Config: { - bech32PrefixAccAddr: 'union' - } - }, - { force: false } - ); - const offlineSigner = new CosmjsOfflineSigner(chainId); - - let accounts = await offlineSigner.getAccounts(); - if (accounts.length > 0) { - unionAccount.set(accounts[0]); - } - - const key = await getKey(chainId); - const rpcUrl = 'wss://rpc.0xc0dejug.uno'; // Populate with an RPC URL corresponding to the given chainId - tendermintClient.set(await Tendermint37Client.connect(rpcUrl)); - let tmClient = get(tendermintClient); - if (tmClient == null) { - return; - } - console.log('creating stargate client'); - stargateClient.set( - await SigningStargateClient.createWithSigner(tmClient, offlineSigner, { - gasPrice: GasPrice.fromString('0.001muno') - }) - ); -} diff --git a/site/src/lib/stores/wallets.ts b/site/src/lib/stores/wallets.ts index dc68ccb45c..e735bc31b6 100644 --- a/site/src/lib/stores/wallets.ts +++ b/site/src/lib/stores/wallets.ts @@ -3,9 +3,11 @@ import type { Writable } from 'svelte/store'; import type { Tendermint37Client } from '@cosmjs/tendermint-rpc'; import type { SigningStargateClient } from '@cosmjs/stargate'; import type { AccountData, Coin } from '@cosmjs/amino'; +import type { ApolloClient, InMemoryCache, NormalizedCacheObject } from '@apollo/client'; export const tendermintClient: Writable = writable(null); export const stargateClient: Writable = writable(null); export const unionAccount: Writable = writable(null); export const unionBalance: Writable = writable(null); -export const apolloClient: Writable = writable(null); +export const apolloClient: Writable | null> = writable(null); +export const ethersProvider: Writable = writable(null); diff --git a/site/src/lib/transferDemo.ts b/site/src/lib/transferDemo.ts index e6706abbc8..bf424965d9 100644 --- a/site/src/lib/transferDemo.ts +++ b/site/src/lib/transferDemo.ts @@ -78,8 +78,10 @@ const GET_UNO_FROM_FAUCET = gql` export const getUnoFromFaucet = async () => { const uAccount = get(unionAccount); const apollo = get(apolloClient); - if (uAccount === null) { - console.error('trying to get uno from faucet before accounts are loaded'); + if (uAccount === null || apollo === null) { + console.error( + 'trying to get uno from faucet before accounts are loaded or apollo client has not been init' + ); return; } @@ -129,3 +131,5 @@ export const getBalance = async () => { } unionBalance.set(await sgClient.getBalance(uAccount.address, 'muno')); }; + +export const setupEthers = async () => {}; diff --git a/site/src/routes/blog/start-of-the-endgame/+page.md b/site/src/routes/blog/start-of-the-endgame/+page.md index 244bf7b1bd..27fb589f0b 100644 --- a/site/src/routes/blog/start-of-the-endgame/+page.md +++ b/site/src/routes/blog/start-of-the-endgame/+page.md @@ -11,13 +11,14 @@ published: true import TokenTransfer from '$lib/TokenTransfer.svelte'; // import Ethers from '$lib/Ethers.svelte'; import { browser } from '$app/environment'; - import { initClients, getBalanceWorker } from '$lib/transferDemo'; + import { initClients, getBalanceWorker, setupEthers } from '$lib/transferDemo'; import { onMount } from 'svelte'; onMount(async () => { if (browser) { await initClients(); getBalanceWorker(); + setupEthers(); } })