-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathTronUnstakedBanner.tsx
More file actions
68 lines (63 loc) · 2.36 KB
/
TronUnstakedBanner.tsx
File metadata and controls
68 lines (63 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import React, { useEffect } from 'react';
import { useSelector } from 'react-redux';
import type { CaipChainId } from '@metamask/utils';
import { strings } from '../../../../../../../locales/i18n';
import Banner, {
BannerAlertSeverity,
BannerVariant,
} from '../../../../../../component-library/components/Banners/Banner';
import {
Text,
Button,
ButtonVariant,
ButtonSize,
} from '@metamask/design-system-react-native';
import useTronClaimUnstakedTrx from '../../../hooks/useTronClaimUnstakedTrx';
import useEarnToasts from '../../../hooks/useEarnToasts';
import { selectTronClaimUnstakedTrxButtonEnabled } from '../../../../../../selectors/featureFlagController/tronClaimUnstakedTrxButtonEnabled';
import { TronUnstakedBannerTestIds } from './TronUnstakedBanner.testIds';
interface TronUnstakedBannerProps {
amount: string;
chainId: CaipChainId;
}
const TronUnstakedBanner = ({ amount, chainId }: TronUnstakedBannerProps) => {
const showClaimButton = useSelector(selectTronClaimUnstakedTrxButtonEnabled);
const { handleClaimUnstakedTrx, isSubmitting, errors } =
useTronClaimUnstakedTrx({ chainId });
const { showToast, EarnToastOptions } = useEarnToasts();
useEffect(() => {
if (errors) {
showToast(EarnToastOptions.tronWithdrawal.failed(errors));
}
// eslint-disable-next-line react-hooks/exhaustive-deps -- Only re-fire when a new error occurs; showToast/EarnToastOptions refs change on theme switch and would cause repeat toasts.
}, [errors]);
return (
<Banner
title={strings('stake.tron.unstaked_banner.title', { amount })}
severity={BannerAlertSeverity.Success}
variant={BannerVariant.Alert}
description={
<>
<Text
testID={TronUnstakedBannerTestIds.BANNER_DESCRIPTION}
twClassName={showClaimButton ? 'pt-1 pb-4' : 'pt-1'}
>
{strings('stake.tron.unstaked_banner.description')}
</Text>
{showClaimButton ? (
<Button
testID={TronUnstakedBannerTestIds.CLAIM_BUTTON}
variant={ButtonVariant.Primary}
size={ButtonSize.Md}
onPress={handleClaimUnstakedTrx}
isDisabled={isSubmitting}
>
{strings('stake.tron.unstaked_banner.button')}
</Button>
) : null}
</>
}
/>
);
};
export default TronUnstakedBanner;