-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(suite): fiat rates loading visualization
- Loading branch information
1 parent
dfb1169
commit f904439
Showing
12 changed files
with
165 additions
and
230 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
44 changes: 44 additions & 0 deletions
44
packages/suite/src/components/suite/Ticker/LastUpdateTooltip.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,44 @@ | ||
import { Translation } from 'src/components/suite'; | ||
import styled from 'styled-components'; | ||
import { Tooltip } from '@trezor/components'; | ||
import { FormattedRelativeTime } from 'react-intl'; | ||
import { ReactNode } from 'react'; | ||
import { differenceInMinutes } from 'date-fns'; | ||
|
||
const LastUpdate = styled.div` | ||
text-transform: none; | ||
`; | ||
|
||
interface LastUpdateTooltipProps { | ||
timestamp: number; | ||
children: ReactNode; | ||
} | ||
|
||
export const LastUpdateTooltip = ({ timestamp, children }: LastUpdateTooltipProps) => { | ||
const rateAge = (timestamp: number) => differenceInMinutes(new Date(timestamp), new Date()); | ||
|
||
return ( | ||
<Tooltip | ||
maxWidth={285} | ||
placement="top" | ||
content={ | ||
<LastUpdate> | ||
<Translation | ||
id="TR_LAST_UPDATE" | ||
values={{ | ||
value: ( | ||
<FormattedRelativeTime | ||
value={rateAge(timestamp) * 60} | ||
numeric="auto" | ||
updateIntervalInSeconds={10} | ||
/> | ||
), | ||
}} | ||
/> | ||
</LastUpdate> | ||
} | ||
> | ||
{children} | ||
</Tooltip> | ||
); | ||
}; |
40 changes: 20 additions & 20 deletions
40
packages/suite/src/components/suite/Ticker/NoRatesTooltip.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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
import { Translation, TooltipSymbol } from 'src/components/suite'; | ||
import styled from 'styled-components'; | ||
import { Tooltip, variables } from '@trezor/components'; | ||
import styled, { useTheme } from 'styled-components'; | ||
import { TranslationKey } from '../Translation'; | ||
import { typography } from '@trezor/theme'; | ||
|
||
const NoRatesMessage = styled.div` | ||
${typography.label}; | ||
display: flex; | ||
align-items: center; | ||
color: ${({ theme }) => theme.TYPE_LIGHT_GREY}; | ||
font-size: ${variables.FONT_SIZE.TINY}; | ||
font-weight: ${variables.FONT_WEIGHT.REGULAR}; | ||
color: ${({ theme }) => theme.textSubdued}; | ||
text-transform: none; | ||
`; | ||
|
||
interface NoRatesTooltipProps extends Partial<typeof Tooltip> { | ||
interface NoRatesTooltipProps { | ||
customText?: TranslationKey; | ||
customTooltip?: TranslationKey; | ||
iconOnly?: boolean; | ||
className?: string; | ||
} | ||
|
||
export const NoRatesTooltip = ({ | ||
customText, | ||
iconOnly, | ||
customTooltip, | ||
className, | ||
}: NoRatesTooltipProps) => ( | ||
<NoRatesMessage className={className}> | ||
{!iconOnly && <Translation id={customText || 'TR_FIAT_RATES_NOT_AVAILABLE'} />} | ||
<TooltipSymbol | ||
content={<Translation id={customTooltip || 'TR_FIAT_RATES_NOT_AVAILABLE_TOOLTIP'} />} | ||
/> | ||
</NoRatesMessage> | ||
); | ||
export const NoRatesTooltip = ({ customText, customTooltip, className }: NoRatesTooltipProps) => { | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<NoRatesMessage className={className}> | ||
<Translation id={customText || 'TR_FIAT_RATES_NOT_AVAILABLE'} /> | ||
<TooltipSymbol | ||
content={ | ||
<Translation id={customTooltip || 'TR_FIAT_RATES_NOT_AVAILABLE_TOOLTIP'} /> | ||
} | ||
iconColor={theme.iconSubdued} | ||
/> | ||
</NoRatesMessage> | ||
); | ||
}; |
63 changes: 16 additions & 47 deletions
63
packages/suite/src/components/suite/Ticker/PriceTicker.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 |
---|---|---|
@@ -1,61 +1,30 @@ | ||
import styled from 'styled-components'; | ||
import { differenceInMinutes } from 'date-fns'; | ||
import { FormattedRelativeTime } from 'react-intl'; | ||
|
||
import { Tooltip } from '@trezor/components'; | ||
import { FiatValue, Translation } from 'src/components/suite'; | ||
import { FiatValue } from 'src/components/suite'; | ||
import { NoRatesTooltip } from './NoRatesTooltip'; | ||
import { typography } from '@trezor/theme'; | ||
import { LastUpdateTooltip } from './LastUpdateTooltip'; | ||
|
||
const FiatRateWrapper = styled.span` | ||
${typography.hint} | ||
display: flex; | ||
align-items: center; | ||
color: ${({ theme }) => theme.TYPE_DARK_GREY}; | ||
${typography.hint} | ||
`; | ||
|
||
const LastUpdate = styled.div` | ||
text-transform: none; | ||
`; | ||
|
||
interface PriceTickerProps { | ||
symbol: string; | ||
tooltipPos?: 'top' | 'bottom'; | ||
compact?: boolean; | ||
} | ||
export const PriceTicker = ({ symbol, tooltipPos = 'top', compact = false }: PriceTickerProps) => { | ||
const rateAge = (timestamp: number) => differenceInMinutes(new Date(timestamp), new Date()); | ||
|
||
return ( | ||
<FiatValue amount="1" symbol={symbol}> | ||
{({ rate, timestamp }) => | ||
rate && timestamp ? ( | ||
<Tooltip | ||
maxWidth={285} | ||
placement={tooltipPos} | ||
content={ | ||
<LastUpdate> | ||
<Translation | ||
id="TR_LAST_UPDATE" | ||
values={{ | ||
value: ( | ||
<FormattedRelativeTime | ||
value={rateAge(timestamp) * 60} | ||
numeric="auto" | ||
updateIntervalInSeconds={10} | ||
/> | ||
), | ||
}} | ||
/> | ||
</LastUpdate> | ||
} | ||
> | ||
<FiatRateWrapper>{rate}</FiatRateWrapper> | ||
</Tooltip> | ||
) : ( | ||
<NoRatesTooltip iconOnly={compact} /> | ||
) | ||
} | ||
</FiatValue> | ||
); | ||
}; | ||
export const PriceTicker = ({ symbol }: PriceTickerProps) => ( | ||
<FiatValue amount="1" symbol={symbol} showLoadingSkeleton> | ||
{({ rate, timestamp }) => | ||
rate && timestamp ? ( | ||
<LastUpdateTooltip timestamp={timestamp}> | ||
<FiatRateWrapper>{rate}</FiatRateWrapper> | ||
</LastUpdateTooltip> | ||
) : ( | ||
<NoRatesTooltip /> | ||
) | ||
} | ||
</FiatValue> | ||
); |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.