ghost-portal/packages/page-staking2/src/Pools/useAmountError.ts
Tarik Gul 384049fb6b
2025 (#11172)
* 2025

* update ci scripts to add access to scripts
2025-01-03 03:59:53 +02:00

25 lines
924 B
TypeScript

// Copyright 2017-2025 @polkadot/app-staking authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { DeriveBalancesAll } from '@polkadot/api-derive/types';
import type { BN } from '@polkadot/util';
import { useMemo } from 'react';
import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks';
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(
() => !amount || amount.isZero() || !minAmount || minAmount.gt(amount) || (
!!balances &&
amount.gt((balances.transferable || balances.availableBalance).sub(api.consts.balances.existentialDeposit))
),
[api, amount, balances, minAmount]
);
}
export default createNamedHook('useAmountError', useAmountErrorImpl);