From 79892cbb6649504317f6de0c91d75a3d1bd1d0c7 Mon Sep 17 00:00:00 2001
From: pdp2121 <71317875+pdp2121@users.noreply.github.com>
Date: Tue, 25 Feb 2025 11:55:11 -0500
Subject: [PATCH] fix: handle non standard currency with decoded length of 3
(#1131)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
## High Level Overview of Change
Handle non standard currency that decoded to 3 characters, putting
prefix `Fake` to such currency.
Instead of being non-standard, 3 character currency codes should use the
[standard
format](https://xrpl.org/docs/references/protocol/data-types/currency-formats#standard-currency-codes)
if they are not "fake".
### Context of Change
Resolve https://github.com/ripple/explorer/issues/1130
### Type of Change
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (non-breaking change that only restructures code)
- [ ] Tests (You added tests for code that already exists, or your new
feature included in this PR)
- [ ] Documentation Updates
- [ ] Translation Updates
- [ ] Release
## Before / After
### Before
### After
---------
Co-authored-by: Elliot Lee
---
src/containers/shared/components/Currency.tsx | 9 ++++++++-
src/containers/shared/components/test/Currency.test.tsx | 7 +++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/containers/shared/components/Currency.tsx b/src/containers/shared/components/Currency.tsx
index ac48efa7c..8f72e5a1a 100644
--- a/src/containers/shared/components/Currency.tsx
+++ b/src/containers/shared/components/Currency.tsx
@@ -40,12 +40,19 @@ const Currency = (props: Props) => {
display
)
} else {
- const currencyCode =
+ let currencyCode =
currency?.length === NON_STANDARD_CODE_LENGTH &&
currency?.substring(0, 2) !== LP_TOKEN_IDENTIFIER
? hexToString(currency)
: currency
+ if (
+ currency?.length === NON_STANDARD_CODE_LENGTH &&
+ currencyCode.length === 3
+ ) {
+ currencyCode = `Fake${currencyCode}`
+ }
+
let display = `${currencyCode}`
if (currencyCode === XRP && displaySymbol) {
diff --git a/src/containers/shared/components/test/Currency.test.tsx b/src/containers/shared/components/test/Currency.test.tsx
index 8d7de259c..b58c68c13 100644
--- a/src/containers/shared/components/test/Currency.test.tsx
+++ b/src/containers/shared/components/test/Currency.test.tsx
@@ -58,6 +58,13 @@ describe('Currency', () => {
wrapper.unmount()
})
+ it('handle non-standard currency decoded to equal or fewer than 3 characters', () => {
+ const wrapper = mount(
+ ,
+ )
+ expect(wrapper.find('.currency').text()).toEqual('FakeXRP')
+ })
+
it('displays the XRP symbol when rendering XRP', () => {
const wrapper = mount()
expect(wrapper.find('.currency').text()).toEqual('\uE900 XRP')