This repository has been archived by the owner on Apr 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: address summary stretchy thing (#297)
* fix: address summary stretchy thing * fix: lint, remove extra stuff
- Loading branch information
1 parent
895a9ca
commit cc95952
Showing
7 changed files
with
162 additions
and
9 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
front/gatsby/src/components/AddressSummary/AddressSummary.styles.ts
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,18 @@ | ||
// Copyright 2018-2020 @paritytech/Nomidot authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import styled from 'styled-components'; | ||
|
||
export const SquareAddressSummaryBlock = styled.div` | ||
display: 'flex'; | ||
align-items: 'center'; | ||
justify-content: 'flex-end'; | ||
height: 100%; | ||
`; | ||
|
||
export const Name = styled.p` | ||
font-size: 20px; | ||
font-weight: 500; | ||
margin: 0 0; | ||
`; |
112 changes: 112 additions & 0 deletions
112
front/gatsby/src/components/AddressSummary/AddressSummary.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,112 @@ | ||
// Copyright 2018-2020 @paritytech/Nomidot authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import ApiRx from '@polkadot/api/rx'; | ||
import IdentityIcon from '@polkadot/react-identicon'; | ||
import { Spinner } from '@substrate/design-system'; | ||
import { Balance, FontSize } from '@substrate/ui-components'; | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import { OrientationType, SizeType } from './types'; | ||
|
||
const Layout = styled.div` | ||
padding: 2px; | ||
& > * { | ||
margin: 1px 10px; | ||
} | ||
`; | ||
|
||
type AddressSummaryProps = { | ||
address?: string; | ||
api: ApiRx; | ||
detailed?: boolean; | ||
name?: string; | ||
noPlaceholderName?: boolean; | ||
noBalance?: boolean; | ||
orientation?: OrientationType; | ||
size?: SizeType; | ||
withShortAddress?: boolean; | ||
}; | ||
|
||
const PLACEHOLDER_NAME = 'No Name'; | ||
|
||
const ICON_SIZES = { | ||
tiny: 16, | ||
small: 32, | ||
medium: 96, | ||
large: 128, | ||
}; | ||
|
||
function renderIcon(address: string, size: SizeType): React.ReactElement { | ||
return ( | ||
<IdentityIcon value={address} theme={'substrate'} size={ICON_SIZES[size]} /> | ||
); | ||
} | ||
|
||
type FontSizeType = { | ||
[x: string]: string; | ||
}; | ||
|
||
const FONT_SIZES: FontSizeType = { | ||
tiny: 'small', | ||
small: 'medium', | ||
medium: 'large', | ||
large: 'big', | ||
}; | ||
|
||
function renderShortAddress(address: string): string { | ||
return address | ||
.slice(0, 8) | ||
.concat('......') | ||
.concat(address.slice(address.length - 8, address.length)); | ||
} | ||
|
||
function renderDetails( | ||
address: string, | ||
api: ApiRx, | ||
summaryProps: Exclude<AddressSummaryProps, keyof 'address'> | ||
): React.ReactElement { | ||
const { | ||
detailed, | ||
name = PLACEHOLDER_NAME, | ||
noBalance, | ||
noPlaceholderName, | ||
orientation, | ||
size = 'medium', | ||
withShortAddress, | ||
} = summaryProps; | ||
|
||
return ( | ||
<> | ||
{noPlaceholderName ? null : name} | ||
{withShortAddress && renderShortAddress(address)} | ||
{!noBalance && ( | ||
<Balance | ||
address={address} | ||
api={api} | ||
detailed={detailed} | ||
orientation={orientation} | ||
fontSize={FONT_SIZES[size] as FontSize} | ||
/> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export function AddressSummary(props: AddressSummaryProps): React.ReactElement { | ||
const { address, api, size = 'medium' } = props; | ||
|
||
if (address) { | ||
return ( | ||
<Layout> | ||
{renderIcon(address, size)} | ||
{renderDetails(address, api, props)} | ||
</Layout> | ||
); | ||
} else { | ||
return <Spinner />; | ||
} | ||
} |
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,5 @@ | ||
// Copyright 2018-2020 @paritytech/Nomidot authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
export * from './AddressSummary'; |
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,6 @@ | ||
// Copyright 2018-2020 @paritytech/Nomidot authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
export type OrientationType = 'horizontal' | 'vertical'; | ||
export type SizeType = 'tiny' | 'small' | 'medium' | 'large'; |
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 |
---|---|---|
|
@@ -299,4 +299,4 @@ const BondingModal = (): React.ReactElement => { | |
); | ||
}; | ||
|
||
export default BondingModal; | ||
export { BondingModal }; |
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
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