Skip to content

Commit

Permalink
Pass managed user id header when fetching wallet balance
Browse files Browse the repository at this point in the history
  • Loading branch information
raducristianpopa committed Oct 3, 2024
1 parent 237b91a commit 4c0a5c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 11 additions & 1 deletion packages/wallet/backend/src/account/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,19 @@ export class AccountService implements IAccountService {
}

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

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

const balances = await this.gateHubClient.getWalletBalance(
account.gateHubWalletId
account.gateHubWalletId,
user.gateHubUserId
)

return Number(
balances.find((balance) => balance.vault.asset_code === account.assetCode)
?.total ?? 0
Expand Down
9 changes: 7 additions & 2 deletions packages/wallet/backend/src/gatehub/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,15 @@ export class GateHubClient {
return response
}

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

const response = await this.request<IWalletBalance[]>('GET', url)
const response = await this.request<IWalletBalance[]>('GET', url, '', {
managedUserUuid
})

return response
}
Expand Down

0 comments on commit 4c0a5c6

Please sign in to comment.