diff --git a/docs/node/CATEGORIES/08-account.md b/docs/node/CATEGORIES/08-account.md index f3e38e4227..5bb9b23967 100644 --- a/docs/node/CATEGORIES/08-account.md +++ b/docs/node/CATEGORIES/08-account.md @@ -216,6 +216,11 @@ enum DfTxType { NONE = '0' } +enum Format { + ID = 'id', + SYMBOL = 'symbol' +} + interface AccountHistory { owner: string blockHeight: number @@ -235,6 +240,7 @@ interface AccountHistoryOptions { txtype?: DfTxType limit?: number txn?: number + format?: Format } ``` diff --git a/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts b/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts index dc3c131781..faf9537bca 100644 --- a/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts @@ -1,7 +1,7 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers' import { ContainerAdapterClient } from '../../container_adapter_client' import waitForExpect from 'wait-for-expect' -import { DfTxType, BalanceTransferPayload, AccountResult, AccountOwner } from '../../../src/category/account' +import { DfTxType, BalanceTransferPayload, AccountResult, AccountOwner, Format } from '../../../src/category/account' function createTokenForContainer (container: MasterNodeRegTestContainer) { return async (address: string, symbol: string, amount: number) => { @@ -303,6 +303,61 @@ describe('Account', () => { } }) }) + + it('should listAccountHistory with options format', async () => { + { // amount format should be id + const options = { + token: 'DBTC', + format: Format.ID + } + const accountHistories = await client.account.listAccountHistory('mine', options) + expect(accountHistories.length).toBeGreaterThan(0) + for (let i = 0; i < accountHistories.length; i += 1) { + const accountHistory = accountHistories[i] + expect(accountHistory.amounts.length).toBeGreaterThan(0) + for (let j = 0; j < accountHistory.amounts.length; j += 1) { + const amount = accountHistory.amounts[j] + const id = amount.split('@')[1] + expect(id).toStrictEqual('1') + } + } + } + + { // amount format should be symbol + const options = { + token: 'DBTC', + format: Format.SYMBOL + } + const accountHistories = await client.account.listAccountHistory('mine', options) + expect(accountHistories.length).toBeGreaterThan(0) + for (let i = 0; i < accountHistories.length; i += 1) { + const accountHistory = accountHistories[i] + expect(accountHistory.amounts.length).toBeGreaterThan(0) + for (let j = 0; j < accountHistory.amounts.length; j += 1) { + const amount = accountHistory.amounts[j] + const symbol = amount.split('@')[1] + expect(symbol).toStrictEqual('DBTC') + } + } + } + + { // amount format default should be symbol + const options = { + token: 'DFI' + } + const accountHistories = await client.account.listAccountHistory('mine', options) + expect(accountHistories.length).toBeGreaterThan(0) + for (let i = 0; i < accountHistories.length; i += 1) { + const accountHistory = accountHistories[i] + expect(accountHistory.amounts.length).toBeGreaterThan(0) + for (let j = 0; j < accountHistory.amounts.length; j += 1) { + const amount = accountHistory.amounts[j] + const symbol = amount.split('@')[1] + expect(symbol).toStrictEqual('DFI') + } + } + } + }) }) describe('listAccountHistory', () => { diff --git a/packages/jellyfish-api-core/src/category/account.ts b/packages/jellyfish-api-core/src/category/account.ts index 64ff3cd0f8..4dce320c8e 100644 --- a/packages/jellyfish-api-core/src/category/account.ts +++ b/packages/jellyfish-api-core/src/category/account.ts @@ -34,6 +34,16 @@ export enum DfTxType { FUTURE_SWAP_REFUND = 'w' } +/** + * Configure the format of amounts + * id - amount with the following 'id' -> @id + * symbol - amount with the following 'symbol' -> @symbol + */ +export enum Format { + ID = 'id', + SYMBOL = 'symbol' +} + export enum SelectionModeType { PIE = 'pie', CRUMBS = 'crumbs', @@ -292,6 +302,7 @@ export class Account { * @param {DfTxType} [options.txtype] Filter by transaction type. See DfTxType. * @param {number} [options.limit=100] Maximum number of records to return, 100 by default * @param {number} [options.txn] Order in block, unlimited by default + * @param {Format} [options.format] Set the return amount format, Format.SYMBOL by default * @return {Promise} */ async listAccountHistory ( @@ -511,6 +522,7 @@ export interface AccountHistoryOptions { txtype?: DfTxType limit?: number txn?: number + format?: Format } export interface AccountHistoryCountOptions {