mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-06-14 05:11:10 +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:
@@ -0,0 +1,43 @@
|
||||
// Copyright 2017-2025 @pezkuwi/app-staking authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { DeriveBalancesAll } from '@pezkuwi/api-derive/types';
|
||||
import type { BN } from '@pezkuwi/util';
|
||||
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { createNamedHook, useApi, useCall } from '@pezkuwi/react-hooks';
|
||||
import { BN_ZERO, hexToString } from '@pezkuwi/util';
|
||||
|
||||
// Consider only OpenGov-related locks
|
||||
const openGovLockIds = ['referenda', 'convictionVoting', 'pyconvot'];
|
||||
|
||||
function useAmountErrorImpl (accountId?: string | null, amount?: BN | null, minAmount?: BN | null): boolean {
|
||||
const { api } = useApi();
|
||||
const balances = useCall<DeriveBalancesAll>(!!accountId && api.derive.balances.all, [accountId]);
|
||||
|
||||
return useMemo(
|
||||
() => {
|
||||
if (!amount || amount.isZero() || !minAmount || minAmount.gt(amount) || !balances) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Filter out OpenGov-related locks (those that don't prevent staking)
|
||||
const openGovLocks = balances.lockedBreakdown.filter((lock) => {
|
||||
return openGovLockIds.includes(hexToString(lock.id.toHex()));
|
||||
});
|
||||
|
||||
// Total locked amount that affects staking
|
||||
const openGovLockedBalance = openGovLocks.reduce((acc, lock) => acc.add(lock.amount), BN_ZERO);
|
||||
|
||||
const usableBalance = (balances.transferable || balances.availableBalance)
|
||||
.add(openGovLockedBalance)
|
||||
.sub(api.consts.balances.existentialDeposit);
|
||||
|
||||
return amount.gt(usableBalance);
|
||||
},
|
||||
[api, amount, balances, minAmount]
|
||||
);
|
||||
}
|
||||
|
||||
export default createNamedHook('useAmountError', useAmountErrorImpl);
|
||||
Reference in New Issue
Block a user