From 9e80daa90158df7e2f65e06f50ae41404b0b9cb8 Mon Sep 17 00:00:00 2001 From: Keng Ye <40191153+kyleleow@users.noreply.github.com> Date: Tue, 27 Sep 2022 11:35:32 +0800 Subject: [PATCH] feat(whale-api): return decoded address in bid history (#1785) --- apps/whale-api/src/module.api/loan.auction.history.e2e.ts | 8 ++++++++ apps/whale-api/src/module.api/loan.controller.ts | 8 +++++++- .../src/module.model/vault.auction.batch.history.ts | 2 +- .../__tests__/api/loan.auction.history.test.ts | 8 ++++++++ packages/whale-api-client/src/api/loan.ts | 1 + 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/apps/whale-api/src/module.api/loan.auction.history.e2e.ts b/apps/whale-api/src/module.api/loan.auction.history.e2e.ts index ab0e1d5864..29d841f19a 100644 --- a/apps/whale-api/src/module.api/loan.auction.history.e2e.ts +++ b/apps/whale-api/src/module.api/loan.auction.history.e2e.ts @@ -171,6 +171,7 @@ it('should listVaultAuctionHistory', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: colAddr, amount: '5408.55', tokenId: 2, block: expect.any(Object) @@ -182,6 +183,7 @@ it('should listVaultAuctionHistory', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: bobColAddr, amount: '5355', tokenId: 2, block: expect.any(Object) @@ -193,6 +195,7 @@ it('should listVaultAuctionHistory', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: colAddr, amount: '5300', tokenId: 2, block: expect.any(Object) @@ -211,6 +214,7 @@ it('should listVaultAuctionHistory', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: bobColAddr, amount: '5355.123', tokenId: 4, block: expect.any(Object) @@ -222,6 +226,7 @@ it('should listVaultAuctionHistory', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: colAddr, amount: '5300.123', tokenId: 4, block: expect.any(Object) @@ -241,6 +246,7 @@ it('should listVaultAuctionHistory with pagination', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: colAddr, amount: '5408.55', tokenId: 2, block: expect.any(Object) @@ -257,6 +263,7 @@ it('should listVaultAuctionHistory with pagination', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: bobColAddr, amount: '5355', tokenId: 2, block: expect.any(Object) @@ -273,6 +280,7 @@ it('should listVaultAuctionHistory with pagination', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: colAddr, amount: '5300', tokenId: 2, block: expect.any(Object) diff --git a/apps/whale-api/src/module.api/loan.controller.ts b/apps/whale-api/src/module.api/loan.controller.ts index 21951b8941..89bc5eed43 100644 --- a/apps/whale-api/src/module.api/loan.controller.ts +++ b/apps/whale-api/src/module.api/loan.controller.ts @@ -34,6 +34,7 @@ import { VaultAuctionHistoryMapper, VaultAuctionBatchHistory } from '../module.m import { ActivePrice } from '@defichain/whale-api-client/dist/api/prices' import { NetworkName } from '@defichain/jellyfish-network' import { HexEncoder } from '../module.model/_hex.encoder' +import { fromScriptHex } from '@defichain/jellyfish-address' @Controller('/loans') export class LoanController { @@ -202,7 +203,12 @@ export class LoanController { ): Promise> { const lt = query.next ?? `${HexEncoder.encodeHeight(height)}-${'f'.repeat(64)}` const gt = `${HexEncoder.encodeHeight(height - this.liqBlockExpiry)}-${'0'.repeat(64)}` - const list = await this.vaultAuctionHistoryMapper.query(`${id}-${batchIndex}`, query.size, lt, gt) + const list = (await this.vaultAuctionHistoryMapper.query(`${id}-${batchIndex}`, query.size, lt, gt)).map(history => { + return { + ...history, + address: fromScriptHex(history.from, this.network)?.address as string + } + }) return ApiPagedResponse.of(list, query.size, item => { return item.sort diff --git a/apps/whale-api/src/module.model/vault.auction.batch.history.ts b/apps/whale-api/src/module.model/vault.auction.batch.history.ts index 7889721dd2..8a5bb0c89c 100644 --- a/apps/whale-api/src/module.model/vault.auction.batch.history.ts +++ b/apps/whale-api/src/module.model/vault.auction.batch.history.ts @@ -63,7 +63,7 @@ export interface VaultAuctionBatchHistory extends Model { vaultId: string index: number - from: string + from: string // -------------------| hex script amount: string // -------------------| stringified bignumber tokenId: number // ------------------| tokenId diff --git a/packages/whale-api-client/__tests__/api/loan.auction.history.test.ts b/packages/whale-api-client/__tests__/api/loan.auction.history.test.ts index 4ef92df649..c82c1c6f30 100644 --- a/packages/whale-api-client/__tests__/api/loan.auction.history.test.ts +++ b/packages/whale-api-client/__tests__/api/loan.auction.history.test.ts @@ -173,6 +173,7 @@ it('should listVaultAuctionHistory', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: colAddr, amount: '5408.55', tokenId: 2, block: expect.any(Object) @@ -184,6 +185,7 @@ it('should listVaultAuctionHistory', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: bobColAddr, amount: '5355', tokenId: 2, block: expect.any(Object) @@ -195,6 +197,7 @@ it('should listVaultAuctionHistory', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: colAddr, amount: '5300', tokenId: 2, block: expect.any(Object) @@ -213,6 +216,7 @@ it('should listVaultAuctionHistory', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: bobColAddr, amount: '5355.123', tokenId: 4, block: expect.any(Object) @@ -224,6 +228,7 @@ it('should listVaultAuctionHistory', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: colAddr, amount: '5300.123', tokenId: 4, block: expect.any(Object) @@ -245,6 +250,7 @@ it('should listVaultAuctionHistory with pagination', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: colAddr, amount: '5408.55', tokenId: 2, block: expect.any(Object) @@ -263,6 +269,7 @@ it('should listVaultAuctionHistory with pagination', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: bobColAddr, amount: '5355', tokenId: 2, block: expect.any(Object) @@ -281,6 +288,7 @@ it('should listVaultAuctionHistory with pagination', async () => { vaultId: vaultId, index: 0, from: expect.any(String), + address: colAddr, amount: '5300', tokenId: 2, block: expect.any(Object) diff --git a/packages/whale-api-client/src/api/loan.ts b/packages/whale-api-client/src/api/loan.ts index 5bd9fe2b84..5e8a047025 100644 --- a/packages/whale-api-client/src/api/loan.ts +++ b/packages/whale-api-client/src/api/loan.ts @@ -211,6 +211,7 @@ export interface VaultAuctionBatchHistory { vaultId: string index: number from: string + address: string amount: string tokenId: number