@@ -4,10 +4,7 @@ import { type Address } from 'viem'
44import { z } from 'zod'
55
66import type { AuthContext } from '@/middleware/auth.js'
7- import type {
8- CreateWalletResponse ,
9- GetWalletResponse ,
10- } from '@/types/service.js'
7+ import type { GetWalletResponse } from '@/types/service.js'
118
129import { validateRequest } from '../helpers/validation.js'
1310import * as walletService from '../services/wallet.js'
@@ -23,63 +20,31 @@ const LendPositionRequestSchema = z.object({
2320} )
2421
2522export class WalletController {
26- /**
27- * POST - Create a new wallet for a user
28- */
29- async createWallet ( c : Context ) {
30- try {
31- const auth = c . get ( 'auth' ) as AuthContext | undefined
32-
33- if ( ! auth || ! auth . userId ) {
34- return c . json ( { error : 'Unauthorized' } , 401 )
35- }
36-
37- const { privyAddress, smartWalletAddress } =
38- await walletService . createWallet ( )
39-
40- return c . json ( {
41- privyAddress,
42- smartWalletAddress,
43- userId : auth . userId ,
44- } satisfies CreateWalletResponse )
45- } catch ( error ) {
46- console . error ( error )
47- return c . json (
48- {
49- error : 'Failed to create wallet' ,
50- message : error instanceof Error ? error . message : 'Unknown error' ,
51- } ,
52- 500 ,
53- )
54- }
55- }
56-
5723 /**
5824 * GET - Retrieve wallet information by user ID
5925 */
6026 async getWallet ( c : Context ) {
6127 try {
6228 const auth = c . get ( 'auth' ) as AuthContext | undefined
6329
64- if ( ! auth || ! auth . userId ) {
30+ if ( ! auth || ! auth . idToken ) {
6531 return c . json ( { error : 'Unauthorized' } , 401 )
6632 }
6733
68- const wallet = await walletService . getWallet ( auth . userId )
34+ const wallet = await walletService . getWallet ( auth . idToken )
6935
7036 if ( ! wallet ) {
7137 return c . json (
7238 {
7339 error : 'Wallet not found' ,
74- message : `No wallet found for user ${ auth . userId } ` ,
40+ message : `No wallet found for user` ,
7541 } ,
7642 404 ,
7743 )
7844 }
7945
8046 return c . json ( {
8147 address : wallet . address ,
82- userId : auth . userId ,
8348 } satisfies GetWalletResponse )
8449 } catch ( error ) {
8550 console . error ( error )
@@ -100,11 +65,11 @@ export class WalletController {
10065 try {
10166 const auth = c . get ( 'auth' ) as AuthContext | undefined
10267
103- if ( ! auth || ! auth . userId ) {
68+ if ( ! auth || ! auth . idToken ) {
10469 return c . json ( { error : 'Unauthorized' } , 401 )
10570 }
10671
107- const wallet = await walletService . getWallet ( auth . userId )
72+ const wallet = await walletService . getWallet ( auth . idToken )
10873 if ( ! wallet ) {
10974 throw new Error ( 'Wallet not found' )
11075 }
@@ -138,11 +103,11 @@ export class WalletController {
138103
139104 const auth = c . get ( 'auth' ) as AuthContext | undefined
140105
141- if ( ! auth || ! auth . userId ) {
106+ if ( ! auth || ! auth . idToken ) {
142107 return c . json ( { error : 'Unauthorized' } , 401 )
143108 }
144109
145- const wallet = await walletService . getWallet ( auth . userId )
110+ const wallet = await walletService . getWallet ( auth . idToken )
146111 if ( ! wallet ) {
147112 throw new Error ( 'Wallet not found' )
148113 }
@@ -156,11 +121,11 @@ export class WalletController {
156121 async fundWallet ( c : Context ) {
157122 try {
158123 const auth = c . get ( 'auth' ) as AuthContext | undefined
159- if ( ! auth || ! auth . userId ) {
124+ if ( ! auth || ! auth . idToken ) {
160125 return c . json ( { error : 'Unauthorized' } , 401 )
161126 }
162127
163- const wallet = await walletService . getWallet ( auth . userId )
128+ const wallet = await walletService . getWallet ( auth . idToken )
164129 if ( ! wallet ) {
165130 throw new Error ( 'Wallet not found' )
166131 }
0 commit comments