-
Notifications
You must be signed in to change notification settings - Fork 629
Winston/tool 3161 cannot create backend wallets using latest version #6025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joaquim-verges
merged 4 commits into
main
from
winston/tool-3161-cannot-create-backend-wallets-using-latest-version
Jan 24, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| --- | ||
| "thirdweb": patch | ||
| --- | ||
|
|
||
| fix (in app wallets): error when calling connect for backend strategy due to `document` reference |
This file contains hidden or 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 hidden or 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
102 changes: 102 additions & 0 deletions
102
...ges/thirdweb/src/wallets/in-app/web/utils/iFrameCommunication/IframeCommunicator.test.tsx
This file contains hidden or 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,102 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { IframeCommunicator } from "./IframeCommunicator.js"; | ||
|
|
||
| describe("IframeCommunicator", () => { | ||
| // biome-ignore lint/suspicious/noExplicitAny: mock | ||
| let mockLocalStorage: any; | ||
| let mockContainer: HTMLElement; | ||
| let mockIframe: HTMLIFrameElement; | ||
|
|
||
| beforeEach(() => { | ||
| // Mock localStorage | ||
| vi.restoreAllMocks(); | ||
|
|
||
| mockLocalStorage = { | ||
| getAuthCookie: vi.fn().mockResolvedValue("mockAuthCookie"), | ||
| getDeviceShare: vi.fn().mockResolvedValue("mockDeviceShare"), | ||
| getWalletUserId: vi.fn().mockResolvedValue("mockWalletUserId"), | ||
| }; | ||
| // Mock DOM elements | ||
| mockContainer = document.createElement("div"); | ||
| mockIframe = document.createElement("iframe"); | ||
| vi.spyOn(document, "createElement").mockReturnValue(mockIframe); | ||
| vi.spyOn(document, "getElementById").mockReturnValue(null); | ||
| }); | ||
|
|
||
| it("should create an iframe with correct properties", () => { | ||
| new IframeCommunicator({ | ||
| link: "https://example.com", | ||
| baseUrl: "https://example.com", | ||
| iframeId: "test-iframe", | ||
| container: mockContainer, | ||
| localStorage: mockLocalStorage, | ||
| clientId: "test-client", | ||
| }); | ||
|
|
||
| expect(document.createElement).toHaveBeenCalledWith("iframe"); | ||
| expect(mockIframe.id).toBe("test-iframe"); | ||
| expect(mockIframe.src).toBe("https://example.com/"); | ||
| expect(mockIframe.style.display).toBe("none"); | ||
| }); | ||
|
|
||
| it("should initialize with correct variables", async () => { | ||
| const communicator = new IframeCommunicator({ | ||
| link: "https://example.com", | ||
| baseUrl: "https://example.com", | ||
| iframeId: "test-iframe", | ||
| container: mockContainer, | ||
| localStorage: mockLocalStorage, | ||
| clientId: "test-client", | ||
| }); | ||
|
|
||
| // biome-ignore lint/complexity/useLiteralKeys: accessing protected method | ||
| const vars = await communicator["onIframeLoadedInitVariables"](); | ||
|
|
||
| expect(vars).toEqual({ | ||
| authCookie: "mockAuthCookie", | ||
| deviceShareStored: "mockDeviceShare", | ||
| walletUserId: "mockWalletUserId", | ||
| clientId: "test-client", | ||
| partnerId: undefined, | ||
| ecosystemId: undefined, | ||
| }); | ||
| }); | ||
|
|
||
| it("should throw error when calling methods without iframe", async () => { | ||
| const temp = global.document; | ||
| // @ts-expect-error - Testing undefined document scenario | ||
| global.document = undefined; | ||
|
|
||
| const communicator = new IframeCommunicator({ | ||
| link: "https://example.com", | ||
| baseUrl: "https://example.com", | ||
| iframeId: "test-iframe", | ||
| localStorage: mockLocalStorage, | ||
| clientId: "test-client", | ||
| }); | ||
|
|
||
| await expect( | ||
| communicator.call({ | ||
| procedureName: "test", | ||
| params: {}, | ||
| }), | ||
| ).rejects.toThrow("Iframe not found"); | ||
| global.document = temp; | ||
| }); | ||
|
|
||
| it("should cleanup on destroy", () => { | ||
| const communicator = new IframeCommunicator({ | ||
| link: "https://example.com", | ||
| baseUrl: "https://example.com", | ||
| iframeId: "test-iframe", | ||
| container: mockContainer, | ||
| localStorage: mockLocalStorage, | ||
| clientId: "test-client", | ||
| }); | ||
|
|
||
| communicator.destroy(); | ||
|
|
||
| // biome-ignore lint/complexity/useLiteralKeys: accessing protected field | ||
| expect(communicator["iframe"]).toBeDefined(); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can this ever go through iframe auth? shouldnt it always do the enclave flow?