From 00ab6961699d4ef522ce046863374ea4ad7bf74b Mon Sep 17 00:00:00 2001 From: Ji Young Lee <641712+jiyounglee@users.noreply.github.com> Date: Thu, 17 Oct 2024 14:05:03 +1100 Subject: [PATCH] [NO CHANGELOG] [Add Funds Widget] Display error when environment is not set to prod (#2323) --- .../widgets-lib/src/widgets/add-funds/AddFundsWidget.tsx | 6 ++++++ .../widgets-lib/src/widgets/add-funds/hooks/useError.tsx | 6 ++++++ .../checkout/widgets-lib/src/widgets/add-funds/types.ts | 1 + 3 files changed, 13 insertions(+) diff --git a/packages/checkout/widgets-lib/src/widgets/add-funds/AddFundsWidget.tsx b/packages/checkout/widgets-lib/src/widgets/add-funds/AddFundsWidget.tsx index daeac2d2c2..e207b39c85 100644 --- a/packages/checkout/widgets-lib/src/widgets/add-funds/AddFundsWidget.tsx +++ b/packages/checkout/widgets-lib/src/widgets/add-funds/AddFundsWidget.tsx @@ -100,6 +100,12 @@ export default function AddFundsWidget({ checkout.config.environment ?? Environment.SANDBOX, ); + useEffect(() => { + if (config.environment !== Environment.PRODUCTION) { + showErrorHandover(AddFundsErrorTypes.ENVIRONMENT_ERROR); + } + }, [config]); + useEffect(() => { const isInvalidToTokenAddress = toTokenAddress && !isValidAddress(toTokenAddress); const isInvalidToAmount = toAmount && !amountInputValidation(toAmount); diff --git a/packages/checkout/widgets-lib/src/widgets/add-funds/hooks/useError.tsx b/packages/checkout/widgets-lib/src/widgets/add-funds/hooks/useError.tsx index b0b86a3ac4..2adda37980 100644 --- a/packages/checkout/widgets-lib/src/widgets/add-funds/hooks/useError.tsx +++ b/packages/checkout/widgets-lib/src/widgets/add-funds/hooks/useError.tsx @@ -118,6 +118,12 @@ export const useError = (environment: Environment) => { secondaryButtonText: 'Close', onSecondaryButtonClick: goBackToAddFundsView, }, + [AddFundsErrorTypes.ENVIRONMENT_ERROR]: { + headingText: 'Unsupported environment', + subHeadingText: 'This is only supported in production environment.', + secondaryButtonText: 'Close', + onSecondaryButtonClick: closeWidget, + }, }; const getErrorConfig = (errorType: AddFundsErrorTypes) => errorConfig[errorType]; diff --git a/packages/checkout/widgets-lib/src/widgets/add-funds/types.ts b/packages/checkout/widgets-lib/src/widgets/add-funds/types.ts index 56dfe77e0b..f87772e75c 100644 --- a/packages/checkout/widgets-lib/src/widgets/add-funds/types.ts +++ b/packages/checkout/widgets-lib/src/widgets/add-funds/types.ts @@ -72,4 +72,5 @@ export enum AddFundsErrorTypes { WALLET_REJECTED = 'WALLET_REJECTED', WALLET_REJECTED_NO_FUNDS = 'WALLET_REJECTED_NO_FUNDS', WALLET_POPUP_BLOCKED = 'WALLET_POPUP_BLOCKED', + ENVIRONMENT_ERROR = 'ENVIRONMENT_ERROR', }