Skip to content

Commit

Permalink
remove address
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiet1618 committed Nov 23, 2023
1 parent 66e4acf commit e5c28aa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 55 deletions.
3 changes: 1 addition & 2 deletions src/controllers/nft.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class NftController {
constructor(private readonly nftService: NftService,
private readonly userService: UserService,
private readonly dataService: DataService,
private readonly walletService: WalletService,
) { }

@Get(":id")
Expand Down Expand Up @@ -100,7 +99,7 @@ export class NftController {
};
}
const user = await verifyAccessToken(accessToken);
const wallet = await this.walletService.findWalletById(user.id);
// check address wallet in nodes network
// check if user is owner of data in blockchain
return {
id: data.id,
Expand Down
40 changes: 0 additions & 40 deletions src/controllers/oauth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class OauthController {
constructor(
private configService: ConfigService,
private readonly userService: UserService,
private readonly walletService: WalletService,
private readonly socialUserService: SocialUserService
) {
this.oAuth2Client = new OAuth2Client(
Expand All @@ -33,37 +32,14 @@ export class OauthController {
if (!code) {
throw new BadRequestException("Missing code");
}

const { tokens } = await this.oAuth2Client.getToken(code);
const { access_token } = tokens;
const user: User = await verifyAccessToken(`Bearer ${access_token}`);
const existedUser = await this.userService.findUserById(user.id);
// const wallet: any = await gaxios({
// url: "http://localhost:3001/proxy",
// method: 'POST',
// data: {
// owner: user.email,
// idToken: tokens.id_token,
// verifier: "google"
// },
// headers: {
// 'Content-Type': 'application/json',
// },
// });
const wallet = {
data: {
ethAddress: "0x0",
privKey: "0x0"
}
}

if (!existedUser) {
await this.userService.createUser(user);
const socialUser = await this.socialUserService.createSocialUser(user.id, [], [], [], 0, 0, 0, 0);
if (!wallet.data.ethAddress) {
throw new BadRequestException("Can not create wallet");
}
await this.walletService.createWallet(user.id, wallet.data.ethAddress);
return {
user: {
id: user.id,
Expand All @@ -75,10 +51,6 @@ export class OauthController {
family_name: user.family_name,
given_name: user.given_name
},
wallet: {
address: wallet?.data.ethAddress ?? "",
privateKey: wallet?.data.privKey ?? ""
},
socialUser: {
bookmarks: socialUser.bookmarks,
following: socialUser.following,
Expand All @@ -104,14 +76,6 @@ export class OauthController {
if (!socialUser)
await this.socialUserService.createSocialUser(user.id, [], [], [], 0, 0, 0, 0);

const walletStorage = await this.walletService.findWalletById(user.id);
if (!walletStorage) {
await this.walletService.createWallet(user.id, wallet.data.ethAddress);
}
if (walletStorage.address !== wallet.data.ethAddress) {
await this.walletService.updateWallet(user.id, wallet.data.ethAddress);
}

return {
user: {
id: user.id,
Expand All @@ -123,10 +87,6 @@ export class OauthController {
family_name: user.family_name,
given_name: user.given_name
},
wallet: {
address: wallet?.data.ethAddress ?? "",
privateKey: wallet?.data.privKey ?? ""
},
socialUser: {
bookmarks: socialUser.bookmarks ?? [],
following: socialUser.following ?? [],
Expand Down
23 changes: 10 additions & 13 deletions src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ export class UserController {
given_name: info.given_name,
email: info.email,
locale: info.locale,
wallet: {
address: wallet.address,
},
socialUser: {
following: listUserByFlowing?.map((user) => {
return {
Expand Down Expand Up @@ -72,15 +69,15 @@ export class UserController {
}

// get wallet by email
@Get("/wallet/:email")
async getWalletByEmail(@Param("email") email: string) {
const user = await this.userService.findUserByEmail(email);
const wallet = await this.walletService.findWalletById(user.id);
return {
id: user.id,
email: user.email,
address: wallet.address,
};
}
// @Get("/wallet/:email")
// async getWalletByEmail(@Param("email") email: string) {
// const user = await this.userService.findUserByEmail(email);
// const wallet = await this.walletService.findWalletById(user.id);
// return {
// id: user.id,
// email: user.email,
// address: wallet.address,
// };
// }

}

0 comments on commit e5c28aa

Please sign in to comment.