Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for issued currencies on Escrows and PaymentChannels #587

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/containers/Accounts/AccountHeader/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const AccountHeader = (props) => {
)
}

const options = { ...CURRENCY_OPTIONS, currency: currencySelected }
function renderPaymentChannels() {
const { paychannels } = data
return (
Expand Down Expand Up @@ -95,22 +96,20 @@ const AccountHeader = (props) => {

function renderEscrows() {
const { escrows } = data
const fIn = escrows && escrows.totalIn[currencySelected]
const fOut = escrows && escrows.totalOut[currencySelected]
return (
escrows && (
<div className="escrows secondary">
<div className="title">{t('escrows')}</div>
<ul>
<li>
<span className="label">{t('inbound_total')}: </span>
<b>
{localizeNumber(escrows.totalIn, language, CURRENCY_OPTIONS)}
</b>
<b>{localizeNumber(fIn, language, options)}</b>
</li>
<li>
<span className="label">{t('outbound_total')}: </span>
<b>
{localizeNumber(escrows.totalOut, language, CURRENCY_OPTIONS)}
</b>
<b>{localizeNumber(fOut, language, options)}</b>
</li>
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ const Description: TransactionDescriptionComponent = (
)}
<div>
{t('escrowed_amount')}
<b>
{' '}
{normalizeAmount(data.tx.Amount, language)}
<small>XRP</small>
</b>
<b> {normalizeAmount(data.tx.Amount, language)}</b>
</div>
{data.tx.CancelAfter && (
<div>
Expand Down
2 changes: 1 addition & 1 deletion src/containers/shared/transactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export function normalizeAmount(
const value =
typeof amount === 'object' ? amount.value : Number(amount) / XRP_BASE
const numberOption = { ...CURRENCY_OPTIONS, currency }
return localizeNumber(value, language, numberOption)
return `${localizeNumber(value, language, numberOption)} ${currency}`
}

export function findNode(
Expand Down
8 changes: 6 additions & 2 deletions src/containers/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,14 @@ export function formatPrice(number, options = {}) {
// Document: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
export const localizeDate = (date, lang = 'en-US', options = {}) => {
// TODO: default config
if (!date) {
try {
if (!date) {
return null
}
return new Intl.DateTimeFormat(lang, options).format(date)
} catch {
Comment on lines +234 to +239
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this try-catch block catch that wasn't caught before? Seems better to solve the root cause instead of using this blanket fix.

return null
}
return new Intl.DateTimeFormat(lang, options).format(date)
}

/**
Expand Down
26 changes: 17 additions & 9 deletions src/rippled/lib/rippled.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const formatEscrow = (d) => ({
id: d.index,
account: d.Account,
destination: d.Destination,
amount: d.Amount / XRP_BASE,
amount: d.Amount,
condition: d.Condition,
cancelAfter: d.CancelAfter ? convertRippleDate(d.CancelAfter) : undefined,
finishAfter: d.FinishAfter ? convertRippleDate(d.FinishAfter) : undefined,
Expand Down Expand Up @@ -146,22 +146,30 @@ const getAccountEscrows = (
return undefined
}

const escrows = { in: [], out: [], total: 0, totalIn: 0, totalOut: 0 }
const escrows = {
in: [],
out: [],
total: 0,
totalIn: { XRP: 0 },
totalOut: { XRP: 0 },
}
resp.account_objects.forEach((d) => {
const amount = Number(d.Amount)
const amount =
typeof d.Amount === 'object'
? d.Amount.value
: Number(d.Amount) / XRP_BASE
const currency = typeof d.Amount === 'object' ? d.Amount.currency : 'XRP'
escrows.total += amount
escrows.totalIn[currency] = 0
escrows.totalOut[currency] = 0
if (account === d.Destination) {
escrows.in.push(formatEscrow(d))
escrows.totalIn += amount
escrows.totalIn[currency] = amount
} else {
escrows.out.push(formatEscrow(d))
escrows.totalOut += amount
escrows.totalOut[currency] = amount
}
})

escrows.total /= XRP_BASE
escrows.totalIn /= XRP_BASE
escrows.totalOut /= XRP_BASE
return escrows
})

Expand Down