|
|
@@ -21,7 +21,7 @@ export class AccountsService {
|
|
|
return await this.accountsRepository.find()
|
|
|
}
|
|
|
|
|
|
- async findByUserId(userId: number, network: Network) {
|
|
|
+ async findByUserId(userId: number, network?: Network) {
|
|
|
return await this.accountsRepository.findBy({
|
|
|
userId,
|
|
|
network
|
|
|
@@ -68,8 +68,8 @@ export class AccountsService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @OnEvent('updateBalance')
|
|
|
- async handleOrderCreatedEvent(accountId) {
|
|
|
+ @OnEvent('refreshBalance')
|
|
|
+ async refreshBalanceByAccountId(accountId) {
|
|
|
try {
|
|
|
const account = await this.findById(accountId)
|
|
|
Logger.log(`fetching balances for ${account.address}`)
|
|
|
@@ -87,7 +87,14 @@ export class AccountsService {
|
|
|
account.zkUsdcBalance = ethers.utils.formatUnits(zkUsdcBalance, 6)
|
|
|
await this.save([account])
|
|
|
} catch (error) {
|
|
|
- Logger.error(error, 'updateBalance')
|
|
|
+ Logger.error(error, 'refreshBalance')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async refreshBalance(userId: number) {
|
|
|
+ const accounts = await this.findByUserId(userId)
|
|
|
+ for (let account of accounts) {
|
|
|
+ await this.refreshBalanceByAccountId(account.id)
|
|
|
}
|
|
|
}
|
|
|
}
|