-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(suite-native): Introduce AccountAddress component
- Loading branch information
Showing
4 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
suite-native/module-trading/src/components/general/AccountAddress.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Text, TextProps } from '@suite-native/atoms'; | ||
|
||
type AccountAddressProps = { | ||
address: string; | ||
form?: 'short' | 'full'; | ||
} & Omit<TextProps, 'numberOfLines' | 'children'>; | ||
|
||
const SHORT_ADDRESS_TRUNCATION_LENGTH = 8; | ||
|
||
export const AccountAddress = ({ address, form = 'full', ...textProps }: AccountAddressProps) => { | ||
const addressToDisplay = | ||
form === 'short' && address.length > SHORT_ADDRESS_TRUNCATION_LENGTH | ||
? `${address.substring(0, SHORT_ADDRESS_TRUNCATION_LENGTH)}...` | ||
: address; | ||
|
||
return ( | ||
<Text {...textProps} numberOfLines={1}> | ||
{addressToDisplay} | ||
</Text> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
suite-native/module-trading/src/components/general/__tests__/AccountAddress.comp.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { render } from '@suite-native/test-utils'; | ||
|
||
import { AccountAddress } from '../AccountAddress'; | ||
|
||
describe('AccountAddress', () => { | ||
describe('full form', () => { | ||
it('should render full address', () => { | ||
const { getByText } = render(<AccountAddress address="0x1234567890abcdef" />); | ||
|
||
expect(getByText('0x1234567890abcdef')).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('short form', () => { | ||
it('should render address with ellipsis', () => { | ||
const { getByText } = render( | ||
<AccountAddress address="0x1234567890abcdef" form="short" />, | ||
); | ||
|
||
expect(getByText('0x123456...')).toBeDefined(); | ||
}); | ||
|
||
it('should render full address when it is shorter than 9 characters', () => { | ||
const { getByText } = render(<AccountAddress address="0x123456" />); | ||
|
||
expect(getByText('0x123456')).toBeDefined(); | ||
}); | ||
}); | ||
}); |