Skip to content

Commit

Permalink
add confirmation text & notification
Browse files Browse the repository at this point in the history
  • Loading branch information
GrandSchtroumpf committed Jan 15, 2025
1 parent fdc76d9 commit 28f922c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/libs/notifications/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface NotificationSchema {
approveError: { symbol: string };
trade: { txHash: string; amount: string; from: string; to: string };
createStrategy: { txHash: string };
createBatchStrategy: { txHash: string };
pauseStrategy: { txHash: string };
renewStrategy: { txHash: string };
editStrategyName: { txHash: string };
Expand Down Expand Up @@ -82,6 +83,19 @@ export const NOTIFICATIONS_MAP: NotificationsMap = {
showAlert: true,
testid: 'create-strategy',
}),
createBatchStrategy: (data) => ({
type: 'tx',
status: 'pending',
title: 'Pending Confirmation',
description: 'New batch of strategies are being created.',
successTitle: 'Success',
successDesc: 'New batch of strategies were successfully created.',
failedTitle: 'Transaction Failed',
failedDesc: 'New batch of strategy creation has failed.',
txHash: data.txHash,
showAlert: true,
testid: 'create-batch-strategy',
}),
pauseStrategy: (data) => ({
type: 'tx',
status: 'pending',
Expand Down
25 changes: 19 additions & 6 deletions src/pages/cart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Warning } from 'components/common/WarningMessageWithIcon';
import { useModal } from 'hooks/useModal';
import { carbonSDK } from 'libs/sdk';
import { useNavigate } from '@tanstack/react-router';
import { useNotifications } from 'hooks/useNotifications';
import style from 'components/strategies/common/form.module.css';
import config from 'config';

Expand Down Expand Up @@ -56,8 +57,11 @@ export const CartPage = () => {
const strategies = useStrategyCart();
const { user, signer } = useWagmi();
const { openModal } = useModal();
const { dispatchNotification } = useNotifications();

const nav = useNavigate({ from: '/cart' });
const [pending, setPending] = useState(false);
const [confirmation, setConfirmation] = useState(false);
const [processing, setProcessing] = useState(false);

const approvalTokens = useMemo(() => {
return getApproveTokens(strategies);
Expand All @@ -77,7 +81,7 @@ export const CartPage = () => {
}

const create = async () => {
setPending(true);
setConfirmation(true);
try {
const params = strategies.map(({ base, quote, order0, order1 }) => ({
baseToken: base.address,
Expand All @@ -92,11 +96,16 @@ export const CartPage = () => {
sellBudget: order1.balance,
}));
const unsignedTx = await carbonSDK.batchCreateBuySellStrategies(params);
await signer!.sendTransaction(unsignedTx);
const tx = await signer!.sendTransaction(unsignedTx);
setConfirmation(false);
setProcessing(true);
dispatchNotification('createBatchStrategy', { txHash: tx.hash });
await tx.wait();
clearCart(user!);
nav({ to: '/' });
} finally {
setPending(false);
setConfirmation(false);
setProcessing(false);
}
};

Expand Down Expand Up @@ -160,9 +169,13 @@ export const CartPage = () => {
</label>
<Button
type="submit"
disabled={!user || approval.isPending || funds.isPending || pending}
disabled={!user || approval.isPending || funds.isPending}
loading={confirmation || processing}
loadingChildren={
confirmation ? 'Waiting for Confirmation' : 'Processing'
}
variant="success"
className="place-self-center"
className="mt-20 place-self-center"
>
Sign all strategies
</Button>
Expand Down

0 comments on commit 28f922c

Please sign in to comment.