Skip to content

Commit

Permalink
fix: work around cjs interop quirks of api-kit
Browse files Browse the repository at this point in the history
  • Loading branch information
frontendphil committed Dec 16, 2024
1 parent c727582 commit c295b55
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/execute/execute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assert from 'assert'
import {
Address,
Chain,
createWalletClient,
custom,
defineChain,
Expand Down Expand Up @@ -121,7 +122,7 @@ export const execute = async (
})
)

const apiKit = new SafeApiKit({ chainId: BigInt(chain) })
const apiKit = initApiKit(chain)
await apiKit.proposeTransaction({
safeAddress: safe,
safeTransactionData: {
Expand Down Expand Up @@ -150,6 +151,17 @@ export const execute = async (
}
}

// TODO: remove this once https://github.com/safe-global/safe-core-sdk/issues/514 is closed
const initApiKit = (chainId: ChainId) => {
// @ts-expect-error SafeApiKit is only available as a CJS module. That doesn't play super nice with us being ESM.
if (SafeApiKit.default) {
// @ts-expect-error See above
return new SafeApiKit.default({ chainId: BigInt(chainId) })
}

return new SafeApiKit({ chainId: BigInt(chainId) })
}

const _getWalletClient = ({
chain,
account,
Expand Down

0 comments on commit c295b55

Please sign in to comment.