wallet-core: sort transactions ASC by default to not break tests
This commit is contained in:
parent
6a4e0ffd85
commit
529993da2f
@ -1006,8 +1006,8 @@ export class WithdrawOperationStatusResponse {
|
|||||||
/**
|
/**
|
||||||
* Response from the merchant.
|
* Response from the merchant.
|
||||||
*/
|
*/
|
||||||
export class TipPickupGetResponse {
|
export class RewardPickupGetResponse {
|
||||||
tip_amount: string;
|
reward_amount: string;
|
||||||
|
|
||||||
exchange_url: string;
|
exchange_url: string;
|
||||||
|
|
||||||
@ -1566,9 +1566,9 @@ export const codecForWithdrawOperationStatusResponse =
|
|||||||
.property("wire_types", codecForList(codecForString()))
|
.property("wire_types", codecForList(codecForString()))
|
||||||
.build("WithdrawOperationStatusResponse");
|
.build("WithdrawOperationStatusResponse");
|
||||||
|
|
||||||
export const codecForTipPickupGetResponse = (): Codec<TipPickupGetResponse> =>
|
export const codecForRewardPickupGetResponse = (): Codec<RewardPickupGetResponse> =>
|
||||||
buildCodecForObject<TipPickupGetResponse>()
|
buildCodecForObject<RewardPickupGetResponse>()
|
||||||
.property("tip_amount", codecForString())
|
.property("reward_amount", codecForString())
|
||||||
.property("exchange_url", codecForString())
|
.property("exchange_url", codecForString())
|
||||||
.property("next_url", codecOptional(codecForString()))
|
.property("next_url", codecOptional(codecForString()))
|
||||||
.property("expiration", codecForTimestamp)
|
.property("expiration", codecForTimestamp)
|
||||||
|
@ -62,6 +62,13 @@ export interface TransactionsRequest {
|
|||||||
*/
|
*/
|
||||||
search?: string;
|
search?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort order of the transaction items.
|
||||||
|
* By default, items are sorted ascending by their
|
||||||
|
* main timestamp.
|
||||||
|
*/
|
||||||
|
sort?: "ascending" | "descending",
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If true, include all refreshes in the transactions list.
|
* If true, include all refreshes in the transactions list.
|
||||||
*/
|
*/
|
||||||
|
@ -23,7 +23,7 @@ import {
|
|||||||
Amounts,
|
Amounts,
|
||||||
BlindedDenominationSignature,
|
BlindedDenominationSignature,
|
||||||
codecForMerchantTipResponseV2,
|
codecForMerchantTipResponseV2,
|
||||||
codecForTipPickupGetResponse,
|
codecForRewardPickupGetResponse,
|
||||||
CoinStatus,
|
CoinStatus,
|
||||||
DenomKeyType,
|
DenomKeyType,
|
||||||
encodeCrock,
|
encodeCrock,
|
||||||
@ -168,11 +168,11 @@ export async function prepareTip(
|
|||||||
const merchantResp = await ws.http.fetch(tipStatusUrl.href);
|
const merchantResp = await ws.http.fetch(tipStatusUrl.href);
|
||||||
const tipPickupStatus = await readSuccessResponseJsonOrThrow(
|
const tipPickupStatus = await readSuccessResponseJsonOrThrow(
|
||||||
merchantResp,
|
merchantResp,
|
||||||
codecForTipPickupGetResponse(),
|
codecForRewardPickupGetResponse(),
|
||||||
);
|
);
|
||||||
logger.trace(`status ${j2s(tipPickupStatus)}`);
|
logger.trace(`status ${j2s(tipPickupStatus)}`);
|
||||||
|
|
||||||
const amount = Amounts.parseOrThrow(tipPickupStatus.tip_amount);
|
const amount = Amounts.parseOrThrow(tipPickupStatus.reward_amount);
|
||||||
|
|
||||||
logger.trace("new tip, creating tip record");
|
logger.trace("new tip, creating tip record");
|
||||||
await updateExchangeFromUrl(ws, tipPickupStatus.exchange_url);
|
await updateExchangeFromUrl(ws, tipPickupStatus.exchange_url);
|
||||||
|
@ -1290,9 +1290,16 @@ export async function getTransactions(
|
|||||||
const txPending = transactions.filter((x) => isPending(x));
|
const txPending = transactions.filter((x) => isPending(x));
|
||||||
const txNotPending = transactions.filter((x) => !isPending(x));
|
const txNotPending = transactions.filter((x) => !isPending(x));
|
||||||
|
|
||||||
|
let sortSign: number;
|
||||||
|
if (transactionsRequest?.sort == "descending") {
|
||||||
|
sortSign = -1;
|
||||||
|
} else {
|
||||||
|
sortSign = 1;
|
||||||
|
}
|
||||||
|
|
||||||
const txCmp = (h1: Transaction, h2: Transaction) => {
|
const txCmp = (h1: Transaction, h2: Transaction) => {
|
||||||
// Order transactions by timestamp. Newest transactions come first.
|
// Order transactions by timestamp. Newest transactions come first.
|
||||||
const tsCmp = -AbsoluteTime.cmp(
|
const tsCmp = AbsoluteTime.cmp(
|
||||||
AbsoluteTime.fromPreciseTimestamp(h1.timestamp),
|
AbsoluteTime.fromPreciseTimestamp(h1.timestamp),
|
||||||
AbsoluteTime.fromPreciseTimestamp(h2.timestamp),
|
AbsoluteTime.fromPreciseTimestamp(h2.timestamp),
|
||||||
);
|
);
|
||||||
@ -1300,7 +1307,7 @@ export async function getTransactions(
|
|||||||
if (tsCmp === 0) {
|
if (tsCmp === 0) {
|
||||||
return Math.sign(txOrder[h1.type] - txOrder[h2.type]);
|
return Math.sign(txOrder[h1.type] - txOrder[h2.type]);
|
||||||
}
|
}
|
||||||
return tsCmp;
|
return sortSign * tsCmp;
|
||||||
};
|
};
|
||||||
|
|
||||||
txPending.sort(txCmp);
|
txPending.sort(txCmp);
|
||||||
|
Loading…
Reference in New Issue
Block a user