1
1
import type { UserProfile } from "@prisma/client" ;
2
- import type { GetUserResult } from "thirdweb" ;
2
+ import {
3
+ DEFAULT_TDK_ECOSYSTEM_ID ,
4
+ type EcosystemIdString ,
5
+ } from "@treasure-dev/tdk-core" ;
6
+ import { type GetUserResult , type ThirdwebClient , getUser } from "thirdweb" ;
7
+
8
+ import { log } from "./log" ;
3
9
4
10
export const transformUserProfileResponseFields = (
5
11
profile : Partial < UserProfile > ,
@@ -12,6 +18,51 @@ export const transformUserProfileResponseFields = (
12
18
profile . testnetFaucetLastUsedAt ?. toISOString ( ) ?? null ,
13
19
} ) ;
14
20
21
+ export const getThirdwebUser = async ( {
22
+ client,
23
+ ecosystemId = DEFAULT_TDK_ECOSYSTEM_ID ,
24
+ ecosystemPartnerId,
25
+ walletAddress,
26
+ } : {
27
+ client : ThirdwebClient ;
28
+ ecosystemId ?: EcosystemIdString ;
29
+ ecosystemPartnerId : string ;
30
+ walletAddress : string ;
31
+ } ) => {
32
+ try {
33
+ const ecosystemWalletUser = await getUser ( {
34
+ client,
35
+ ecosystem : {
36
+ id : ecosystemId ,
37
+ partnerId : ecosystemPartnerId ,
38
+ } ,
39
+ walletAddress,
40
+ } ) ;
41
+ if ( ecosystemWalletUser ) {
42
+ return ecosystemWalletUser ;
43
+ }
44
+ } catch ( err ) {
45
+ // Ignore failures from the Thirdweb SDK, this info is "nice-to-have"
46
+ log . warn ( "Error fetching Thirdweb ecosystem wallets user:" , err ) ;
47
+ }
48
+
49
+ // Fall back to querying in-app wallets (no ecosystem ID)
50
+ try {
51
+ const inAppWalletUser = await getUser ( {
52
+ client,
53
+ walletAddress,
54
+ } ) ;
55
+ if ( inAppWalletUser ) {
56
+ return inAppWalletUser ;
57
+ }
58
+ } catch ( err ) {
59
+ // Ignore failures from the Thirdweb SDK, this info is "nice-to-have"
60
+ log . warn ( "Error fetching Thirdweb in-app wallets user:" , err ) ;
61
+ }
62
+
63
+ return undefined ;
64
+ } ;
65
+
15
66
export const parseThirdwebUserEmail = ( user : GetUserResult ) => {
16
67
if ( user . email ) {
17
68
return user . email ;
0 commit comments