Skip to content

Commit

Permalink
Merge pull request #1489 from gabrielbazan7/ref/fee-msg
Browse files Browse the repository at this point in the history
[REF] improve not enough funds/fee err msg
  • Loading branch information
JohnathanWhite authored Dec 6, 2024
2 parents 19bb86e + 5617855 commit f3cd49b
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 154 deletions.
1 change: 1 addition & 0 deletions locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,7 @@
"Insufficient confirmed funds": "Insufficient confirmed funds",
"You do not have enough confirmed funds to make this payment. Wait for your pending transactions to confirm or enable \"Use unconfirmed funds\" in Advanced Settings.": "You do not have enough confirmed funds to make this payment. Wait for your pending transactions to confirm or enable \"Use unconfirmed funds\" in Advanced Settings.",
"Insufficient funds": "Insufficient funds",
"Insufficient funds in your linked wallet to cover the transaction fee.": "Insufficient funds in your linked {{linkedWalletAbbreviation}} wallet to cover the transaction fee.",
"No compatible wallets": "No compatible wallets",
"You currently don't have any wallets capable of sending this payment. Would you like to import one?": "You currently don't have any wallets capable of sending this payment. Would you like to import one?",
"Maybe Later": "Maybe Later",
Expand Down
21 changes: 14 additions & 7 deletions src/navigation/wallet/components/ErrorMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import styled from 'styled-components/native';
import {BaseText} from '../../../components/styled/Text';
import {FlatList} from 'react-native';
import {t} from 'i18next';
import {RootStacks, navigationRef} from '../../../Root';

interface BottomNotificationListType {
key: number;
Expand Down Expand Up @@ -116,25 +117,31 @@ export const WrongPasswordError = (): BottomNotificationConfig => {
export const CustomErrorMessage = ({
errMsg,
action = () => null,
cta,
title,
}: {
errMsg: string;
title?: string;
action?: () => void;
cta?: [{text: string; action: () => void; primary: boolean}];
}): BottomNotificationConfig => {
if (!cta) {
// set CTA with action if default
cta = [
{
text: t('OK'),
action,
primary: true,
},
];
}
return {
type: 'error',
title: title || t('Something went wrong'),
message: errMsg,
enableBackdropDismiss: true,
onBackdropDismiss: action,
actions: [
{
text: t('OK'),
action,
primary: true,
},
],
actions: cta,
};
};

Expand Down
6 changes: 0 additions & 6 deletions src/navigation/wallet/screens/AccountDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -895,12 +895,6 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
showBottomNotificationModal({
...errorMessageConfig,
enableBackdropDismiss: false,
actions: [
{
text: t('OK'),
action: () => {},
},
],
}),
);
}
Expand Down
11 changes: 1 addition & 10 deletions src/navigation/wallet/screens/GlobalSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ const GlobalSelect: React.FC<GlobalSelectScreenProps | GlobalSelectProps> = ({
dispatch(LogActions.error('[GlobalSelect] ' + errStr));
if (setButtonState) {
setButtonState('failed');
sleep(1000).then(() => setButtonState?.(null));
} else {
dispatch(dismissOnGoingProcessModal());
}
Expand All @@ -994,16 +995,6 @@ const GlobalSelect: React.FC<GlobalSelectScreenProps | GlobalSelectProps> = ({
showBottomNotificationModal({
...errorMessageConfig,
enableBackdropDismiss: false,
actions: [
{
text: t('OK'),
action: () => {
if (setButtonState) {
setButtonState(undefined);
}
},
},
],
}),
);
}
Expand Down
6 changes: 0 additions & 6 deletions src/navigation/wallet/screens/SelectInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,6 @@ const SelectInputs = () => {
showBottomNotificationModal({
...errorMessageConfig,
enableBackdropDismiss: false,
actions: [
{
text: t('OK'),
action: () => {},
},
],
}),
);
}
Expand Down
6 changes: 0 additions & 6 deletions src/navigation/wallet/screens/SendToOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,6 @@ const SendToOptions = () => {
showBottomNotificationModal({
...errorMessageConfig,
enableBackdropDismiss: false,
actions: [
{
text: t('OK'),
action: () => {},
},
],
}),
);
}
Expand Down
6 changes: 0 additions & 6 deletions src/navigation/wallet/screens/TransactionDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,6 @@ const TransactionDetails = () => {
showBottomNotificationModal({
...errorMessageConfig,
enableBackdropDismiss: false,
actions: [
{
text: t('OK'),
action: () => {},
},
],
}),
);
}
Expand Down
6 changes: 0 additions & 6 deletions src/navigation/wallet/screens/WalletDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -791,12 +791,6 @@ const WalletDetails: React.FC<WalletDetailsScreenProps> = ({route}) => {
showBottomNotificationModal({
...errorMessageConfig,
enableBackdropDismiss: false,
actions: [
{
text: t('OK'),
action: () => {},
},
],
}),
);
}
Expand Down
15 changes: 9 additions & 6 deletions src/navigation/wallet/screens/send/confirm/BillConfirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,18 @@ const BillConfirm: React.VFC<
const handleBillPayInvoiceOrTxpError = async (err: any) => {
await sleep(400);
dispatch(dismissOnGoingProcessModal());
const onDismiss = () => openWalletSelector(400);
const [errorConfig] = await Promise.all([
dispatch(handleCreateTxProposalError(err)),
dispatch(handleCreateTxProposalError(err, onDismiss)),
sleep(500),
]);
showError({
defaultErrorMessage:
err.response?.data?.message || err.message || errorConfig.message,
onDismiss: () => openWalletSelector(400),
});
dispatch(
AppActions.showBottomNotificationModal({
...errorConfig,
errMsg:
err.response?.data?.message || err.message || errorConfig.message,
}),
);
};

const onCoinbaseAccountSelect = async (walletRowProps: WalletRowProps) => {
Expand Down
6 changes: 0 additions & 6 deletions src/navigation/wallet/screens/send/confirm/Confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,6 @@ const Confirm = () => {
showBottomNotificationModal({
...errorMessageConfig,
enableBackdropDismiss: false,
actions: [
{
text: t('OK'),
action: () => {},
},
],
}),
);
}
Expand Down
39 changes: 24 additions & 15 deletions src/navigation/wallet/screens/send/confirm/GiftCardConfirm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import Transport from '@ledgerhq/hw-transport';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import {useNavigation, useRoute} from '@react-navigation/native';
import {
useNavigation,
useRoute,
useFocusEffect,
} from '@react-navigation/native';
import styled from 'styled-components/native';
import {Hr} from '../../../../../components/styled/Containers';
import {RouteProp, StackActions} from '@react-navigation/core';
Expand Down Expand Up @@ -323,20 +327,23 @@ const Confirm = () => {
const handleCreateGiftCardInvoiceOrTxpError = async (err: any) => {
await sleep(400);
dispatch(dismissOnGoingProcessModal());
const onDismiss = () => {
if (err.message === GiftCardInvoiceCreationErrors.couponExpired) {
return popToShopHome();
}
return openWalletSelector(400);
};
const [errorConfig] = await Promise.all([
dispatch(handleCreateTxProposalError(err)),
dispatch(handleCreateTxProposalError(err, onDismiss)),
sleep(500),
]);
showError({
defaultErrorMessage:
err.response?.data?.message || err.message || errorConfig.message,
onDismiss: () => {
if (err.message === GiftCardInvoiceCreationErrors.couponExpired) {
return popToShopHome();
}
return openWalletSelector(400);
},
});
dispatch(
AppActions.showBottomNotificationModal({
...errorConfig,
errMsg:
err.response?.data?.message || err.message || errorConfig.message,
}),
);
};

const onCoinbaseAccountSelect = async (walletRowProps: WalletRowProps) => {
Expand Down Expand Up @@ -626,9 +633,11 @@ const Confirm = () => {
return () => clearTimeout(timer);
}, [resetSwipeButton]);

useEffect(() => {
openWalletSelector(100);
}, []);
useFocusEffect(
useCallback(() => {
openWalletSelector(100);
}, []),
);

return (
<ConfirmContainer>
Expand Down
51 changes: 27 additions & 24 deletions src/navigation/wallet/screens/send/confirm/PayProConfirm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Transport from '@ledgerhq/hw-transport';
import {RouteProp, StackActions} from '@react-navigation/core';
import {useNavigation, useRoute} from '@react-navigation/native';
import {
useNavigation,
useRoute,
useFocusEffect,
} from '@react-navigation/native';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {useTranslation} from 'react-i18next';
import {WalletScreens, WalletGroupParamList} from '../../../WalletGroup';
Expand Down Expand Up @@ -244,28 +248,29 @@ const PayProConfirm = () => {
} catch (err: any) {
await sleep(400);
dispatch(dismissOnGoingProcessModal());
const onDismiss = () =>
wallet ? navigation.goBack() : reshowWalletSelector();
const [errorConfig] = await Promise.all([
dispatch(handleCreateTxProposalError(err)),
dispatch(handleCreateTxProposalError(err, onDismiss)),
sleep(500),
]);
dispatch(
AppActions.showBottomNotificationModal(
CustomErrorMessage({
title: t('Error'),
errMsg:
err.response?.data?.message || err.message || errorConfig.message,
action: () =>
wallet ? navigation.goBack() : reshowWalletSelector(),
}),
),
AppActions.showBottomNotificationModal({
...errorConfig,
errMsg:
err.response?.data?.message || err.message || errorConfig.message,
}),
);
}
};

useEffect(() => {
wallet ? createTxp(wallet) : setTimeout(() => openKeyWalletSelector(), 500);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useFocusEffect(
useCallback(() => {
wallet
? createTxp(wallet)
: setTimeout(() => openKeyWalletSelector(), 500);
}, []),
);

const openKeyWalletSelector = () => {
setWalletSelectorVisible(true);
Expand All @@ -274,19 +279,17 @@ const PayProConfirm = () => {
const handleTxpError = async (err: any) => {
await sleep(400);
dispatch(dismissOnGoingProcessModal());
const onDismiss = () => reshowWalletSelector();
const [errorConfig] = await Promise.all([
dispatch(handleCreateTxProposalError(err)),
dispatch(handleCreateTxProposalError(err, onDismiss)),
sleep(500),
]);
dispatch(
AppActions.showBottomNotificationModal(
CustomErrorMessage({
title: t('Error'),
errMsg:
err.response?.data?.message || err.message || errorConfig.message,
action: () => reshowWalletSelector(),
}),
),
AppActions.showBottomNotificationModal({
...errorConfig,
errMsg:
err.response?.data?.message || err.message || errorConfig.message,
}),
);
};

Expand Down
12 changes: 1 addition & 11 deletions src/store/scan/scan.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ const goToConfirm =
} catch (err: any) {
if (setButtonState) {
setButtonState('failed');
sleep(1000).then(() => setButtonState?.(null));
} else {
dispatch(dismissOnGoingProcessModal());
}
Expand All @@ -571,17 +572,6 @@ const goToConfirm =
dispatch(
showBottomNotificationModal({
...errorMessageConfig,
enableBackdropDismiss: false,
actions: [
{
text: 'OK',
action: () => {
if (setButtonState) {
setButtonState(undefined);
}
},
},
],
}),
);
}
Expand Down
Loading

0 comments on commit f3cd49b

Please sign in to comment.