Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions app/components/UI/Earn/hooks/useEarnToasts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type HapticNotificationMoment,
} from '../../../../util/haptics';
import React, { useCallback, useContext, useMemo } from 'react';
import { StyleSheet, View } from 'react-native';
import { strings } from '../../../../../locales/i18n';
import Icon, {
IconName,
Expand All @@ -19,6 +18,7 @@ import {
import { useAppThemeFromContext } from '../../../../util/theme';
import {
Spinner,
IconColor,
IconSize as ReactNativeDsIconSize,
Text,
TextColor,
Expand Down Expand Up @@ -66,7 +66,7 @@ interface EarnToastLabelOptions {
const getEarnToastLabels = ({
primary,
secondary,
primaryIsBold = false,
primaryIsBold = true,
}: EarnToastLabelOptions) => {
const labels = [
{
Expand Down Expand Up @@ -95,12 +95,6 @@ const EARN_TOASTS_DEFAULT_OPTIONS: Partial<EarnToastOptions> = {
hasNoTimeout: false,
};

const toastStyles = StyleSheet.create({
iconWrapper: {
marginRight: 16,
},
});

const useEarnToasts = (): {
showToast: (config: EarnToastOptions) => void;
EarnToastOptions: EarnToastOptionsConfig;
Expand Down Expand Up @@ -130,13 +124,11 @@ const useEarnToasts = (): {
iconColor: theme.colors.success.default,
hapticsType: NotificationMoment.Success,
startAccessory: (
<View style={toastStyles.iconWrapper}>
<Icon
name={IconName.Confirmation}
color={theme.colors.success.default}
size={IconSize.Lg}
/>
</View>
<Icon
name={IconName.Confirmation}
color={theme.colors.success.default}
size={IconSize.Lg}
/>
),
},
inProgress: {
Expand All @@ -146,9 +138,10 @@ const useEarnToasts = (): {
hapticsType: NotificationMoment.Warning,
hasNoTimeout: true,
startAccessory: (
<View style={toastStyles.iconWrapper}>
<Spinner spinnerIconProps={{ size: ReactNativeDsIconSize.Lg }} />
</View>
<Spinner
color={IconColor.IconDefault}
spinnerIconProps={{ size: ReactNativeDsIconSize.Lg }}
/>
),
},
error: {
Expand All @@ -158,13 +151,11 @@ const useEarnToasts = (): {
iconColor: theme.colors.error.default,
hapticsType: NotificationMoment.Error,
startAccessory: (
<View style={toastStyles.iconWrapper}>
<Icon
name={IconName.CircleX}
color={theme.colors.error.default}
size={IconSize.Lg}
/>
</View>
<Icon
name={IconName.CircleX}
color={theme.colors.error.default}
size={IconSize.Lg}
/>
),
},
}),
Expand Down Expand Up @@ -245,7 +236,6 @@ const useEarnToasts = (): {
...earnBaseToastOptions.error,
labelOptions: getEarnToastLabels({
primary: strings('stake.tron.unstaked_banner.error'),
primaryIsBold: true,
...(errors.length > 0 && {
secondary: (
<Text
Expand Down
2 changes: 0 additions & 2 deletions app/components/UI/Rewards/hooks/useRewardsToast.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,6 @@ describe('useRewardsToast', () => {
{ label: 'Winner title', isBold: true },
]);
expect(config.startAccessory).toBeDefined();
const { getByTestId } = render(config.startAccessory as ReactElement);
expect(getByTestId('rewards-nudge-start-accessory-box')).toBeDefined();
config.linkButtonOptions?.onPress?.();
config.closeButtonOptions?.onPress?.();
expect(onCta).toHaveBeenCalledTimes(1);
Expand Down
33 changes: 13 additions & 20 deletions app/components/UI/Rewards/hooks/useRewardsToast.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useCallback, useContext, useMemo } from 'react';
import { ActivityIndicator } from 'react-native';
import { Box } from '@metamask/design-system-react-native';
import { ToastContext } from '../../../../component-library/components/Toast';
import {
ButtonIconVariant,
Expand Down Expand Up @@ -131,9 +130,7 @@ const useRewardsToast = (): {
hasNoTimeout: true,
hapticsType: NotificationMoment.Warning,
startAccessory: (
<Box twClassName="p-1 mr-2">
<ActivityIndicator size="small" color={theme.colors.icon.default} />
</Box>
<ActivityIndicator size="small" color={theme.colors.icon.default} />
),
labelOptions: getRewardsToastLabels(title),
descriptionOptions: getRewardsToastDescriptionLabels(subtitle),
Expand Down Expand Up @@ -189,14 +186,12 @@ const useRewardsToast = (): {
hasNoTimeout: true,
hapticsType: NotificationMoment.Warning,
startAccessory: (
<Box twClassName="p-1 mr-2">
<RewardsNotificationIcon
name="notification"
width={24}
height={24}
color={theme.colors.warning.default}
/>
</Box>
<RewardsNotificationIcon
name="notification"
width={24}
height={24}
color={theme.colors.warning.default}
/>
),
labelOptions: getRewardsToastLabels(
strings('rewards.notifications_nudge.title'),
Expand Down Expand Up @@ -225,14 +220,12 @@ const useRewardsToast = (): {
hasNoTimeout: true,
hapticsType: NotificationMoment.Success,
startAccessory: (
<Box twClassName="p-1 mr-2">
<RewardsTrophyIcon
name="trophy"
width={24}
height={24}
color={theme.colors.success.default}
/>
</Box>
<RewardsTrophyIcon
name="trophy"
width={24}
height={24}
color={theme.colors.success.default}
/>
),
labelOptions: getRewardsToastLabels(title),
descriptionOptions: { description },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import {
Box,
IconColor as DsIconColor,
IconSize as DsIconSize,
Spinner,
Expand Down Expand Up @@ -85,12 +84,10 @@ export function buildQuickBuyToastOptions(
descriptionOptions,
closeButtonOptions,
startAccessory: (
<Box twClassName="pr-3">
<Spinner
color={DsIconColor.PrimaryDefault}
spinnerIconProps={{ size: DsIconSize.Lg }}
/>
</Box>
<Spinner
color={DsIconColor.IconDefault}
spinnerIconProps={{ size: DsIconSize.Lg }}
/>
),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ describe('GasFeeTokenToast', () => {
expect(mockShowToast).toHaveBeenCalledWith(
expect.objectContaining({
labelOptions: [
{ label: "You're paying this network fee with ", isBold: false },
{ label: matchingTokenSymbol, isBold: true },
{ label: '.', isBold: false },
{
label: `You're paying this network fee with ${matchingTokenSymbol}.`,
isBold: true,
},
],
variant: ToastVariants.Network,
networkImageSource: { uri: matchingTokenImage },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useContext, useEffect, useRef } from 'react';
import {
ToastContext,
ToastVariants,
ButtonIconVariant,
} from '../../../../../../component-library/components/Toast';
import { strings } from '../../../../../../../locales/i18n';
import { TransactionType } from '@metamask/transaction-controller';
Expand All @@ -13,7 +14,6 @@ import {
} from '../../../hooks/gas/useGasFeeToken';
import { useTransactionMetadataRequest } from '../../../hooks/transactions/useTransactionMetadataRequest';
import { IconName } from '../../../../../../component-library/components/Icons/Icon';
import { ButtonVariants } from '../../../../../../component-library/components/Buttons/Button';
import { useTokenWithBalance } from '../../../hooks/tokens/useTokenWithBalance';
import { getNetworkImageSource } from '../../../../../../util/networks';
import { hasTransactionType } from '../../../utils/transaction';
Expand Down Expand Up @@ -52,9 +52,10 @@ export function GasFeeTokenToast() {

toast.showToast({
labelOptions: [
{ label: strings('gas_fee_token_toast.message'), isBold: false },
{ label: `${gasFeeToken.symbol}`, isBold: true },
{ label: '.', isBold: false },
{
label: `${strings('gas_fee_token_toast.message')}${gasFeeToken.symbol}.`,
isBold: true,
},
],
variant: ToastVariants.Network,
hasNoTimeout: false,
Expand All @@ -63,18 +64,11 @@ export function GasFeeTokenToast() {
? { uri: tokenSelected.image }
: networkImageSource,
closeButtonOptions: {
variant: ButtonVariants.Primary,
endIconName: IconName.Close,
label: undefined,
variant: ButtonIconVariant.Icon,
iconName: IconName.Close,
onPress: () => {
toast?.closeToast();
},
style: {
backgroundColor: 'transparent',
paddingHorizontal: 4,
paddingVertical: 10,
height: 20,
},
},
});
}, [
Expand Down
Loading