mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-10-25 04:35:01 +00:00
feat: initial Pezkuwi Apps rebrand from polkadot-apps
Rebranded terminology: - Polkadot → Pezkuwi - Kusama → Dicle - Westend → Zagros - Rococo → PezkuwiChain - Substrate → Bizinikiwi - parachain → teyrchain Custom logos with Kurdistan brand colors (#e6007a → #86e62a): - bizinikiwi-hexagon.svg - sora-bizinikiwi.svg - hezscanner.svg - heztreasury.svg - pezkuwiscan.svg - pezkuwistats.svg - pezkuwiassembly.svg - pezkuwiholic.svg
This commit is contained in:
commit
d21bfb1320
5867 files changed
+329019
No files matched your search
@@ -0,0 +1,67 @@
|
||||
// Copyright 2017-2025 @pezkuwi/react-hooks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiPromise } from '@pezkuwi/api';
|
||||
import type { BN } from '@pezkuwi/util';
|
||||
import type { Time } from '@pezkuwi/util/types';
|
||||
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { BN_MAX_INTEGER, BN_ONE, bnMin, bnToBn, extractTime } from '@pezkuwi/util';
|
||||
|
||||
import { createNamedHook } from './createNamedHook.js';
|
||||
import { useTranslation } from './translate.js';
|
||||
import { useBlockInterval } from './useBlockInterval.js';
|
||||
|
||||
type Result = [blockInterval: number, timeStr: string, time: Time];
|
||||
|
||||
export function calcBlockTime (blockTime: BN, blocks: BN, t: (key: string, options?: { replace: Record<string, unknown> }) => string): Result {
|
||||
// in the case of excessively large locks, limit to the max JS integer value
|
||||
const value = bnMin(BN_MAX_INTEGER, blockTime.mul(blocks)).toNumber();
|
||||
|
||||
// time calculations are using the absolute value (< 0 detection only on strings)
|
||||
const time = extractTime(Math.abs(value));
|
||||
const { days, hours, minutes, seconds } = time;
|
||||
|
||||
return [
|
||||
blockTime.toNumber(),
|
||||
`${value < 0 ? '+' : ''}${[
|
||||
days
|
||||
? (days > 1)
|
||||
? t('{{days}} days', { replace: { days } })
|
||||
: t('1 day')
|
||||
: null,
|
||||
hours
|
||||
? (hours > 1)
|
||||
? t('{{hours}} hrs', { replace: { hours } })
|
||||
: t('1 hr')
|
||||
: null,
|
||||
minutes
|
||||
? (minutes > 1)
|
||||
? t('{{minutes}} mins', { replace: { minutes } })
|
||||
: t('1 min')
|
||||
: null,
|
||||
seconds
|
||||
? (seconds > 1)
|
||||
? t('{{seconds}} s', { replace: { seconds } })
|
||||
: t('1 s')
|
||||
: null
|
||||
]
|
||||
.filter((s): s is string => !!s)
|
||||
.slice(0, 2)
|
||||
.join(' ')}`,
|
||||
time
|
||||
];
|
||||
}
|
||||
|
||||
function useBlockTimeImpl (blocks: number | BN = BN_ONE, apiOverride?: ApiPromise | null): Result {
|
||||
const { t } = useTranslation();
|
||||
const blockTime = useBlockInterval(apiOverride);
|
||||
|
||||
return useMemo(
|
||||
() => calcBlockTime(blockTime, bnToBn(blocks), t),
|
||||
[blockTime, blocks, t]
|
||||
);
|
||||
}
|
||||
|
||||
export const useBlockTime = createNamedHook('useBlockTime', useBlockTimeImpl);
|
||||
Reference in new issue
Block a user