-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/development' into amg_provider_s…
…trategy
- Loading branch information
Showing
11 changed files
with
1,464 additions
and
1,374 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
70 changes: 70 additions & 0 deletions
70
src/core/providers/helpers/components/SignTransactionsModal/SignTransactionsStateManager.ts
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,70 @@ | ||
import { | ||
ISignTransactionsModalData, | ||
SignEventsEnum | ||
} from './signTransactionsModal.types'; | ||
|
||
export interface IEventBus { | ||
publish(event: string, data: any): void; | ||
} | ||
|
||
const notInitializedError = () => new Error('Event bus not initialized'); | ||
|
||
export class SignTransactionsStateManager<T extends IEventBus = IEventBus> { | ||
private static instance: SignTransactionsStateManager<IEventBus> | null = | ||
null; | ||
public readonly addressesPerPage = 10; | ||
|
||
private eventBus: T = { | ||
publish: notInitializedError, | ||
subscribe: notInitializedError, | ||
unsubscribe: notInitializedError | ||
} as unknown as T; | ||
|
||
// whole data to be sent on update events | ||
private initialData: ISignTransactionsModalData = { | ||
transaction: null | ||
}; | ||
|
||
private data: ISignTransactionsModalData = { ...this.initialData }; | ||
|
||
private constructor(eventBus: T) { | ||
this.eventBus = eventBus; | ||
this.resetData(); | ||
} | ||
|
||
public static getInstance<U extends IEventBus>( | ||
eventBus?: U | ||
): SignTransactionsStateManager<U> | null { | ||
if (!eventBus) { | ||
return null; | ||
} | ||
if (!SignTransactionsStateManager.instance) { | ||
SignTransactionsStateManager.instance = new SignTransactionsStateManager( | ||
eventBus | ||
); | ||
} | ||
return SignTransactionsStateManager.instance as SignTransactionsStateManager<U>; | ||
} | ||
|
||
public updateTransaction(members: Partial<ISignTransactionsModalData>): void { | ||
this.data = { | ||
...this.data, | ||
...members | ||
}; | ||
this.notifyDataUpdate(); | ||
} | ||
|
||
private resetData(): void { | ||
this.data = { ...this.initialData }; | ||
} | ||
|
||
public closeAndReset(): void { | ||
this.data.shouldClose = true; | ||
this.notifyDataUpdate(); | ||
this.resetData(); | ||
} | ||
|
||
private notifyDataUpdate(): void { | ||
this.eventBus.publish(SignEventsEnum.DATA_UPDATE, this.data); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/core/providers/helpers/components/SignTransactionsModal/signTransactionsModal.types.ts
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,17 @@ | ||
export interface ITransactionData { | ||
receiver?: string; | ||
value?: string; | ||
} | ||
|
||
export interface ISignTransactionsModalData { | ||
transaction: ITransactionData | null; | ||
shouldClose?: true; | ||
} | ||
|
||
export enum SignEventsEnum { | ||
'SIGN_TRANSACTION' = 'SIGN_TRANSACTION', | ||
'NEXT_PAGE' = 'NEXT_PAGE', | ||
'PREV_PAGE' = 'PREV_PAGE', | ||
'CLOSE' = 'CLOSE', | ||
'DATA_UPDATE' = 'DATA_UPDATE' | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.