From 41ed4ffe96d5eb08573389960c2dd57da5d669fa Mon Sep 17 00:00:00 2001 From: Caio Teixeira Date: Fri, 29 Sep 2023 13:56:40 -0300 Subject: [PATCH] fix: change the payment status history sort to descending order --- src/helpers/formatDisbursements.ts | 15 ++++++++++----- src/helpers/formatPaymentDetails.ts | 19 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/helpers/formatDisbursements.ts b/src/helpers/formatDisbursements.ts index c04ad09..c0c4187 100644 --- a/src/helpers/formatDisbursements.ts +++ b/src/helpers/formatDisbursements.ts @@ -35,9 +35,14 @@ export const formatDisbursement = ( name: disbursement.wallet.name, }, fileName: disbursement.file_name, - statusHistory: disbursement.status_history.map((h) => ({ - status: h.status, - timestamp: h.timestamp, - userId: h.user_id, - })), + statusHistory: disbursement.status_history + .sort( + (a, b) => + new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime(), + ) + .map((h) => ({ + status: h.status, + timestamp: h.timestamp, + userId: h.user_id, + })), }); diff --git a/src/helpers/formatPaymentDetails.ts b/src/helpers/formatPaymentDetails.ts index 1fadb57..973a63c 100644 --- a/src/helpers/formatPaymentDetails.ts +++ b/src/helpers/formatPaymentDetails.ts @@ -12,12 +12,17 @@ export const formatPaymentDetails = (payment: ApiPayment): PaymentDetails => { senderAddress: payment.stellar_address, totalAmount: payment.amount, assetCode: payment.asset.code, - statusHistory: payment?.status_history.map((h) => { - return { - updatedAt: h.timestamp, - message: h.status_message, - status: h.status, - }; - }), + statusHistory: payment?.status_history + .sort( + (a, b) => + new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime(), + ) + .map((h) => { + return { + updatedAt: h.timestamp, + message: h.status_message, + status: h.status, + }; + }), }; };