diff --git a/web/cashtab/src/components/Common/Notifications.js b/web/cashtab/src/components/Common/Notifications.js
new file mode 100644
--- /dev/null
+++ b/web/cashtab/src/components/Common/Notifications.js
@@ -0,0 +1,133 @@
+import * as React from 'react';
+import { notification } from 'antd';
+import {
+ CashReceivedNotificationIcon,
+ TokenReceivedNotificationIcon,
+} from '@components/Common/CustomIcons';
+import Paragraph from 'antd/lib/typography/Paragraph';
+import { currency } from '@components/Common/Ticker';
+
+// Success Notifications:
+const sendXecNotification = link => {
+ notification.success({
+ message: 'Success',
+ description: (
+
+
+ Transaction successful. Click to view in block explorer.
+
+
+ ),
+ duration: 3,
+ icon: ,
+ style: { width: '100%' },
+ });
+};
+
+const createTokenNotification = link => {
+ notification.success({
+ message: 'Success',
+ description: (
+
+
+ Token created! Click to view in block explorer.
+
+
+ ),
+ icon: ,
+ style: { width: '100%' },
+ });
+};
+
+const sendTokenNotification = link => {
+ notification.success({
+ message: 'Success',
+ description: (
+
+
+ Transaction successful. Click to view in block explorer.
+
+
+ ),
+ duration: 3,
+ icon: ,
+ style: { width: '100%' },
+ });
+};
+
+const xecReceivedNotification = (
+ balances,
+ previousBalances,
+ cashtabSettings,
+ fiatPrice,
+) => {
+ notification.success({
+ message: 'Transaction received',
+ description: (
+
+ +{' '}
+ {parseFloat(
+ Number(
+ balances.totalBalance - previousBalances.totalBalance,
+ ).toFixed(currency.cashDecimals),
+ ).toLocaleString()}{' '}
+ {currency.ticker}{' '}
+ {cashtabSettings &&
+ cashtabSettings.fiatCurrency &&
+ `(${
+ currency.fiatCurrencies[cashtabSettings.fiatCurrency]
+ .symbol
+ }${(
+ Number(
+ balances.totalBalance -
+ previousBalances.totalBalance,
+ ) * fiatPrice
+ ).toFixed(
+ currency.cashDecimals,
+ )} ${cashtabSettings.fiatCurrency.toUpperCase()})`}
+
+ ),
+ duration: 3,
+ icon: ,
+ style: { width: '100%' },
+ });
+};
+
+const eTokenReceivedNotification = (
+ currency,
+ receivedSlpTicker,
+ receivedSlpQty,
+ receivedSlpName,
+) => {
+ notification.success({
+ message: `${currency.tokenTicker} transaction received: ${receivedSlpTicker}`,
+ description: (
+
+ You received {receivedSlpQty.toString()} {receivedSlpName}
+
+ ),
+ duration: 3,
+ icon: ,
+ style: { width: '100%' },
+ });
+};
+
+// Error Notification:
+
+const errorNotification = (error, message, stringDescribingCallEvent) => {
+ console.log(error, message, stringDescribingCallEvent);
+ notification.error({
+ message: 'Error',
+ description: message,
+ duration: 5,
+ });
+};
+
+export {
+ sendXecNotification,
+ createTokenNotification,
+ sendTokenNotification,
+ xecReceivedNotification,
+ eTokenReceivedNotification,
+ errorNotification,
+};
diff --git a/web/cashtab/src/components/Send/Send.js b/web/cashtab/src/components/Send/Send.js
--- a/web/cashtab/src/components/Send/Send.js
+++ b/web/cashtab/src/components/Send/Send.js
@@ -3,7 +3,6 @@
import { WalletContext } from '@utils/context';
import { Form, notification, message, Modal, Alert } from 'antd';
import { Row, Col } from 'antd';
-import Paragraph from 'antd/lib/typography/Paragraph';
import PrimaryButton, {
SecondaryButton,
} from '@components/Common/PrimaryButton';
@@ -13,6 +12,10 @@
} from '@components/Common/EnhancedInputs';
import useBCH from '@hooks/useBCH';
import useWindowDimensions from '@hooks/useWindowDimensions';
+import {
+ sendXecNotification,
+ errorNotification,
+} from '@components/Common/Notifications';
import { isMobile, isIOS, isSafari } from 'react-device-detect';
import {
currency,
@@ -30,7 +33,6 @@
AlertMsg,
} from '@components/Common/Atoms';
import { getWalletState } from '@utils/cashMethods';
-import { CashReceivedNotificationIcon } from '@components/Common/CustomIcons';
import ApiError from '@components/Common/ApiError';
// Note jestBCH is only used for unit tests; BCHJS must be mocked for jest
@@ -192,21 +194,7 @@
bchValue,
currency.defaultFee,
);
-
- notification.success({
- message: 'Success',
- description: (
-
-
- Transaction successful. Click to view in block
- explorer.
-
-
- ),
- duration: 3,
- icon: ,
- style: { width: '100%' },
- });
+ sendXecNotification(link);
} catch (e) {
// Set loading to false here as well, as balance may not change depending on where error occured in try loop
passLoadingStatus(false);
@@ -231,12 +219,7 @@
message = e.message || e.error || JSON.stringify(e);
}
- notification.error({
- message: 'Error',
- description: message,
- duration: 5,
- });
- console.error(e);
+ errorNotification(e, message, 'Sending XEC');
}
}
diff --git a/web/cashtab/src/components/Send/SendToken.js b/web/cashtab/src/components/Send/SendToken.js
--- a/web/cashtab/src/components/Send/SendToken.js
+++ b/web/cashtab/src/components/Send/SendToken.js
@@ -10,7 +10,6 @@
Alert,
Descriptions,
} from 'antd';
-import Paragraph from 'antd/lib/typography/Paragraph';
import PrimaryButton, {
SecondaryButton,
} from '@components/Common/PrimaryButton';
@@ -36,8 +35,11 @@
getWalletState,
convertEtokenToSimpleledger,
} from '@utils/cashMethods';
-import { TokenReceivedNotificationIcon } from '@components/Common/CustomIcons';
import ApiError from '@components/Common/ApiError';
+import {
+ sendTokenNotification,
+ errorNotification,
+} from '@components/Common/Notifications';
const SendToken = ({ tokenId, jestBCH, passLoadingStatus }) => {
const { wallet, apiError } = React.useContext(WalletContext);
@@ -114,20 +116,7 @@
amount: value,
});
- notification.success({
- message: 'Success',
- description: (
-
-
- Transaction successful. Click to view in block
- explorer.
-
-
- ),
- duration: 3,
- icon: ,
- style: { width: '100%' },
- });
+ sendTokenNotification(link);
} catch (e) {
passLoadingStatus(false);
let message;
@@ -143,13 +132,7 @@
} else {
message = e.message || e.error || JSON.stringify(e);
}
- console.log(e);
- notification.error({
- message: 'Error',
- description: message,
- duration: 3,
- });
- console.error(e);
+ errorNotification(e, message, 'Sending eToken');
}
}
diff --git a/web/cashtab/src/components/Tokens/CreateTokenForm.js b/web/cashtab/src/components/Tokens/CreateTokenForm.js
--- a/web/cashtab/src/components/Tokens/CreateTokenForm.js
+++ b/web/cashtab/src/components/Tokens/CreateTokenForm.js
@@ -15,9 +15,11 @@
import { SmartButton } from '@components/Common/PrimaryButton';
import { Collapse, Form, Input, Modal, notification } from 'antd';
const { Panel } = Collapse;
-import Paragraph from 'antd/lib/typography/Paragraph';
import { TokenParamLabel } from '@components/Common/Atoms';
-import { TokenReceivedNotificationIcon } from '@components/Common/CustomIcons';
+import {
+ createTokenNotification,
+ errorNotification,
+} from '@components/Common/Notifications';
const CreateTokenForm = ({
BCH,
@@ -136,19 +138,7 @@
currency.defaultFee,
configObj,
);
-
- notification.success({
- message: 'Success',
- description: (
-
-
- Token created! Click to view in block explorer.
-
-
- ),
- icon: ,
- style: { width: '100%' },
- });
+ createTokenNotification(link);
} catch (e) {
// Set loading to false here as well, as balance may not change depending on where error occured in try loop
passLoadingStatus(false);
@@ -172,13 +162,7 @@
} else {
message = e.message || e.error || JSON.stringify(e);
}
-
- notification.error({
- message: 'Error',
- description: message,
- duration: 5,
- });
- console.error(e);
+ errorNotification(e, message, 'Creating eToken');
}
// Hide the modal
setShowConfirmCreateToken(false);
diff --git a/web/cashtab/src/hooks/useWallet.js b/web/cashtab/src/hooks/useWallet.js
--- a/web/cashtab/src/hooks/useWallet.js
+++ b/web/cashtab/src/hooks/useWallet.js
@@ -17,11 +17,14 @@
import { currency } from '@components/Common/Ticker';
import isEmpty from 'lodash.isempty';
import isEqual from 'lodash.isequal';
+import {
+ xecReceivedNotification,
+ eTokenReceivedNotification,
+} from '@components/Common/Notifications';
import {
CashReceivedNotificationIcon,
TokenReceivedNotificationIcon,
} from '@components/Common/CustomIcons';
-
const useWallet = () => {
const [wallet, setWallet] = useState(false);
const [cashtabSettings, setCashtabSettings] = useState(false);
@@ -900,38 +903,12 @@
.minus(previousBalances.totalBalance)
.gt(0)
) {
- notification.success({
- message: 'Transaction received',
- description: (
-
- +{' '}
- {parseFloat(
- Number(
- balances.totalBalance -
- previousBalances.totalBalance,
- ).toFixed(currency.cashDecimals),
- ).toLocaleString()}{' '}
- {currency.ticker}{' '}
- {cashtabSettings &&
- cashtabSettings.fiatCurrency &&
- `(${
- currency.fiatCurrencies[
- cashtabSettings.fiatCurrency
- ].symbol
- }${(
- Number(
- balances.totalBalance -
- previousBalances.totalBalance,
- ) * fiatPrice
- ).toFixed(
- currency.cashDecimals,
- )} ${cashtabSettings.fiatCurrency.toUpperCase()})`}
-
- ),
- duration: 3,
- icon: ,
- style: { width: '100%' },
- });
+ xecReceivedNotification(
+ balances,
+ previousBalances,
+ cashtabSettings,
+ fiatPrice,
+ );
}
// Parse for incoming eToken transactions
@@ -987,19 +964,13 @@
// Notification if you received SLP
if (receivedSlpQty > 0) {
- notification.success({
- message: `${currency.tokenTicker} transaction received: ${receivedSlpTicker}`,
- description: (
-
- You received {receivedSlpQty} {receivedSlpName}
-
- ),
- duration: 3,
- icon: ,
- style: { width: '100%' },
- });
+ eTokenReceivedNotification(
+ currency,
+ receivedSlpTicker,
+ receivedSlpQty,
+ receivedSlpName,
+ );
}
-
//
} else {
// If tokens[i].balance > previousTokens[i].balance, a new SLP tx of an existing token has been received
@@ -1025,18 +996,12 @@
const receivedSlpTicker = tokens[i].info.tokenTicker;
const receivedSlpName = tokens[i].info.tokenName;
- notification.success({
- message: `${currency.tokenTicker} transaction received: ${receivedSlpTicker}`,
- description: (
-
- You received {receivedSlpQty.toString()}{' '}
- {receivedSlpName}
-
- ),
- duration: 3,
- icon: ,
- style: { width: '100%' },
- });
+ eTokenReceivedNotification(
+ currency,
+ receivedSlpTicker,
+ receivedSlpQty,
+ receivedSlpName,
+ );
}
}
}