StakingRedeemable.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2017-2020 @polkadot/react-components 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 { DeriveStakingAccount } from '@polkadot/api-derive/types';
  5. import React from 'react';
  6. import { useAccounts } from '@polkadot/react-hooks';
  7. import { FormatBalance } from '@polkadot/react-query';
  8. import TxButton from './TxButton';
  9. import { useTranslation } from './translate';
  10. interface Props {
  11. className?: string;
  12. stakingInfo?: DeriveStakingAccount;
  13. }
  14. function StakingRedeemable ({ className, stakingInfo }: Props): React.ReactElement<Props> | null {
  15. const { allAccounts } = useAccounts();
  16. const { t } = useTranslation();
  17. if (!stakingInfo?.redeemable?.gtn(0)) {
  18. return null;
  19. }
  20. return (
  21. <div className={className}>
  22. <FormatBalance value={stakingInfo.redeemable}>
  23. {allAccounts.includes((stakingInfo.controllerId || '').toString()) && (
  24. <TxButton
  25. accountId={stakingInfo.controllerId}
  26. icon='lock'
  27. isIcon
  28. key='unlock'
  29. params={[]}
  30. tooltip={t('Withdraw these unlocked funds')}
  31. tx='staking.withdrawUnbonded'
  32. />
  33. )}
  34. </FormatBalance>
  35. </div>
  36. );
  37. }
  38. export default React.memo(StakingRedeemable);