From bfec8e07dd6569ae629cddcfbd515fdccda87cc0 Mon Sep 17 00:00:00 2001 From: gantunesr Date: Wed, 27 Apr 2022 00:52:44 -0400 Subject: [PATCH 1/3] Fix address crash in EthereumAddress --- app/util/address/index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/util/address/index.js b/app/util/address/index.js index 52f88bc010f..eaaaabf23c8 100644 --- a/app/util/address/index.js +++ b/app/util/address/index.js @@ -24,15 +24,18 @@ export function renderFullAddress(address) { export const formatAddress = (rawAddress, type) => { let formattedAddress = rawAddress; - if (isValidAddress(rawAddress)) { - if (type && type === 'short') { - formattedAddress = renderShortAddress(rawAddress); - } else if (type && type === 'mid') { - formattedAddress = renderSlightlyLongAddress(rawAddress); - } else { - formattedAddress = renderFullAddress(rawAddress); - } + if (!isValidAddress(rawAddress)) { + return rawAddress; + } + + if (type && type === 'short') { + formattedAddress = renderShortAddress(rawAddress); + } else if (type && type === 'mid') { + formattedAddress = renderSlightlyLongAddress(rawAddress); + } else { + formattedAddress = renderFullAddress(rawAddress); } + return formattedAddress.toLowerCase(); }; From 60e155b37357b56422617a7d9e6ea0ea9f8f363b Mon Sep 17 00:00:00 2001 From: gantunesr Date: Wed, 27 Apr 2022 00:53:04 -0400 Subject: [PATCH 2/3] Update tests --- app/util/address/index.test.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/util/address/index.test.ts b/app/util/address/index.test.ts index ffadb400f8c..acb73e01975 100644 --- a/app/util/address/index.test.ts +++ b/app/util/address/index.test.ts @@ -1,4 +1,4 @@ -import { isENS, renderSlightlyLongAddress } from '.'; +import { isENS, renderSlightlyLongAddress, formatAddress } from '.'; describe('isENS', () => { it('should return false by default', () => { @@ -32,3 +32,15 @@ describe('renderSlightlyLongAddress', () => { expect(renderSlightlyLongAddress(mockAddress, 5, 0).split('.')[3]).toBe('4D272'); }); }); + +describe('formatAddress', () => { + const mockAddress = '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272'; + it('should return address formatted for short type', () => { + const expectedValue = '0xc495...d272'; + expect(formatAddress(mockAddress, 'short')).toBe(expectedValue); + }); + it('should return address formatted for mid type', () => { + const expectedValue = '0xc4955c0d639d99699bfd7e...d272'; + expect(formatAddress(mockAddress, 'mid')).toBe(expectedValue); + }); +}); From c6fac70b8e1777c2e7c2064d144264c313cbfddb Mon Sep 17 00:00:00 2001 From: gantunesr Date: Wed, 27 Apr 2022 01:00:32 -0400 Subject: [PATCH 3/3] Update tests --- app/util/address/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/util/address/index.test.ts b/app/util/address/index.test.ts index acb73e01975..5cafc1cc1c0 100644 --- a/app/util/address/index.test.ts +++ b/app/util/address/index.test.ts @@ -21,7 +21,7 @@ describe('isENS', () => { describe('renderSlightlyLongAddress', () => { const mockAddress = '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272'; it('should return the address when the address do not exist', () => { - expect(renderSlightlyLongAddress(null)).toBe(null); + expect(renderSlightlyLongAddress(null)).toBeNull(); }); it('should return 5 characters before ellipsis and 4 final characters of the address after the ellipsis', () => { expect(renderSlightlyLongAddress(mockAddress).split('.')[0].length).toBe(24);