-
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.
Make types and enums more generic (#1)
* make types and enums more generic and fix login response for dapp provider base type * 0.1.0
- Loading branch information
1 parent
e160215
commit 97ce670
Showing
13 changed files
with
162 additions
and
156 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,6 @@ | ||
type SafeWindowType<T extends Window = Window> = { | ||
[K in keyof T]?: T[K]; | ||
}; | ||
|
||
export const safeWindow: SafeWindowType = | ||
typeof window !== "undefined" ? window : ({} as SafeWindowType); |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./crossWindowProviderConstants"; | ||
export * from "./windowProviderConstants"; | ||
export * from "./browserConstants"; |
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,24 @@ | ||
import { ResponseTypeMap } from "../types"; | ||
import { | ||
WindowProviderRequestEnums, | ||
WindowProviderResponseEnums, | ||
} from "../enums"; | ||
|
||
export const responseTypeMap: ResponseTypeMap = { | ||
[WindowProviderRequestEnums.signTransactionsRequest]: | ||
WindowProviderResponseEnums.signTransactionsResponse, | ||
[WindowProviderRequestEnums.guardTransactionsRequest]: | ||
WindowProviderResponseEnums.guardTransactionsResponse, | ||
[WindowProviderRequestEnums.signMessageRequest]: | ||
WindowProviderResponseEnums.signMessageResponse, | ||
[WindowProviderRequestEnums.loginRequest]: | ||
WindowProviderResponseEnums.loginResponse, | ||
[WindowProviderRequestEnums.logoutRequest]: | ||
WindowProviderResponseEnums.disconnectResponse, | ||
[WindowProviderRequestEnums.cancelAction]: | ||
WindowProviderResponseEnums.cancelResponse, | ||
[WindowProviderRequestEnums.finalizeHandshakeRequest]: | ||
WindowProviderResponseEnums.noneResponse, | ||
[WindowProviderRequestEnums.finalizeResetStateRequest]: | ||
WindowProviderResponseEnums.resetStateResponse, | ||
}; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./crossWindowProviderEnums"; | ||
export * from "./windowProviderEnums"; | ||
export * from "./signMessageStatusEnum"; |
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,6 @@ | ||
export enum SignMessageStatusEnum { | ||
pending = "pending", | ||
failed = "failed", | ||
signed = "signed", | ||
cancelled = "cancelled", | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from "./crossWindowProviderTypes"; | ||
export * from "./windowProviderTypes"; | ||
export * from "./nullable"; |
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,107 @@ | ||
import { | ||
WindowProviderRequestEnums, | ||
WindowProviderResponseEnums, | ||
SignMessageStatusEnum, | ||
} from "../enums"; | ||
import type { IPlainTransactionObject } from "@multiversx/sdk-core"; | ||
|
||
export type ReplyWithPostMessageObjectType = { | ||
[WindowProviderResponseEnums.handshakeResponse]: boolean; | ||
[WindowProviderResponseEnums.loginResponse]: { | ||
address: string; | ||
accessToken?: string; | ||
/** | ||
* used in De-Fi wallet extension as wallet name | ||
* */ | ||
name?: string; | ||
signature?: string; | ||
/** | ||
* contract address for alternate multisig login | ||
* */ | ||
multisig?: string; | ||
/** | ||
* custom address for alternate login | ||
* */ | ||
impersonate?: string; | ||
}; | ||
[WindowProviderResponseEnums.disconnectResponse]: boolean; | ||
[WindowProviderResponseEnums.cancelResponse]: { | ||
address: string; | ||
}; | ||
[WindowProviderResponseEnums.signTransactionsResponse]: IPlainTransactionObject[]; | ||
[WindowProviderResponseEnums.guardTransactionsResponse]: IPlainTransactionObject[]; | ||
[WindowProviderResponseEnums.signMessageResponse]: { | ||
signature?: string; | ||
status: SignMessageStatusEnum; | ||
}; | ||
[WindowProviderResponseEnums.noneResponse]: null; | ||
[WindowProviderResponseEnums.resetStateResponse]: boolean; | ||
}; | ||
|
||
export type ReplyWithPostMessagePayloadType< | ||
K extends keyof ReplyWithPostMessageObjectType | ||
> = { | ||
data?: ReplyWithPostMessageObjectType[K]; | ||
error?: string; | ||
}; | ||
|
||
export type ReplyWithPostMessageType = { | ||
[K in keyof ReplyWithPostMessageObjectType]: { | ||
type: K; | ||
payload: ReplyWithPostMessagePayloadType<K>; | ||
}; | ||
}[keyof ReplyWithPostMessageObjectType]; | ||
|
||
export type ResponseTypeMap = { | ||
[WindowProviderRequestEnums.signTransactionsRequest]: WindowProviderResponseEnums.signTransactionsResponse; | ||
[WindowProviderRequestEnums.signMessageRequest]: WindowProviderResponseEnums.signMessageResponse; | ||
[WindowProviderRequestEnums.loginRequest]: WindowProviderResponseEnums.loginResponse; | ||
[WindowProviderRequestEnums.logoutRequest]: WindowProviderResponseEnums.disconnectResponse; | ||
[WindowProviderRequestEnums.guardTransactionsRequest]: WindowProviderResponseEnums.guardTransactionsResponse; | ||
[WindowProviderRequestEnums.cancelAction]: WindowProviderResponseEnums.cancelResponse; | ||
[WindowProviderRequestEnums.finalizeHandshakeRequest]: WindowProviderResponseEnums.noneResponse; | ||
[WindowProviderRequestEnums.finalizeResetStateRequest]: WindowProviderResponseEnums.resetStateResponse; | ||
}; | ||
|
||
export type RequestPayloadType = { | ||
[WindowProviderRequestEnums.loginRequest]: { | ||
token: string | undefined; | ||
}; | ||
[WindowProviderRequestEnums.logoutRequest]: undefined; | ||
[WindowProviderRequestEnums.signTransactionsRequest]: IPlainTransactionObject[]; | ||
[WindowProviderRequestEnums.guardTransactionsRequest]: IPlainTransactionObject[]; | ||
[WindowProviderRequestEnums.signMessageRequest]: { | ||
message: string; | ||
}; | ||
[WindowProviderRequestEnums.cancelAction]: undefined; | ||
[WindowProviderRequestEnums.finalizeHandshakeRequest]: undefined; | ||
[WindowProviderRequestEnums.finalizeResetStateRequest]: undefined; | ||
}; | ||
|
||
export type RequestMessageType = { | ||
[K in keyof RequestPayloadType]: { | ||
type: K; | ||
payload: RequestPayloadType[K]; | ||
}; | ||
}[keyof RequestPayloadType]; | ||
|
||
export type ReplyWithPostMessageEventType = { | ||
[K in keyof ReplyWithPostMessageObjectType]: { | ||
type: WindowProviderResponseEnums; | ||
payload: ReplyWithPostMessageObjectType[K]; | ||
}; | ||
}[keyof ReplyWithPostMessageObjectType]; | ||
|
||
export interface PostMessageParamsType< | ||
T extends WindowProviderRequestEnums | ||
> { | ||
type: T; | ||
payload: RequestPayloadType[keyof RequestPayloadType]; | ||
} | ||
|
||
export interface PostMessageReturnType< | ||
T extends WindowProviderRequestEnums | ||
> { | ||
type: ResponseTypeMap[T] | WindowProviderResponseEnums.cancelResponse; | ||
payload: ReplyWithPostMessagePayloadType<ResponseTypeMap[T]>; | ||
} |