Skip to content

Commit

Permalink
Merge pull request #209 from reservoirprotocol/chore/drop-lodash
Browse files Browse the repository at this point in the history
Chore/drop lodash
  • Loading branch information
pedromcunha authored Aug 6, 2024
2 parents b1a1229 + 3af0a27 commit a690842
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-cherries-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reservoir0x/relay-sdk': patch
---

Drop lodash cloneDeep in favor of native cloning
3 changes: 1 addition & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
"viem": "^2.9.31"
},
"dependencies": {
"axios": "^1.6.5",
"lodash-es": "^4.17.21"
"axios": "^1.6.5"
},
"keywords": [
"eth",
Expand Down
9 changes: 4 additions & 5 deletions packages/sdk/src/actions/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { getClient } from '../client.js'
import {
executeSteps,
adaptViemWallet,
getCurrentStepData
getCurrentStepData,
safeStructuredClone
} from '../utils/index.js'
import { type WalletClient } from 'viem'
import { isViemWalletClient } from '../utils/viemWallet.js'
import cloneDeep from 'lodash-es/cloneDeep.js'

export type ExecuteActionParameters = {
quote: Execute
Expand Down Expand Up @@ -49,9 +49,8 @@ export async function execute(data: ExecuteActionParameters) {
throw new Error('Missing chainId from quote')
}

const modifiableQuote = cloneDeep(quote)

const { request, ..._quote } = modifiableQuote
const { request, ...restOfQuote } = quote
const _quote = safeStructuredClone(restOfQuote)

const data = await executeSteps(
chainId,
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export {
type SimulateContractRequest,
isSimulateContractRequest
} from './simulateContract.js'
export { safeStructuredClone } from './structuredClone.js'
7 changes: 7 additions & 0 deletions packages/sdk/src/utils/structuredClone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function safeStructuredClone<T>(obj: T): T {
if (typeof structuredClone === 'function') {
return structuredClone(obj)
}
// Fallback implementation, for Chrome < 98 (before 2022)
return JSON.parse(JSON.stringify(obj))
}
7 changes: 0 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a690842

Please sign in to comment.