thirdweb 5.118.0 → 5.118.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/in-app/web/lib/get-url-token.js +41 -8
- package/dist/cjs/wallets/in-app/web/lib/get-url-token.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/in-app/web/lib/get-url-token.js +41 -8
- package/dist/esm/wallets/in-app/web/lib/get-url-token.js.map +1 -1
- package/dist/scripts/bridge-widget.js +3 -3
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/in-app/web/lib/get-url-token.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/react/web/ui/SiteLink.test.tsx +21 -0
- package/src/version.ts +1 -1
- package/src/wallets/in-app/web/lib/get-url-token.test.tsx +63 -7
- package/src/wallets/in-app/web/lib/get-url-token.ts +47 -8
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "5.118.
|
|
1
|
+
export declare const version = "5.118.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-url-token.d.ts","sourceRoot":"","sources":["../../../../../../src/wallets/in-app/web/lib/get-url-token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,oCAAoC,CAAC;AAE9F;;GAEG;AACH,wBAAgB,WAAW,IACvB;IACE,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,mCAAmC,CAAC;IACjD,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;CAC/B,GACD,SAAS,
|
|
1
|
+
{"version":3,"file":"get-url-token.d.ts","sourceRoot":"","sources":["../../../../../../src/wallets/in-app/web/lib/get-url-token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,oCAAoC,CAAC;AAE9F;;GAEG;AACH,wBAAgB,WAAW,IACvB;IACE,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,mCAAmC,CAAC;IACjD,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;CAC/B,GACD,SAAS,CAwEZ"}
|
package/package.json
CHANGED
|
@@ -62,4 +62,25 @@ describe("SiteLink", () => {
|
|
|
62
62
|
expect(anchor).toBeTruthy();
|
|
63
63
|
await waitFor(() => expect(anchor?.href).toContain("walletId=inApp"));
|
|
64
64
|
});
|
|
65
|
+
|
|
66
|
+
it("preserves hash fragment for hash-routed URLs", async () => {
|
|
67
|
+
const testUrl = "https://snapshot.org/#/s:wampei.eth";
|
|
68
|
+
const { container } = render(
|
|
69
|
+
<SiteLink client={TEST_CLIENT} href={testUrl}>
|
|
70
|
+
Test Link
|
|
71
|
+
</SiteLink>,
|
|
72
|
+
{
|
|
73
|
+
setConnectedWallet: true,
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const anchor = container.querySelector("a");
|
|
78
|
+
expect(anchor).toBeTruthy();
|
|
79
|
+
await waitFor(() => {
|
|
80
|
+
const href = anchor?.href ?? "";
|
|
81
|
+
// Hash fragment must be preserved in the URL
|
|
82
|
+
expect(href).toContain("#/s:wampei.eth");
|
|
83
|
+
expect(href).toContain("walletId=");
|
|
84
|
+
});
|
|
85
|
+
});
|
|
65
86
|
});
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "5.118.
|
|
1
|
+
export const version = "5.118.1";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
2
|
import { getUrlToken } from "./get-url-token.js";
|
|
3
3
|
|
|
4
4
|
describe.runIf(global.window !== undefined)("getUrlToken", () => {
|
|
@@ -48,9 +48,9 @@ describe.runIf(global.window !== undefined)("getUrlToken", () => {
|
|
|
48
48
|
const result = getUrlToken();
|
|
49
49
|
|
|
50
50
|
expect(result).toEqual({
|
|
51
|
-
authCookie:
|
|
52
|
-
authFlow:
|
|
53
|
-
authProvider:
|
|
51
|
+
authCookie: undefined,
|
|
52
|
+
authFlow: undefined,
|
|
53
|
+
authProvider: undefined,
|
|
54
54
|
authResult: { token: "abc" },
|
|
55
55
|
walletId: "123",
|
|
56
56
|
});
|
|
@@ -63,8 +63,8 @@ describe.runIf(global.window !== undefined)("getUrlToken", () => {
|
|
|
63
63
|
|
|
64
64
|
expect(result).toEqual({
|
|
65
65
|
authCookie: "myCookie",
|
|
66
|
-
authFlow:
|
|
67
|
-
authProvider:
|
|
66
|
+
authFlow: undefined,
|
|
67
|
+
authProvider: undefined,
|
|
68
68
|
authResult: undefined,
|
|
69
69
|
walletId: "123",
|
|
70
70
|
});
|
|
@@ -81,7 +81,7 @@ describe.runIf(global.window !== undefined)("getUrlToken", () => {
|
|
|
81
81
|
|
|
82
82
|
expect(result).toEqual({
|
|
83
83
|
authCookie: "myCookie",
|
|
84
|
-
authFlow:
|
|
84
|
+
authFlow: undefined,
|
|
85
85
|
authProvider: "provider1",
|
|
86
86
|
authResult: { token: "xyz" },
|
|
87
87
|
walletId: "123",
|
|
@@ -92,4 +92,60 @@ describe.runIf(global.window !== undefined)("getUrlToken", () => {
|
|
|
92
92
|
"?walletId=123&authResult=%7B%22token%22%3A%22xyz%22%7D&authProvider=provider1&authCookie=myCookie",
|
|
93
93
|
);
|
|
94
94
|
});
|
|
95
|
+
|
|
96
|
+
it("should preserve hash fragment when cleaning up URL", () => {
|
|
97
|
+
Object.defineProperty(window, "location", {
|
|
98
|
+
value: {
|
|
99
|
+
...window.location,
|
|
100
|
+
search: "?walletId=123&authCookie=myCookie",
|
|
101
|
+
hash: "#/s:wampei.eth",
|
|
102
|
+
pathname: "/",
|
|
103
|
+
},
|
|
104
|
+
writable: true,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const pushStateSpy = vi.spyOn(window.history, "pushState");
|
|
108
|
+
|
|
109
|
+
const result = getUrlToken();
|
|
110
|
+
|
|
111
|
+
expect(result).toEqual({
|
|
112
|
+
authCookie: "myCookie",
|
|
113
|
+
authFlow: undefined,
|
|
114
|
+
authProvider: undefined,
|
|
115
|
+
authResult: undefined,
|
|
116
|
+
walletId: "123",
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Verify pushState was called with the hash preserved
|
|
120
|
+
expect(pushStateSpy).toHaveBeenCalledWith({}, "", "/#/s:wampei.eth");
|
|
121
|
+
pushStateSpy.mockRestore();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should parse auth params embedded inside the hash fragment", () => {
|
|
125
|
+
Object.defineProperty(window, "location", {
|
|
126
|
+
value: {
|
|
127
|
+
...window.location,
|
|
128
|
+
search: "",
|
|
129
|
+
hash: "#/s:wampei.eth?walletId=123&authCookie=myCookie",
|
|
130
|
+
pathname: "/",
|
|
131
|
+
},
|
|
132
|
+
writable: true,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const pushStateSpy = vi.spyOn(window.history, "pushState");
|
|
136
|
+
|
|
137
|
+
const result = getUrlToken();
|
|
138
|
+
|
|
139
|
+
expect(result).toEqual({
|
|
140
|
+
authCookie: "myCookie",
|
|
141
|
+
authFlow: undefined,
|
|
142
|
+
authProvider: undefined,
|
|
143
|
+
authResult: undefined,
|
|
144
|
+
walletId: "123",
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Verify pushState preserves hash path but strips auth params from it
|
|
148
|
+
expect(pushStateSpy).toHaveBeenCalledWith({}, "", "/#/s:wampei.eth");
|
|
149
|
+
pushStateSpy.mockRestore();
|
|
150
|
+
});
|
|
95
151
|
});
|
|
@@ -19,18 +19,40 @@ export function getUrlToken():
|
|
|
19
19
|
return undefined;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
const params = new URLSearchParams(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
22
|
+
// Read params from the standard query string
|
|
23
|
+
const params = new URLSearchParams(window.location.search);
|
|
24
|
+
|
|
25
|
+
// Also check for params embedded inside the hash fragment (e.g. #/route?walletId=...)
|
|
26
|
+
// This supports hash-routed apps where params may be placed after the hash path
|
|
27
|
+
let hashParams: URLSearchParams | undefined;
|
|
28
|
+
const hash = window.location.hash || "";
|
|
29
|
+
let cleanHash = hash;
|
|
30
|
+
const hashQueryIndex = hash.indexOf("?");
|
|
31
|
+
if (hashQueryIndex !== -1) {
|
|
32
|
+
hashParams = new URLSearchParams(hash.substring(hashQueryIndex));
|
|
33
|
+
cleanHash = hash.substring(0, hashQueryIndex);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const walletId = (params.get("walletId") ??
|
|
37
|
+
hashParams?.get("walletId") ??
|
|
38
|
+
undefined) as WalletId | undefined;
|
|
39
|
+
const authResultString =
|
|
40
|
+
params.get("authResult") ?? hashParams?.get("authResult") ?? undefined;
|
|
41
|
+
const authProvider = (params.get("authProvider") ??
|
|
42
|
+
hashParams?.get("authProvider") ??
|
|
43
|
+
undefined) as AuthOption | undefined;
|
|
44
|
+
const authCookie = (params.get("authCookie") ??
|
|
45
|
+
hashParams?.get("authCookie") ??
|
|
46
|
+
undefined) as string | undefined;
|
|
47
|
+
const authFlow = (params.get("authFlow") ??
|
|
48
|
+
hashParams?.get("authFlow") ??
|
|
49
|
+
undefined) as "connect" | "link" | undefined;
|
|
29
50
|
|
|
30
51
|
if ((authCookie || authResultString) && walletId) {
|
|
31
52
|
const authResult = (() => {
|
|
32
53
|
if (authResultString) {
|
|
33
54
|
params.delete("authResult");
|
|
55
|
+
hashParams?.delete("authResult");
|
|
34
56
|
return JSON.parse(decodeURIComponent(authResultString));
|
|
35
57
|
}
|
|
36
58
|
})();
|
|
@@ -38,10 +60,27 @@ export function getUrlToken():
|
|
|
38
60
|
params.delete("authProvider");
|
|
39
61
|
params.delete("authCookie");
|
|
40
62
|
params.delete("authFlow");
|
|
63
|
+
hashParams?.delete("walletId");
|
|
64
|
+
hashParams?.delete("authProvider");
|
|
65
|
+
hashParams?.delete("authCookie");
|
|
66
|
+
hashParams?.delete("authFlow");
|
|
67
|
+
|
|
68
|
+
const remainingSearch = params.toString();
|
|
69
|
+
const searchString = remainingSearch ? `?${remainingSearch}` : "";
|
|
70
|
+
|
|
71
|
+
// Reconstruct hash, preserving the hash path and any remaining non-auth params
|
|
72
|
+
let hashString = cleanHash;
|
|
73
|
+
if (hashParams) {
|
|
74
|
+
const remainingHashParams = hashParams.toString();
|
|
75
|
+
if (remainingHashParams) {
|
|
76
|
+
hashString = `${cleanHash}?${remainingHashParams}`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
41
80
|
window.history.pushState(
|
|
42
81
|
{},
|
|
43
82
|
"",
|
|
44
|
-
`${window.location.pathname}
|
|
83
|
+
`${window.location.pathname}${searchString}${hashString}`,
|
|
45
84
|
);
|
|
46
85
|
return { authCookie, authFlow, authProvider, authResult, walletId };
|
|
47
86
|
}
|