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

[FIX] Undefined address error #4166

Merged
merged 5 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
19 changes: 11 additions & 8 deletions app/util/address/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down
16 changes: 14 additions & 2 deletions app/util/address/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isENS, renderSlightlyLongAddress } from '.';
import { isENS, renderSlightlyLongAddress, formatAddress } from '.';

describe('isENS', () => {
it('should return false by default', () => {
Expand All @@ -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);
Expand All @@ -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);
});
});