1
- import {
2
- type WalletComponents ,
3
- startUserSessionViaLauncher ,
4
- } from "@treasure-dev/launcher" ;
1
+ import { startUserSessionViaLauncher } from "@treasure-dev/launcher" ;
5
2
import {
6
3
AnalyticsManager ,
7
4
DEFAULT_TDK_API_BASE_URI ,
@@ -42,6 +39,7 @@ import {
42
39
import { isZkSyncChain } from "thirdweb/utils" ;
43
40
import { type Wallet , ecosystemWallet } from "thirdweb/wallets" ;
44
41
42
+ import type { AuthStoredTokenWithCookieReturnType } from "thirdweb/dist/types/wallets/in-app/core/authentication/types" ;
45
43
import { useLauncher } from "../hooks/useLauncher" ;
46
44
import { i18n } from "../i18n" ;
47
45
import type { AnalyticsEvent , Config , ContextValues } from "../types" ;
@@ -71,6 +69,8 @@ export const useTreasure = () => {
71
69
72
70
type Props = PropsWithChildren < Config > ;
73
71
72
+ let hasSetUrlParams = false ;
73
+
74
74
const TreasureProviderInner = ( {
75
75
children,
76
76
appName,
@@ -195,26 +195,43 @@ const TreasureProviderInner = ({
195
195
) ;
196
196
197
197
const onWalletComponentsUpdated = useCallback (
198
- ( walletComponents : WalletComponents ) => {
198
+ async (
199
+ authResult : AuthStoredTokenWithCookieReturnType ,
200
+ authProvider : string ,
201
+ walletId : string ,
202
+ authCookie : string ,
203
+ ) => {
199
204
if ( activeWallet ) {
200
205
console . debug (
201
206
"[TreasureProvider] There is already an active wallet, skipping updating with launcher wallet components" ,
202
207
) ;
203
208
return ;
204
209
}
210
+ if ( hasSetUrlParams ) {
211
+ return ;
212
+ }
213
+ hasSetUrlParams = true ;
205
214
console . debug (
206
215
"[TreasureProvider] Updating wallet with launcher wallet components" ,
207
216
) ;
217
+
218
+ authResult . storedToken . cookieString = authCookie ;
219
+ const encoded = encodeURIComponent ( JSON . stringify ( authResult ) ) ;
208
220
const url = new URL ( window . location . href ) ;
209
- url . searchParams . set ( "walletId" , walletComponents . walletId ) ;
210
- url . searchParams . set ( "authProvider" , walletComponents . authProvider ) ;
211
- url . searchParams . set ( "authCookie" , walletComponents . authCookie ) ;
212
- window . history . pushState ( { } , "" , url ) ;
221
+ url . searchParams . set ( "authResult" , encoded ) ;
222
+ url . searchParams . set ( "authProvider" , authProvider ) ;
223
+ url . searchParams . set ( "walletId" , walletId ) ;
224
+ url . searchParams . set ( "authCookie" , authCookie ) ;
225
+ window . history . pushState ( { } , "" , url . toString ( ) ) ;
213
226
} ,
214
227
[ activeWallet ] ,
215
228
) ;
216
229
217
- const { isUsingTreasureLauncher, openLauncherAccountModal } = useLauncher ( {
230
+ const {
231
+ isUsingTreasureLauncher,
232
+ isUsingLauncherAuthToken,
233
+ openLauncherAccountModal,
234
+ } = useLauncher ( {
218
235
getAuthTokenOverride : launcherOptions ?. getAuthTokenOverride ,
219
236
getWalletComponentsOverride : launcherOptions ?. getWalletComponentsOverride ,
220
237
setRootElement : setEl ,
@@ -228,6 +245,7 @@ const TreasureProviderInner = ({
228
245
name : EVT_TREASURECONNECT_DISCONNECTED ,
229
246
properties : {
230
247
isUsingTreasureLauncher,
248
+ isUsingLauncherAuthToken,
231
249
} ,
232
250
} )
233
251
. then ( ( eventId ) => {
@@ -248,7 +266,7 @@ const TreasureProviderInner = ({
248
266
chainId ?: number ,
249
267
skipCurrentUser = false ,
250
268
) : Promise < { user : User | undefined ; legacyProfiles : LegacyProfile [ ] } > => {
251
- if ( isUsingTreasureLauncher ) {
269
+ if ( isUsingLauncherAuthToken ) {
252
270
console . debug (
253
271
"[TreasureProvider] Skipping login because launcher is being used" ,
254
272
) ;
@@ -345,6 +363,7 @@ const TreasureProviderInner = ({
345
363
name : EVT_TREASURECONNECT_CONNECTED ,
346
364
properties : {
347
365
isUsingTreasureLauncher,
366
+ isUsingLauncherAuthToken,
348
367
} ,
349
368
} )
350
369
. then ( ( eventId ) => {
@@ -409,6 +428,7 @@ const TreasureProviderInner = ({
409
428
userAddress : undefined ,
410
429
} ) ,
411
430
isUsingTreasureLauncher,
431
+ isUsingLauncherAuthToken,
412
432
logIn,
413
433
logOut,
414
434
updateUser : ( partialUser ) =>
0 commit comments