Skip to content

Commit 6040757

Browse files
mathiasmoellerH3xeptchybisov
authored
fix!: deep clone incoming routes to prevent side effects (#62)
* fix: deep clone incoming routes to prevent side effects * feat: added getTools (#61) * feat: added getTools * feat!: improve status management (#63) * refactor: cleanup error messages, add a curly rule to eslint * refactor: add a curly rule to eslint * feat: define process type * feat: get processing messages depending on type and status * fix: add PENDING state for allowance process after resume * feat: add TRANSACTION process type * chore: bump packages * refactor: remove unnecessary comments Co-authored-by: Leonardo Cascianelli <[email protected]> Co-authored-by: Eugene Chybisov <[email protected]>
1 parent e22ab60 commit 6040757

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/Lifi.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
} from './types'
4545
import { ValidationError } from './utils/errors'
4646
import { parseBackendError } from './utils/parseError'
47+
import { deepClone } from './utils/utils'
4748

4849
export default class LIFI {
4950
private activeRouteDictionary: ActiveRouteDictionary = {}
@@ -233,12 +234,15 @@ export default class LIFI {
233234
route: Route,
234235
settings?: ExecutionSettings
235236
): Promise<Route> => {
237+
const clonedRoute = deepClone<Route>(route) // deep clone to prevent side effects
238+
236239
// check if route is already running
237-
if (this.activeRouteDictionary[route.id]) {
238-
return route
239-
} // TODO: maybe inform user why nothing happens?
240+
if (this.activeRouteDictionary[clonedRoute.id]) {
241+
// TODO: maybe inform user why nothing happens?
242+
return clonedRoute
243+
}
240244

241-
return this.executeSteps(signer, route, settings)
245+
return this.executeSteps(signer, clonedRoute, settings)
242246
}
243247

244248
/**
@@ -254,17 +258,19 @@ export default class LIFI {
254258
route: Route,
255259
settings?: ExecutionSettings
256260
): Promise<Route> => {
257-
const activeRoute = this.activeRouteDictionary[route.id]
261+
const clonedRoute = deepClone<Route>(route) // deep clone to prevent side effects
262+
263+
const activeRoute = this.activeRouteDictionary[clonedRoute.id]
258264
if (activeRoute) {
259265
const executionHalted = activeRoute.executors.some(
260266
(executor) => executor.executionStopped
261267
)
262268
if (!executionHalted) {
263-
return route
269+
return clonedRoute
264270
}
265271
}
266272

267-
return this.executeSteps(signer, route, settings)
273+
return this.executeSteps(signer, clonedRoute, settings)
268274
}
269275

270276
private executeSteps = async (

0 commit comments

Comments
 (0)