diff --git a/bun.lockb b/bun.lockb index 6604000..e67e8a2 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 80e900f..4e8bec9 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "bits-ui": "^0.9.8", "clsx": "^2.0.0", "cmdk-sv": "^0.0.4", + "consola": "^3.2.3", "drizzle-orm": "^0.29.3", "lucide-svelte": "^0.276.0", "radix-icons-svelte": "^1.2.1", diff --git a/src/lib/utils.ts b/src/lib/utils.ts index b2b66b9..486b6c6 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -2,13 +2,14 @@ import { type ClassValue, clsx } from 'clsx' import { twMerge } from 'tailwind-merge' import { cubicOut } from 'svelte/easing' import type { TransitionConfig } from 'svelte/transition' -import { parseAbi, type Address } from 'viem' +import { type Address } from 'viem' import type { Contract } from './types' import toast from 'svelte-french-toast' import Database from 'bun:sqlite' import { drizzle } from 'drizzle-orm/bun-sqlite' import { contracts } from '../schema' import { and, eq } from 'drizzle-orm' +import consola from 'consola' export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)) @@ -70,13 +71,14 @@ export const getContractInformation = async ( const sqlite = new Database('./data/louper.db') const db = drizzle(sqlite) + consola.info('Fetching contract information for', address, 'on chain', chainId) const result = await db .select() .from(contracts) .where(and(eq(contracts.address, address), eq(contracts.chainId, chainId))) if (result.length) { - console.log('Found in db cache!') + consola.info('Found in db cache') return { name: result[0].name, abi: [...JSON.parse(result[0].abi)], @@ -89,7 +91,7 @@ export const getContractInformation = async ( const contractData = await response.json() // Update the database - console.log('Adding to db cache...') + consola.info('Updating db cache') await db.insert(contracts).values({ id: `${chainId}:${address}`, name: contractData.name, @@ -104,7 +106,7 @@ export const getContractInformation = async ( address, } } catch (e) { - console.error(e) + consola.error(e) throw new Error('Contract not found') } }