-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: onboarding multisig duplication (#3076)
* fix: onbording mutisig duplication * fix: test
- Loading branch information
1 parent
8ee699d
commit 37e9096
Showing
7 changed files
with
110 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { createEffect } from 'effector'; | ||
|
||
type Params<P, R> = { | ||
fn(params: P, abort: AbortSignal): Awaited<R> | Promise<Awaited<R>>; | ||
key(params: P): string; | ||
}; | ||
|
||
export const takeLast = <P, R>({ fn, key }: Params<P, R>) => { | ||
const controllers: Record<string, AbortController> = {}; | ||
|
||
return createEffect(async (params: P) => { | ||
const effectKey = key(params); | ||
|
||
let controller = controllers[effectKey]; | ||
if (controller) controller.abort(); | ||
controller = new AbortController(); | ||
controllers[effectKey] = controller; | ||
|
||
try { | ||
return await fn(params, controller.signal); | ||
} finally { | ||
if (controllers[effectKey] === controller) { | ||
delete controllers[effectKey]; | ||
} | ||
controller.signal.throwIfAborted(); | ||
} | ||
}); | ||
}; |