-
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.
Support
NotLoggedIn
status on connection page (#787)
* Support NotLoggedIn status * use toasts * popup flow, error reasons, standardized penumbra failure reason * style updates --------- Co-authored-by: turbocrime <turbocrime@users.noreply.github.com>
- Loading branch information
1 parent
19f17f9
commit 7a1efed
Showing
18 changed files
with
277 additions
and
188 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@penumbra-zone/client': major | ||
--- | ||
|
||
isPraxInstalled -> isPraxAvailable renaming |
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 @@ | ||
--- | ||
'@penumbra-zone/ui': minor | ||
--- | ||
|
||
Added warning toast |
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
8 changes: 4 additions & 4 deletions
8
apps/extension/src/content-scripts/injected-connection-port.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
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
23 changes: 16 additions & 7 deletions
23
apps/extension/src/content-scripts/injected-request-listener.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 |
---|---|---|
@@ -1,15 +1,24 @@ | ||
import { isPraxRequestConnectionMessageEvent } from './message'; | ||
import { Prax } from '../message/prax'; | ||
import { PraxMessage, isPraxRequestMessageEvent } from './message-event'; | ||
import { PraxConnection } from '../message/prax'; | ||
|
||
const handleRequest = (ev: MessageEvent<unknown>) => { | ||
if (isPraxRequestConnectionMessageEvent(ev) && ev.origin === window.origin) | ||
if (ev.origin === window.origin && isPraxRequestMessageEvent(ev)) { | ||
void (async () => { | ||
window.removeEventListener('message', handleRequest); | ||
const result = await chrome.runtime.sendMessage< | ||
Prax.RequestConnection, | ||
Prax.ApprovedConnection | Prax.DeniedConnection | ||
>(Prax.RequestConnection); | ||
window.postMessage({ [PRAX]: result }, '/'); | ||
PraxConnection, | ||
Exclude<PraxConnection, PraxConnection.Request> | ||
>(PraxConnection.Request); | ||
// init is handled by injected-connection-port | ||
if (result !== PraxConnection.Init) | ||
window.postMessage( | ||
{ [PRAX]: result } satisfies PraxMessage< | ||
PraxConnection.Denied | PraxConnection.NeedsLogin | ||
>, | ||
'/', | ||
); | ||
})(); | ||
} | ||
}; | ||
|
||
window.addEventListener('message', handleRequest); |
25 changes: 12 additions & 13 deletions
25
.../extension/src/content-scripts/message.ts → ...sion/src/content-scripts/message-event.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 |
---|---|---|
@@ -1,33 +1,32 @@ | ||
import { Prax } from '../message/prax'; | ||
import { PraxConnection } from '../message/prax'; | ||
|
||
// @ts-expect-error - ts can't understand the injected string | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export type PraxMessage<T = unknown> = { [PRAX]: T }; | ||
|
||
export type PraxRequestConnection = PraxMessage<Prax.RequestConnection>; | ||
export type PraxConnectionPort = PraxMessage<MessagePort>; | ||
|
||
export const isPraxMessageEvent = (ev: MessageEvent<unknown>): ev is MessageEvent<PraxMessage> => | ||
isPraxMessageEventData(ev.data); | ||
|
||
const isPraxMessageEventData = (p: unknown): p is PraxMessage => | ||
typeof p === 'object' && p != null && PRAX in p; | ||
|
||
export const isPraxRequestConnectionMessageEvent = ( | ||
export const isPraxRequestMessageEvent = ( | ||
ev: MessageEvent<unknown>, | ||
): ev is MessageEvent<PraxRequestConnection> => | ||
): ev is MessageEvent<PraxMessage<PraxConnection.Request>> => | ||
// @ts-expect-error - ts can't understand the injected string | ||
isPraxMessageEventData(ev.data) && ev.data[PRAX] === Prax.RequestConnection; | ||
isPraxMessageEventData(ev.data) && ev.data[PRAX] === PraxConnection.Request; | ||
|
||
export const isPraxRequestResponseMessageEvent = ( | ||
export const isPraxFailureMessageEvent = ( | ||
ev: MessageEvent<unknown>, | ||
): ev is MessageEvent<Prax.ApprovedConnection | Prax.DeniedConnection> => | ||
isPraxMessageEventData(ev.data) && | ||
): ev is MessageEvent<PraxMessage<PraxConnection.Denied | PraxConnection.NeedsLogin>> => { | ||
if (!isPraxMessageEventData(ev.data)) return false; | ||
// @ts-expect-error - ts can't understand the injected string | ||
(ev.data[PRAX] === Prax.ApprovedConnection || ev.data[PRAX] === Prax.DeniedConnection); | ||
const status = ev.data[PRAX] as unknown; | ||
return status === PraxConnection.Denied || status === PraxConnection.NeedsLogin; | ||
}; | ||
|
||
export const isPraxConnectionPortMessageEvent = ( | ||
export const isPraxPortMessageEvent = ( | ||
ev: MessageEvent<unknown>, | ||
): ev is MessageEvent<PraxConnectionPort> => | ||
): ev is MessageEvent<PraxMessage<MessagePort>> => | ||
// @ts-expect-error - ts can't understand the injected string | ||
isPraxMessageEventData(ev.data) && ev.data[PRAX] instanceof MessagePort; |
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
Oops, something went wrong.