From e8adff25c4b85035c1736455034544189005ed4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20G=C5=82ownia?= Date: Sat, 25 Mar 2023 00:57:00 +0100 Subject: [PATCH] fix(trading): handle lack of approval in trading deposit flow (#3278) --- libs/deposits/src/lib/approve-notification.tsx | 6 ++++-- libs/deposits/src/lib/deposit-form.tsx | 14 +++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libs/deposits/src/lib/approve-notification.tsx b/libs/deposits/src/lib/approve-notification.tsx index a3141f5a9..afe713d2a 100644 --- a/libs/deposits/src/lib/approve-notification.tsx +++ b/libs/deposits/src/lib/approve-notification.tsx @@ -16,6 +16,7 @@ interface ApproveNotificationProps { balances: DepositBalances | null; amount: string; approveTxId: number | null; + intent?: Intent; } export const ApproveNotification = ({ @@ -26,6 +27,7 @@ export const ApproveNotification = ({ balances, approved, approveTxId, + intent = Intent.Warning, }: ApproveNotificationProps) => { const tx = useEthTransactionStore((state) => { return state.transactions.find((t) => t?.id === approveTxId); @@ -46,7 +48,7 @@ export const ApproveNotification = ({ const approvePrompt = (
store.open); const { isActive, account } = useWeb3React(); const { pubKey, pubKeys: _pubKeys } = useVegaWallet(); + const [approveNotificationIntent, setApproveNotificationIntent] = + useState(Intent.Warning); const { register, handleSubmit, @@ -103,8 +105,10 @@ export const DepositForm = ({ if (!selectedAsset || selectedAsset.source.__typename !== 'ERC20') { throw new Error('Invalid asset'); } - if (!approved) throw new Error('Deposits not approved'); - + if (!approved) { + setApproveNotificationIntent(Intent.Danger); + return; + } submitDeposit({ assetSource: selectedAsset.source.contractAddress, amount: fields.amount, @@ -355,9 +359,13 @@ export const DepositForm = ({ isActive={isActive} approveTxId={approveTxId} selectedAsset={selectedAsset} - onApprove={submitApprove} + onApprove={() => { + submitApprove(); + setApproveNotificationIntent(Intent.Warning); + }} balances={balances} approved={approved} + intent={approveNotificationIntent} amount={amount} />