date-fns#fromUnixTime TypeScript Examples
The following examples show how to use
date-fns#fromUnixTime.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: date.ts From ngx-gantt with MIT License | 6 votes |
constructor(date?: Date | string | number) {
if (date) {
if (date instanceof Date) {
this.value = date;
} else if (typeof date === 'string' || typeof date === 'number') {
if (date.toString().length < 13) {
this.value = fromUnixTime(+date);
} else {
this.value = new Date(date);
}
} else {
throw new Error(
`The input date type is not supported expect Date | string
| number | { date: number; with_time: 0 | 1}, actual ${JSON.stringify(date)}`
);
}
} else {
this.value = new Date();
}
}
Example #2
Source File: sign-xdr.component.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 5 votes |
dateFromEpoch(epoch: number): Date {
return fromUnixTime(epoch);
}
Example #3
Source File: xdr-signer.component.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 5 votes |
dateFromEpoch(epoch: number): Date {
return fromUnixTime(epoch);
}
Example #4
Source File: ClaimGraph.tsx From mStable-apps with GNU Lesser General Public License v3.0 | 5 votes |
timeFormatter =
(dateFormat: string) =>
(timestamp: unknown): string => {
if (typeof timestamp === 'number' && Number.isFinite(timestamp)) {
return format(fromUnixTime(timestamp), dateFormat)
}
return ''
}
Example #5
Source File: formatters.ts From mStable-apps with GNU Lesser General Public License v3.0 | 5 votes |
formatUnix = (unixTime: number, dateFormat = 'dd-MM-yyyy'): string => format(fromUnixTime(unixTime), dateFormat)
Example #6
Source File: index.tsx From glide-frontend with GNU General Public License v3.0 | 4 votes |
Overview: React.FC = () => {
const { t } = useTranslation()
const [liquidityHover, setLiquidityHover] = useState<number | undefined>()
const [liquidityDateHover, setLiquidityDateHover] = useState<string | undefined>()
const [volumeHover, setVolumeHover] = useState<number | undefined>()
const [volumeDateHover, setVolumeDateHover] = useState<string | undefined>()
const [protocolData] = useProtocolData()
const [chartData] = useProtocolChartData()
const [transactions] = useProtocolTransactions()
const currentDate = format(new Date(), 'MMM d, yyyy')
// Getting latest liquidity and volumeUSD to display on top of chart when not hovered
useEffect(() => {
if (volumeHover == null && protocolData) {
setVolumeHover(protocolData.volumeUSD)
}
}, [protocolData, volumeHover])
useEffect(() => {
if (liquidityHover == null && protocolData) {
setLiquidityHover(protocolData.liquidityUSD)
}
}, [liquidityHover, protocolData])
const formattedLiquidityData = useMemo(() => {
if (chartData) {
return chartData.map((day) => {
return {
time: fromUnixTime(day.date),
value: day.liquidityUSD,
}
})
}
return []
}, [chartData])
const formattedVolumeData = useMemo(() => {
if (chartData) {
return chartData.map((day) => {
return {
time: fromUnixTime(day.date),
value: day.volumeUSD,
}
})
}
return []
}, [chartData])
const allTokens = useAllTokenData()
const formattedTokens = useMemo(() => {
return Object.values(allTokens)
.map((token) => token.data)
.filter((token) => token)
}, [allTokens])
const allPoolData = useAllPoolData()
const poolDatas = useMemo(() => {
return Object.values(allPoolData)
.map((pool) => pool.data)
.filter((pool) => pool)
}, [allPoolData])
const somePoolsAreLoading = useMemo(() => {
return Object.values(allPoolData).some((pool) => !pool.data)
}, [allPoolData])
return (
<Page>
<Heading scale="lg" mb="16px" id="info-overview-title">
{t('Glide Info & Analytics')}
</Heading>
<ChartCardsContainer>
<Card>
<Box p={['16px', '16px', '24px']}>
<Text bold color="secondary">
{t('Liquidity')}
</Text>
{liquidityHover > 0 ? (
<Text bold fontSize="24px">
${formatAmount(liquidityHover)}
</Text>
) : (
<Skeleton width="128px" height="36px" />
)}
<Text>{liquidityDateHover ?? currentDate}</Text>
<Box height="250px">
<LineChart
data={formattedLiquidityData}
setHoverValue={setLiquidityHover}
setHoverDate={setLiquidityDateHover}
/>
</Box>
</Box>
</Card>
<Card>
<Box p={['16px', '16px', '24px']}>
<Text bold color="secondary">
{t('Volume 24H')}
</Text>
{volumeHover > 0 ? (
<Text bold fontSize="24px">
${formatAmount(volumeHover)}
</Text>
) : (
<Skeleton width="128px" height="36px" />
)}
<Text>{volumeDateHover ?? currentDate}</Text>
<Box height="250px">
<BarChart data={formattedVolumeData} setHoverValue={setVolumeHover} setHoverDate={setVolumeDateHover} />
</Box>
</Box>
</Card>
</ChartCardsContainer>
<Heading scale="lg" mt="40px" mb="16px">
{t('Top Tokens')}
</Heading>
<TokenTable tokenDatas={formattedTokens} />
<Heading scale="lg" mt="40px" mb="16px">
{t('Top Pools')}
</Heading>
<PoolTable poolDatas={poolDatas} loading={somePoolsAreLoading} />
<Heading scale="lg" mt="40px" mb="16px">
{t('Transactions')}
</Heading>
<TransactionTable transactions={transactions} />
</Page>
)
}
Example #7
Source File: index.tsx From glide-frontend with GNU General Public License v3.0 | 4 votes |
ChartCard: React.FC<ChartCardProps> = ({ variant, chartData, tokenData, tokenPriceData }) => {
const [view, setView] = useState(ChartView.PRICE)
const [hoverValue, setHoverValue] = useState<number | undefined>()
const [hoverDate, setHoverDate] = useState<string | undefined>()
const { t } = useTranslation()
const currentDate = format(new Date(), 'MMM d, yyyy')
const formattedTvlData = useMemo(() => {
if (chartData) {
return chartData.map((day) => {
return {
time: fromUnixTime(day.date),
value: day.liquidityUSD,
}
})
}
return []
}, [chartData])
const formattedVolumeData = useMemo(() => {
if (chartData) {
return chartData.map((day) => {
return {
time: fromUnixTime(day.date),
value: day.volumeUSD,
}
})
}
return []
}, [chartData])
const getLatestValueDisplay = () => {
let valueToDisplay = null
if (hoverValue) {
valueToDisplay = formatAmount(hoverValue)
} else if (view === ChartView.VOLUME && formattedVolumeData.length > 0) {
valueToDisplay = formatAmount(formattedVolumeData[formattedVolumeData.length - 1]?.value)
} else if (view === ChartView.LIQUIDITY && formattedTvlData.length > 0) {
valueToDisplay = formatAmount(formattedTvlData[formattedTvlData.length - 1]?.value)
} else if (view === ChartView.PRICE && tokenData?.priceUSD) {
valueToDisplay = formatAmount(tokenData.priceUSD)
}
return valueToDisplay ? (
<Text fontSize="24px" bold>
${valueToDisplay}
</Text>
) : (
<Skeleton height="36px" width="128px" />
)
}
return (
<Card>
<TabToggleGroup>
{variant === 'token' && (
<TabToggle isActive={view === ChartView.PRICE} onClick={() => setView(ChartView.PRICE)}>
<Text>{t('Price')}</Text>
</TabToggle>
)}
<TabToggle isActive={view === ChartView.VOLUME} onClick={() => setView(ChartView.VOLUME)}>
<Text>{t('Volume')}</Text>
</TabToggle>
<TabToggle isActive={view === ChartView.LIQUIDITY} onClick={() => setView(ChartView.LIQUIDITY)}>
<Text>{t('Liquidity')}</Text>
</TabToggle>
</TabToggleGroup>
<Flex flexDirection="column" px="24px" pt="24px">
{getLatestValueDisplay()}
<Text small color="secondary">
{hoverDate || currentDate}
</Text>
</Flex>
<Box px="24px" height={variant === 'token' ? '250px' : '335px'}>
{view === ChartView.LIQUIDITY ? (
<LineChart data={formattedTvlData} setHoverValue={setHoverValue} setHoverDate={setHoverDate} />
) : view === ChartView.VOLUME ? (
<BarChart data={formattedVolumeData} setHoverValue={setHoverValue} setHoverDate={setHoverDate} />
) : view === ChartView.PRICE ? (
<CandleChart data={tokenPriceData} setValue={setHoverValue} setLabel={setHoverDate} />
) : null}
</Box>
</Card>
)
}
Example #8
Source File: UserRewards.tsx From mStable-apps with GNU Lesser General Public License v3.0 | 4 votes |
UserRewards: FC = () => {
const rewardStreams = useRewardStreams()
const isMasquerading = useIsMasquerading()
const feederVault = useSelectedFeederPoolVaultContract()
const saveVault = useSelectedSaveVaultContract()
const [selectedSaveVersion] = useSelectedSaveVersion()
const [showLockTable, toggleLockTable] = useToggle(true)
const propose = usePropose()
const contract = feederVault ?? saveVault
const showGraph = !!rewardStreams?.amounts?.total
const canClaim = !!rewardStreams?.amounts.unlocked || !!rewardStreams?.amounts.earned.unlocked
const headerTitles = ['Date unlocked', 'Amount'].map(t => ({ title: t }))
return (
<RewardsCard>
<div>
{showGraph ? (
<>
{showLockTable ? (
<GraphAndValues>
<ClaimGraph />
<RewardValues>
<RewardValue
title="Unclaimed"
label="Sent to you now"
value={rewardStreams?.amounts.earned.unlocked}
streamType={StreamType.Earned}
/>
<RewardValue
title="Unlocked"
label={(rewardStreams?.amounts.unlocked ?? 0) > 0 ? `Sent to you now` : `From previous claims`}
value={rewardStreams?.amounts.unlocked}
streamType={StreamType.Unlocked}
/>
<RewardValue
title="Locked"
label="From previous earnings"
value={(rewardStreams?.amounts.previewLocked ?? 0) + (rewardStreams?.amounts.locked ?? 0)}
streamType={StreamType.Locked}
/>
</RewardValues>
</GraphAndValues>
) : (
<CustomTable headerTitles={headerTitles}>
{rewardStreams?.lockedStreams?.map(stream => (
<TableRow key={stream.start} buttonTitle="View">
<TableCell width={75}>
{format(fromUnixTime(stream.finish), 'dd.MM.yy')}
<span> {format(fromUnixTime(stream.finish), 'HH:mm')}</span>
</TableCell>
<TableCell>
<p>{(stream.amount?.[2] ?? stream.amount?.[3])?.toFixed(2)} MTA</p>
</TableCell>
</TableRow>
))}
</CustomTable>
)}
<ClaimContainer>
<div>
<ToggleViewButton onClick={toggleLockTable}>{showLockTable ? `View Table` : `View Chart`}</ToggleViewButton>
</div>
{!isMasquerading && (
<ClaimButton
visible
valid={canClaim}
title="Claim Rewards"
handleSend={() => {
if (contract && rewardStreams) {
propose<Interfaces.BoostedVault, 'claimRewards(uint256,uint256)'>(
new TransactionManifest(contract, 'claimRewards(uint256,uint256)', rewardStreams.claimRange, {
present: 'Claiming rewards',
past: 'Claimed rewards',
}),
)
}
}}
/>
)}
</ClaimContainer>
</>
) : (
<EmptyState>
<h3>No rewards to claim</h3>
{selectedSaveVersion === 1 ? (
<p>Migrate your balance and deposit to the Vault to earn MTA rewards.</p>
) : (
<p>Deposit to the Vault to earn MTA rewards.</p>
)}
</EmptyState>
)}
</div>
</RewardsCard>
)
}
Example #9
Source File: index.tsx From vvs-ui with GNU General Public License v3.0 | 4 votes |
Overview: React.FC = () => {
const { t } = useTranslation()
const [liquidityHover, setLiquidityHover] = useState<number | undefined>()
const [liquidityDateHover, setLiquidityDateHover] = useState<string | undefined>()
const [volumeHover, setVolumeHover] = useState<number | undefined>()
const [volumeDateHover, setVolumeDateHover] = useState<string | undefined>()
const [protocolData] = useProtocolData()
const [chartData] = useProtocolChartData()
const [transactions] = useProtocolTransactions()
const currentDate = format(new Date(), 'MMM d, yyyy')
// Getting latest liquidity and volumeUSD to display on top of chart when not hovered
useEffect(() => {
if (volumeHover == null && protocolData) {
setVolumeHover(protocolData.volumeUSD)
}
}, [protocolData, volumeHover])
useEffect(() => {
if (liquidityHover == null && protocolData) {
setLiquidityHover(protocolData.liquidityUSD)
}
}, [liquidityHover, protocolData])
const formattedLiquidityData = useMemo(() => {
if (chartData) {
return chartData.map((day) => {
return {
time: fromUnixTime(day.date),
value: day.liquidityUSD,
}
})
}
return []
}, [chartData])
const formattedVolumeData = useMemo(() => {
if (chartData) {
return chartData.map((day) => {
return {
time: fromUnixTime(day.date),
value: day.volumeUSD,
}
})
}
return []
}, [chartData])
const allTokens = useAllTokenData()
const formattedTokens = useMemo(() => {
return Object.values(allTokens)
.map((token) => token.data)
.filter((token) => token)
}, [allTokens])
const allPoolData = useAllPoolData()
const poolDatas = useMemo(() => {
return Object.values(allPoolData)
.map((pool) => pool.data)
.filter((pool) => pool)
}, [allPoolData])
const somePoolsAreLoading = useMemo(() => {
return Object.values(allPoolData).some((pool) => !pool.data)
}, [allPoolData])
return (
<Page>
<Heading scale="lg" mb="16px" id="info-overview-title">
{t('VVS Info & Analytics')}
</Heading>
<ChartCardsContainer>
<Card>
<Box p={['16px', '16px', '24px']}>
<Text bold color="black">
{t('Liquidity')}
</Text>
{liquidityHover > 0 ? (
<Text bold fontSize="24px">
${formatAmount(liquidityHover)}
</Text>
) : (
<Skeleton width="128px" height="36px" />
)}
<Text color="darkGrey">{liquidityDateHover ?? currentDate}</Text>
<Box height="250px">
<LineChart
data={formattedLiquidityData}
setHoverValue={setLiquidityHover}
setHoverDate={setLiquidityDateHover}
/>
</Box>
</Box>
</Card>
<Card>
<Box p={['16px', '16px', '24px']}>
<Text bold color="black">
{t('Volume 24H')}
</Text>
{volumeHover > 0 ? (
<Text bold fontSize="24px">
${formatAmount(volumeHover)}
</Text>
) : (
<Skeleton width="128px" height="36px" />
)}
<Text color="darkGrey">{volumeDateHover ?? currentDate}</Text>
<Box height="250px">
<BarChart data={formattedVolumeData} setHoverValue={setVolumeHover} setHoverDate={setVolumeDateHover} />
</Box>
</Box>
</Card>
</ChartCardsContainer>
<Heading scale="lg" mt="40px" mb="16px">
{t('Top Tokens')}
</Heading>
<TokenTable tokenDatas={formattedTokens} />
<Heading scale="lg" mt="40px" mb="16px">
{t('Top Farms')}
</Heading>
<PoolTable poolDatas={poolDatas} loading={somePoolsAreLoading} />
<Heading scale="lg" mt="40px" mb="16px">
{t('Transactions')}
</Heading>
<TransactionTable transactions={transactions} />
</Page>
)
}
Example #10
Source File: index.tsx From vvs-ui with GNU General Public License v3.0 | 4 votes |
ChartCard: React.FC<ChartCardProps> = ({ variant, chartData, tokenData, tokenPriceData }) => {
const [view, setView] = useState(ChartView.VOLUME)
const [hoverValue, setHoverValue] = useState<number | undefined>()
const [hoverDate, setHoverDate] = useState<string | undefined>()
const { t } = useTranslation()
const currentDate = format(new Date(), 'MMM d, yyyy')
const formattedTvlData = useMemo(() => {
if (chartData) {
return chartData.map((day) => {
return {
time: fromUnixTime(day.date),
value: day.liquidityUSD,
}
})
}
return []
}, [chartData])
const formattedVolumeData = useMemo(() => {
if (chartData) {
return chartData.map((day) => {
return {
time: fromUnixTime(day.date),
value: day.volumeUSD,
}
})
}
return []
}, [chartData])
const getLatestValueDisplay = () => {
let valueToDisplay = null
if (hoverValue) {
valueToDisplay = formatAmount(hoverValue)
} else if (view === ChartView.VOLUME && formattedVolumeData.length > 0) {
valueToDisplay = formatAmount(formattedVolumeData[formattedVolumeData.length - 1]?.value)
} else if (view === ChartView.LIQUIDITY && formattedTvlData.length > 0) {
valueToDisplay = formatAmount(formattedTvlData[formattedTvlData.length - 1]?.value)
} else if (view === ChartView.PRICE && tokenData?.priceUSD) {
valueToDisplay = formatAmount(tokenData.priceUSD)
}
return valueToDisplay ? (
<Text fontSize="24px" bold>
${valueToDisplay}
</Text>
) : (
<Skeleton height="36px" width="128px" />
)
}
return (
<Card>
<TabToggleGroup>
<TabToggle isActive={view === ChartView.VOLUME} onClick={() => setView(ChartView.VOLUME)}>
<Text>{t('Volume')}</Text>
</TabToggle>
<TabToggle isActive={view === ChartView.LIQUIDITY} onClick={() => setView(ChartView.LIQUIDITY)}>
<Text>{t('Liquidity')}</Text>
</TabToggle>
{variant === 'token' && (
<TabToggle isActive={view === ChartView.PRICE} onClick={() => setView(ChartView.PRICE)}>
<Text>{t('Price')}</Text>
</TabToggle>
)}
</TabToggleGroup>
<Flex flexDirection="column" px="24px" pt="24px">
{getLatestValueDisplay()}
<Text small color="secondary">
{hoverDate || currentDate}
</Text>
</Flex>
<Box px="24px" height={variant === 'token' ? '250px' : '335px'}>
{view === ChartView.LIQUIDITY ? (
<LineChart data={formattedTvlData} setHoverValue={setHoverValue} setHoverDate={setHoverDate} />
) : view === ChartView.VOLUME ? (
<BarChart data={formattedVolumeData} setHoverValue={setHoverValue} setHoverDate={setHoverDate} />
) : view === ChartView.PRICE ? (
<CandleChart data={tokenPriceData} setValue={setHoverValue} setLabel={setHoverDate} />
) : null}
</Box>
</Card>
)
}