Available.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2017-2020 @polkadot/react-query authors & contributors
  2. // This software may be modified and distributed under the terms
  3. // of the Apache-2.0 license. See the LICENSE file for details.
  4. import { DeriveBalancesAll } from '@polkadot/api-derive/types';
  5. import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
  6. import React from 'react';
  7. import { useApi, useCall } from '@polkadot/react-hooks';
  8. import FormatBalance from './FormatBalance';
  9. interface Props {
  10. children?: React.ReactNode;
  11. className?: string;
  12. label?: React.ReactNode;
  13. params?: AccountId | AccountIndex | Address | string | Uint8Array | null;
  14. }
  15. function AvailableDisplay ({ children, className = '', label, params }: Props): React.ReactElement<Props> {
  16. const { api } = useApi();
  17. const allBalances = useCall<DeriveBalancesAll>(api.derive.balances.all, [params]);
  18. return (
  19. <FormatBalance
  20. className={className}
  21. label={label}
  22. value={allBalances?.availableBalance}
  23. >
  24. {children}
  25. </FormatBalance>
  26. );
  27. }
  28. export default React.memo(AvailableDisplay);