Skip to content

Commit

Permalink
Use consola for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ezynda3 committed Mar 10, 2024
1 parent 9126f36 commit 42134d6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)],
Expand All @@ -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,
Expand All @@ -104,7 +106,7 @@ export const getContractInformation = async (
address,
}
} catch (e) {
console.error(e)
consola.error(e)
throw new Error('Contract not found')
}
}
Expand Down

0 comments on commit 42134d6

Please sign in to comment.