Skip to content

Commit

Permalink
feat(hasura): insert user wallet when init app
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Oct 17, 2023
1 parent 89bb3bf commit 88a2e4c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/user-wallet/user-wallet.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class UserWalletGraphql {
this.configSvc.get<string>('graphql.endpoint'),
'',
`query query_user_wallet($ids: [bpchar!] = "") {
authorizer_users(where: {id: {_nin: $ids}}) {
authorizer_users(where: {id: {_nin: $ids}}, limit: 10) {
id
}
}`,
Expand Down
29 changes: 21 additions & 8 deletions src/user-wallet/user-wallet.service.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,49 @@
import * as bip39 from 'bip39';

import { Secp256k1HdWallet } from '@cosmjs/amino';
import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common';
import {
HttpException,
HttpStatus,
Injectable,
Logger,
OnModuleInit,
} from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

import { SysKeyService } from '../keys/syskey.service';
import { GenerateWalletRequestDto } from './dto/generate-wallet-request.dto';
import { UserWalletGraphql } from './user-wallet.graphql';

@Injectable()
export class UserWalletService {
export class UserWalletService implements OnModuleInit {
private readonly logger = new Logger(UserWalletService.name);
constructor(
private configService: ConfigService,
private userWalletGraphql: UserWalletGraphql,
private sysKeyService: SysKeyService
) {
// this.fillEmptyUserWallet();
) {}

async onModuleInit() {
const data = [];
do {
const users = await this.userWalletGraphql.queryEmptyUserWallet();
data.push(...users);
await this.insertUserWallet(data);
} while (data.length > 0);
}

async fillEmptyUserWallet() {
const users = await this.userWalletGraphql.queryEmptyUserWallet();
async insertUserWallet(data: any) {
// const users = await this.userWalletGraphql.queryEmptyUserWallet();
const wallets = await Promise.all(
users.map(() => {
data.map(() => {
return this.randomWallet();
})
);

const objects = wallets.map((wallet, index) => ({
address: wallet.account[0].address,
data: JSON.parse(wallet.serializedWallet).data,
user_id: users[index].id,
user_id: data[index].id,
}));

const result = await this.userWalletGraphql.insertManyUserWallet({
Expand Down

0 comments on commit 88a2e4c

Please sign in to comment.