Skip to content

Commit

Permalink
fix: remove unused user id on get balance
Browse files Browse the repository at this point in the history
  • Loading branch information
dragosp1011 committed Sep 23, 2024
1 parent 7933947 commit 3c8fb7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
19 changes: 6 additions & 13 deletions packages/wallet/backend/src/account/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface IAccountService {
includeWalletKeys?: boolean
) => Promise<Account[]>
getAccountById: (userId: string, accountId: string) => Promise<Account>
getAccountBalance: (userId: string, account: Account) => Promise<number>
getAccountBalance: (account: Account) => Promise<number>
}

export class AccountService implements IAccountService {
Expand Down Expand Up @@ -110,7 +110,7 @@ export class AccountService implements IAccountService {

if (!includeWalletAddress) {
accounts.forEach(async (acc) => {
const balance = await this.getAccountBalance(userId, acc)
const balance = await this.getAccountBalance(acc)
acc.balance = transformBalance(balance, acc.assetScale)
})
}
Expand All @@ -132,7 +132,7 @@ export class AccountService implements IAccountService {
}

account.balance = transformBalance(
await this.getAccountBalance(userId, account),
await this.getAccountBalance(account),
account.assetScale
)

Expand All @@ -152,23 +152,16 @@ export class AccountService implements IAccountService {
}

account.balance = transformBalance(
await this.getAccountBalance(userId, account),
await this.getAccountBalance(account),
account.assetScale
)

return account
}

async getAccountBalance(userId: string, account: Account): Promise<number> {
const user = await User.query().findById(userId)

if (!user || !user.gateHubUserId) {
throw new NotFound()
}

async getAccountBalance(account: Account): Promise<number> {
const balances = await this.gateHubClient.getWalletBalance(
account.gateHubWalletId,
userId
account.gateHubWalletId
)
return Number(
balances.find((balance) => balance.vault.assetCode === account.assetCode)
Expand Down
5 changes: 1 addition & 4 deletions packages/wallet/backend/src/gatehub/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,7 @@ export class GateHubClient {
return response
}

async getWalletBalance(
walletId: string,
_userUuid: string
): Promise<IWalletBalance[]> {
async getWalletBalance(walletId: string): Promise<IWalletBalance[]> {
const url = `${this.apiUrl}/core/v1/wallets/${walletId}/balances`

const response = await this.request<IWalletBalance[]>('GET', url)
Expand Down

0 comments on commit 3c8fb7d

Please sign in to comment.