Skip to content

Commit

Permalink
Fix monorepo loading of exports from package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferossgp committed Nov 4, 2024
1 parent edd7ee4 commit 84f7490
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
27 changes: 24 additions & 3 deletions apps/web/src/lib/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ import { RPCProviderLive } from './rpc-provider'
import {
decodeTransactionByHash,
EtherscanV2StrategyResolver,
FetchTransactionError,
FourByteStrategyResolver,
OpenchainStrategyResolver,
RPCFetchError,
SourcifyStrategyResolver,
UnknownNetwork,
UnsupportedEvent,
type DecodedTransaction,
} from '@3loop/transaction-decoder'
import { SqlAbiStore, SqlContractMetaStore } from '@3loop/transaction-decoder/sql'
import { Hex } from 'viem'
import { DatabaseLive } from './database'
import { SqlError } from '@effect/sql/SqlError'
import { ConfigError } from 'effect/ConfigError'
import { ParseError } from 'effect/ParseResult'

const AbiStoreLive = SqlAbiStore.make({
default: [
Expand All @@ -23,8 +30,10 @@ const AbiStoreLive = SqlAbiStore.make({
],
})

const LoadersLayer = Layer.mergeAll(AbiStoreLive, SqlContractMetaStore.make())
const DataLayer = Layer.mergeAll(DatabaseLive, RPCProviderLive)
const MetaStoreLive = SqlContractMetaStore.make()

const DataLayer = Layer.mergeAll(RPCProviderLive, DatabaseLive)
const LoadersLayer = Layer.mergeAll(AbiStoreLive, MetaStoreLive)
const MainLayer = Layer.provideMerge(LoadersLayer, DataLayer)

export async function decodeTransaction({
Expand All @@ -34,7 +43,19 @@ export async function decodeTransaction({
chainID: number
hash: string
}): Promise<DecodedTransaction | undefined> {
const runnable = Effect.provide(decodeTransactionByHash(hash as Hex, chainID), MainLayer)
// NOTE: For unknonw reason the context of main layer is still missing the SqlClient in the type
const runnable = Effect.provide(decodeTransactionByHash(hash as Hex, chainID), MainLayer) as Effect.Effect<
DecodedTransaction,
| SqlError
| UnknownNetwork
| ConfigError
| SqlError
| RPCFetchError
| ParseError
| UnsupportedEvent
| FetchTransactionError,
never
>
return Effect.runPromise(runnable).catch((error: unknown) => {
console.error('Decode error', JSON.stringify(error, null, 2))
return undefined
Expand Down
3 changes: 2 additions & 1 deletion apps/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
}
],
"paths": {
"@/*": ["./src/*"]
"@/*": ["./src/*"],
"@3loop/transaction-decoder/*": ["../../packages/transaction-decoder/dist/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
Expand Down
6 changes: 3 additions & 3 deletions packages/transaction-decoder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "@3loop/transaction-decoder",
"version": "0.19.4",
"description": "A library for decoding Ethereum transactions",
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "./dist/index.d.ts",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"license": "GPL-3.0-only",
"type": "module",
"exports": {
Expand Down

0 comments on commit 84f7490

Please sign in to comment.