-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introducing hub, our new wallet management
- Loading branch information
1 parent
4f06666
commit 97222bc
Showing
69 changed files
with
5,262 additions
and
381 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import type { Actions, Context, Operators } from '../hub/namespaces/types.js'; | ||
import type { AnyFunction, FunctionWithContext } from '../types/actions.js'; | ||
|
||
export interface ActionByBuilder<T, Context> { | ||
actionName: keyof T; | ||
and: Operators<T>; | ||
or: Operators<T>; | ||
after: Operators<T>; | ||
before: Operators<T>; | ||
action: FunctionWithContext<T[keyof T], Context>; | ||
} | ||
|
||
/* | ||
* TODO: | ||
* Currently, to use this builder you will write something like this: | ||
* new ActionBuilder<EvmActions, 'disconnect'>('disconnect').after(....) | ||
* | ||
* I couldn't figure it out to be able typescript infer the constructor value as key of actions. | ||
* Ideal usage: | ||
* new ActionBuilder<EvmActions>('disconnect').after(....) | ||
* | ||
*/ | ||
export class ActionBuilder<T extends Actions<T>, K extends keyof T> { | ||
readonly name: K; | ||
#and: Operators<T> = new Map(); | ||
#or: Operators<T> = new Map(); | ||
#after: Operators<T> = new Map(); | ||
#before: Operators<T> = new Map(); | ||
#action: FunctionWithContext<T[keyof T], Context<T>> | undefined; | ||
|
||
constructor(name: K) { | ||
this.name = name; | ||
} | ||
|
||
public and(action: FunctionWithContext<AnyFunction, Context<T>>) { | ||
if (!this.#and.has(this.name)) { | ||
this.#and.set(this.name, []); | ||
} | ||
this.#and.get(this.name)?.push(action); | ||
return this; | ||
} | ||
|
||
public or(action: FunctionWithContext<AnyFunction, Context<T>>) { | ||
if (!this.#or.has(this.name)) { | ||
this.#or.set(this.name, []); | ||
} | ||
this.#or.get(this.name)?.push(action); | ||
return this; | ||
} | ||
|
||
public before(action: FunctionWithContext<AnyFunction, Context<T>>) { | ||
if (!this.#before.has(this.name)) { | ||
this.#before.set(this.name, []); | ||
} | ||
this.#before.get(this.name)?.push(action); | ||
return this; | ||
} | ||
|
||
public after(action: FunctionWithContext<AnyFunction, Context<T>>) { | ||
if (!this.#after.has(this.name)) { | ||
this.#after.set(this.name, []); | ||
} | ||
this.#after.get(this.name)?.push(action); | ||
return this; | ||
} | ||
|
||
public action(action: FunctionWithContext<T[keyof T], Context<T>>) { | ||
this.#action = action; | ||
return this; | ||
} | ||
|
||
public build(): ActionByBuilder<T, Context<T>> { | ||
if (!this.#action) { | ||
throw new Error('Your action builder should includes an action.'); | ||
} | ||
|
||
return { | ||
actionName: this.name, | ||
action: this.#action, | ||
before: this.#before, | ||
after: this.#after, | ||
and: this.#and, | ||
or: this.#or, | ||
}; | ||
} | ||
} |
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,5 @@ | ||
export type { ProxiedNamespace, FindProxiedNamespace } from './types.js'; | ||
|
||
export { NamespaceBuilder } from './namespace.js'; | ||
export { ProviderBuilder } from './provider.js'; | ||
export { ActionBuilder } from './action.js'; |
Oops, something went wrong.