From 2fcab1877329ae515df2190736e025de386b120b Mon Sep 17 00:00:00 2001 From: AlexanderBuzz <102560752+AlexanderBuzz@users.noreply.github.com> Date: Fri, 22 Sep 2023 14:35:40 +0200 Subject: [PATCH] - Fixed partial payment exploit - added custom token to displayable amount --- .../desktop-js/library/4_helpers.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/content/_code-samples/build-a-wallet/desktop-js/library/4_helpers.js b/content/_code-samples/build-a-wallet/desktop-js/library/4_helpers.js index a2ac577003..5e4063de90 100644 --- a/content/_code-samples/build-a-wallet/desktop-js/library/4_helpers.js +++ b/content/_code-samples/build-a-wallet/desktop-js/library/4_helpers.js @@ -6,9 +6,22 @@ const prepareTxData = (transactions) => { type: transaction.tx.TransactionType, from: transaction.tx.Account, to: transaction.tx.Destination, - value: xrpl.dropsToXrp(transaction.tx.Amount), + value: getDisplayableAmount(transaction.meta.delivered_amount), hash: transaction.tx.hash })) } +const getDisplayableAmount = (rawAmount) => { + if (rawAmount === 'unavailable') { + // Special case for pre-2014 partial payments. + return rawAmount + } else if (typeof rawAmount === 'string') { + // It's an XRP amount in drops. Convert to decimal. + return xrpl.dropsToXrp(rawAmount) + ' XRP' + } else { + //It's a token (IOU) amount. + return rawAmount.value + ' ' + rawAmount.currency + } +} + module.exports = { prepareTxData }