Skip to content

Commit

Permalink
refactor: TS message-manager add return time & use satisfies
Browse files Browse the repository at this point in the history
  • Loading branch information
digiwand committed Aug 29, 2024
1 parent 6386aea commit 784bb66
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
15 changes: 6 additions & 9 deletions packages/message-manager/src/AbstractMessageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ export abstract class AbstractMessageManager<
* @param req - The original request object.
* @returns The messageParams with the request props added.
*/
protected addRequestToMessageParams(
messageParams: AbstractMessageParams,
req?: OriginalRequest,
) {
protected addRequestToMessageParams<
MessageParams extends AbstractMessageParams,
>(messageParams: MessageParams, req?: OriginalRequest) {
const updatedMessageParams = {
...messageParams,
};
Expand All @@ -161,11 +160,9 @@ export abstract class AbstractMessageManager<
* @param req - The original request object.
* @returns The new unapproved message for a specified type.
*/
protected createUnapprovedMessage(
messageParams: AbstractMessageParams,
type: ApprovalType,
req?: OriginalRequest,
) {
protected createUnapprovedMessage<
MessageParams extends AbstractMessageParams,
>(messageParams: MessageParams, type: ApprovalType, req?: OriginalRequest) {
const messageId = random();

return {
Expand Down
4 changes: 2 additions & 2 deletions packages/message-manager/src/DecryptMessageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ export class DecryptMessageManager extends AbstractMessageManager<
const updatedMessageParams = this.addRequestToMessageParams(
messageParams,
req,
) as DecryptMessageParams;
) satisfies DecryptMessageParams;
messageParams.data = normalizeMessageData(messageParams.data);

const messageData = this.createUnapprovedMessage(
updatedMessageParams,
ApprovalType.EthDecrypt,
req,
) as DecryptMessage;
) satisfies DecryptMessage;

const messageId = messageData.id;

Expand Down
4 changes: 2 additions & 2 deletions packages/message-manager/src/EncryptionPublicKeyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ export class EncryptionPublicKeyManager extends AbstractMessageManager<
const updatedMessageParams = this.addRequestToMessageParams(
messageParams,
req,
) as EncryptionPublicKeyParams;
) satisfies EncryptionPublicKeyParams;

const messageData = this.createUnapprovedMessage(
updatedMessageParams,
ApprovalType.EthGetEncryptionPublicKey,
req,
) as EncryptionPublicKey;
) satisfies EncryptionPublicKey;

const messageId = messageData.id;

Expand Down
4 changes: 2 additions & 2 deletions packages/message-manager/src/PersonalMessageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class PersonalMessageManager extends AbstractMessageManager<
const updatedMessageParams = this.addRequestToMessageParams(
messageParams,
req,
) as PersonalMessageParams;
) satisfies PersonalMessageParams;

updatedMessageParams.data = normalizeMessageData(messageParams.data);
updatedMessageParams.siwe = ethereumSignInData;
Expand All @@ -104,7 +104,7 @@ export class PersonalMessageManager extends AbstractMessageManager<
updatedMessageParams,
ApprovalType.PersonalSign,
req,
) as PersonalMessage;
) satisfies PersonalMessage;

const messageId = messageData.id;
await this.addMessage(messageData);
Expand Down
4 changes: 2 additions & 2 deletions packages/message-manager/src/TypedMessageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ export class TypedMessageManager extends AbstractMessageManager<
const updatedMessageParams = this.addRequestToMessageParams(
messageParams,
req,
) as TypedMessageParams;
) satisfies TypedMessageParams;

const messageData = this.createUnapprovedMessage(
updatedMessageParams,
ApprovalType.EthSignTypedData,
req,
) as TypedMessage;
) satisfies TypedMessage;

const messageId = messageData.id;

Expand Down

0 comments on commit 784bb66

Please sign in to comment.