Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/bonsai/lifecycles/cancelTriggerOrdersLifecycle.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line import/no-internal-modules
import { selectRawParentSubaccountData } from '@/bonsai/selectors/base';

import { timeUnits } from '@/constants/time';
import { WalletNetworkType } from '@/constants/wallets';

Expand Down Expand Up @@ -25,7 +28,7 @@ export function setUpCancelOrphanedTriggerOrdersLifecycle(store: RootStore) {
const selector = createAppSelector(
[selectTxAuthorizedCloseOnlyAccount, selectOrphanedTriggerOrders],
(txAuthorizedAccount, orphanedTriggerOrders) => {
if (!txAuthorizedAccount || orphanedTriggerOrders == null) {
if (!txAuthorizedAccount || orphanedTriggerOrders?.ordersToCancel == null) {
return undefined;
}

Expand All @@ -35,7 +38,8 @@ export function setUpCancelOrphanedTriggerOrdersLifecycle(store: RootStore) {
localDydxWallet,
sourceAccount,
parentSubaccountInfo,
ordersToCancel: orphanedTriggerOrders,
ordersToCancel: orphanedTriggerOrders.ordersToCancel,
groupedPositions: orphanedTriggerOrders.groupedPositions,
};
}
);
Expand All @@ -51,7 +55,7 @@ export function setUpCancelOrphanedTriggerOrdersLifecycle(store: RootStore) {

runFn(async () => {
try {
const { ordersToCancel: ordersToCancelRaw } = data;
const { ordersToCancel: ordersToCancelRaw, groupedPositions } = data;
const ordersToCancel = ordersToCancelRaw.filter((o) => !cancelingOrderIds.has(o.id));

// context: Cosmos wallets do not support our lifecycle methods and are instead handled within useNotificationTypes
Expand All @@ -67,6 +71,8 @@ export function setUpCancelOrphanedTriggerOrdersLifecycle(store: RootStore) {
`Cancelling ${ordersToCancel.length} trigger orders`,
{
ordersToCancel,
groupedPositions,
bonsaiParentSubaccountData: selectRawParentSubaccountData(store.getState()),
}
);

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useNotificationTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import {
} from '@/lib/enumToStringKeyHelpers';
import { BIG_NUMBERS, MaybeBigNumber, MustNumber } from '@/lib/numbers';
import { getAverageFillPrice } from '@/lib/orders';
import { isPresent, orEmptyRecord } from '@/lib/typeUtils';
import { isPresent, orEmptyObj, orEmptyRecord } from '@/lib/typeUtils';

import { DEC_2025_COMPETITION_DETAILS } from './rewards/util';
import { useAccounts } from './useAccounts';
Expand Down Expand Up @@ -1232,7 +1232,7 @@ export const notificationTypes: NotificationTypeConfig[] = [
const stringGetter = useStringGetter();
const isKeplr = useAppSelector(selectIsKeplrConnected);
const reclaimableChildSubaccountFunds = useAppSelector(selectReclaimableChildSubaccountFunds);
const ordersToCancel = useAppSelector(selectOrphanedTriggerOrders);
const { ordersToCancel } = orEmptyObj(useAppSelector(selectOrphanedTriggerOrders));
const maybeRebalanceAction = useAppSelector(selectShouldAccountRebalanceUsdc);

useEffect(() => {
Expand Down
5 changes: 3 additions & 2 deletions src/state/accountSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,12 @@ export const selectOrphanedTriggerOrders = createAppSelector(
return undefined;
}

const groupedPositions = keyBy(openPositions, (o) => o.uniqueId);

const ordersToCancel = calc(() => {
if (ordersLoading !== 'success' || positionsLoading !== 'success') {
return [];
}
const groupedPositions = keyBy(openPositions, (o) => o.uniqueId);

const filteredOrders = openOrders.filter((o) => {
const isConditionalOrder = o.orderFlags === OrderFlags.CONDITIONAL;
Expand All @@ -511,7 +512,7 @@ export const selectOrphanedTriggerOrders = createAppSelector(
return cancelOrders;
});

return ordersToCancel;
return { ordersToCancel, groupedPositions };
}
);

Expand Down
4 changes: 3 additions & 1 deletion src/views/dialogs/CancelOrphanedTriggerOrdersDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import { Dialog } from '@/components/Dialog';
import { selectOrphanedTriggerOrders } from '@/state/accountSelectors';
import { useAppSelector } from '@/state/appTypes';

import { orEmptyObj } from '@/lib/typeUtils';

export const CancelOrphanedTriggerOrdersDialog = ({
setIsOpen,
}: DialogProps<CancelOrphanedTriggersDialogProps>) => {
const stringGetter = useStringGetter();
const ordersToCancel = useAppSelector(selectOrphanedTriggerOrders);
const { ordersToCancel } = orEmptyObj(useAppSelector(selectOrphanedTriggerOrders));
const [isLoading, setIsLoading] = useState<boolean>(false);

const markets: Record<string, SubaccountOrder[]> = useMemo(() => {
Expand Down
Loading