-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a9771e
commit 59aa057
Showing
8 changed files
with
215 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { ExternalMethods, LegacyMessageFromContentScript } from '@shared/message-types'; | ||
import { RouteUrls } from '@shared/route-urls'; | ||
import { StorageKey, storePayload } from '@shared/utils/storage'; | ||
import { popupCenter } from './popup-center'; | ||
|
||
const IS_TEST_ENV = process.env.TEST_ENV === 'true'; | ||
|
||
// | ||
// Playwright does not currently support Chrome extension popup testing: | ||
// https://github.com/microsoft/playwright/issues/5593 | ||
async function openRequestInFullPage(path: string, urlParams: URLSearchParams) { | ||
await chrome.tabs.create({ | ||
url: chrome.runtime.getURL(`index.html#${path}?${urlParams.toString()}`), | ||
}); | ||
} | ||
|
||
export function inferLegacyMessage(message: any): message is LegacyMessageFromContentScript { | ||
// Now that we use a RPC communication style, we can infer | ||
// legacy message types by presence of an id | ||
return !Object.hasOwn(message, 'id'); | ||
} | ||
|
||
export async function handleLegacyExternalMethodFormat( | ||
message: LegacyMessageFromContentScript, | ||
port: chrome.runtime.Port | ||
) { | ||
switch (message.method) { | ||
case ExternalMethods.authenticationRequest: { | ||
const { payload } = message; | ||
void storePayload({ | ||
payload, | ||
storageKey: StorageKey.authenticationRequests, | ||
port, | ||
}); | ||
const path = RouteUrls.Onboarding; | ||
const urlParams = new URLSearchParams(); | ||
urlParams.set('authRequest', payload); | ||
if (IS_TEST_ENV) { | ||
await openRequestInFullPage(path, urlParams); | ||
} else { | ||
popupCenter({ url: `/popup-center.html#${path}?${urlParams.toString()}` }); | ||
} | ||
break; | ||
} | ||
case ExternalMethods.transactionRequest: { | ||
const { payload } = message; | ||
|
||
void storePayload({ | ||
payload, | ||
storageKey: StorageKey.transactionRequests, | ||
port, | ||
}); | ||
const path = RouteUrls.TransactionRequest; | ||
const urlParams = new URLSearchParams(); | ||
urlParams.set('request', payload); | ||
if (IS_TEST_ENV) { | ||
await openRequestInFullPage(path, urlParams); | ||
} else { | ||
popupCenter({ url: `/popup-center.html#${path}?${urlParams.toString()}` }); | ||
} | ||
break; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.