Skip to content

Commit

Permalink
chore: market wind down notifications (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
moo-onthelawn authored Jun 7, 2024
1 parent 884efb9 commit fe26630
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@cosmjs/tendermint-rpc": "^0.32.1",
"@dydxprotocol/v4-abacus": "1.7.51",
"@dydxprotocol/v4-client-js": "^1.1.15",
"@dydxprotocol/v4-localization": "^1.1.113",
"@dydxprotocol/v4-localization": "^1.1.118",
"@ethersproject/providers": "^5.7.2",
"@js-joda/core": "^5.5.3",
"@privy-io/react-auth": "^1.66.2",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions public/configs/v1/env.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
"exchangeStats": "https://app.mode.com/dydx_eng/reports/58822121650d?secret_key=391d9214fe6aefec35b7d35c",
"initialMarginFractionLearnMore": "https://docs.dydx.exchange/governance/functionalities#liquidity-tiers",
"complianceSupportEmail": "[email protected]",
"equityTiersLearnMore": "https://help.dydx.trade/en/articles/171918-equity-tiers-and-rate-limits"
"equityTiersLearnMore": "https://help.dydx.trade/en/articles/171918-equity-tiers-and-rate-limits",
"fetAgixMarketWindDownProposal": "https://www.mintscan.io/dydx/proposals/61",
"contractLossMechanismLearnMore": "https://help.dydx.trade/en/articles/166973-contract-loss-mechanisms-on-dydx-chain"
},
"dydx-testnet-4": {
"tos": "https://dydx.exchange/v4-terms",
Expand Down Expand Up @@ -106,7 +108,9 @@
"exchangeStats": "https://app.mode.com/dydx_eng/reports/58822121650d?secret_key=391d9214fe6aefec35b7d35c",
"initialMarginFractionLearnMore": "https://docs.dydx.exchange/governance/functionalities#liquidity-tiers",
"complianceSupportEmail": "[email protected]",
"equityTiersLearnMore": "https://help.dydx.trade/en/articles/171918-equity-tiers-and-rate-limits"
"equityTiersLearnMore": "https://help.dydx.trade/en/articles/171918-equity-tiers-and-rate-limits",
"fetAgixMarketWindDownProposal": "https://www.mintscan.io/dydx/proposals/61",
"contractLossMechanismLearnMore": "https://help.dydx.trade/en/articles/166973-contract-loss-mechanisms-on-dydx-chain"
},
"[mainnet chain id]": {
"tos": "[HTTP link to TOS]",
Expand Down Expand Up @@ -134,7 +138,9 @@
"exchangeStats": "[HTTP link to exchange stats, can be null]",
"initialMarginFractionLearnMore": "[HTTP link to governance functionalities liquidity tiers, can be null]",
"complianceSupportEmail": "[Email address for compliance support, can be null]",
"equityTiersLearnMore": "[HTTP link to equity tiers learn more, can be null]"
"equityTiersLearnMore": "[HTTP link to equity tiers learn more, can be null]",
"fetAgixMarketWindDownProposal": "[HTTP link to mintscan proposal]",
"contractLossMechanismLearnMore": "[HTTP link to documentation on contract loss mechanisms]"
}
},
"wallets": {
Expand Down
7 changes: 7 additions & 0 deletions src/constants/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum NotificationType {
ApiError = 'ApiError',
ComplianceAlert = 'ComplianceAlert',
OrderStatus = 'OrderStatus',
MarketWindDown = 'MarketWindDown',
}

export enum NotificationCategoryPreferences {
Expand All @@ -28,6 +29,7 @@ export const NotificationTypeCategory: {
[NotificationType.OrderStatus]: NotificationCategoryPreferences.Trading,
[NotificationType.ApiError]: NotificationCategoryPreferences.MustSee,
[NotificationType.ComplianceAlert]: NotificationCategoryPreferences.MustSee,
[NotificationType.MarketWindDown]: NotificationCategoryPreferences.MustSee,
};

export const SingleSessionNotificationTypes = [
Expand Down Expand Up @@ -195,6 +197,11 @@ export const INCENTIVES_SEASON_NOTIFICATION_ID = ReleaseUpdateNotificationIds.In
export const INCENTIVES_DISTRIBUTED_NOTIFICATION_ID =
ReleaseUpdateNotificationIds.IncentivesDistributedS4;

export enum MarketWindDownNotificationIds {
MarketWindDownFetAgix = 'market-wind-down-fet-agix',
MarketWindDownProposalFetAgix = 'market-wind-down-proposal-fet-agix',
}

/**
* @description Struct to store whether a NotificationType belonging to each NotificationCategoryType should be triggered
*/
Expand Down
92 changes: 92 additions & 0 deletions src/hooks/useNotificationTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
DEFAULT_TOAST_AUTO_CLOSE_MS,
INCENTIVES_DISTRIBUTED_NOTIFICATION_ID,
INCENTIVES_SEASON_NOTIFICATION_ID,
MarketWindDownNotificationIds,
NotificationDisplayData,
NotificationType,
REWARD_DISTRIBUTION_SEASON_NUMBER,
Expand All @@ -34,6 +35,7 @@ import { useLocalNotifications } from '@/hooks/useLocalNotifications';
import { AssetIcon } from '@/components/AssetIcon';
import { Icon, IconName } from '@/components/Icon';
import { Link } from '@/components/Link';
import { Output, OutputType } from '@/components/Output';
// eslint-disable-next-line import/no-cycle
import { BlockRewardNotification } from '@/views/notifications/BlockRewardNotification';
import { IncentiveSeasonDistributionNotification } from '@/views/notifications/IncentiveSeasonDistributionNotification';
Expand Down Expand Up @@ -413,6 +415,92 @@ export const notificationTypes: NotificationTypeConfig[] = [
};
},
},
{
type: NotificationType.MarketWindDown,
useTrigger: ({ trigger }) => {
const stringGetter = useStringGetter();

const { fetAgixMarketWindDownProposal, contractLossMechanismLearnMore } = useURLConfigs();

const marketWindDownProposalExpirationDate = '2024-06-11T16:53:00';
const marketWindDownDate = marketWindDownProposalExpirationDate;
const marketWindDownExpirationDate = '2024-07-11T16:53:00'; // 30 days after wind down
const currentDate = new Date();

const outputDate = <$Output type={OutputType.DateTime} value={marketWindDownDate} />;

const firstMarket = 'FET-USD';
const secondMarket = 'AGIX-USD';

useEffect(() => {
if (currentDate <= new Date(marketWindDownProposalExpirationDate)) {
trigger(MarketWindDownNotificationIds.MarketWindDownProposalFetAgix, {
title: stringGetter({
key: 'NOTIFICATIONS.TWO_MARKET_WIND_DOWN_PROPOSAL.TITLE',
params: {
MARKET_1: firstMarket,
MARKET_2: secondMarket,
},
}),
body: stringGetter({
key: 'NOTIFICATIONS.TWO_MARKET_WIND_DOWN_PROPOSAL.BODY',
params: {
MARKET_1: firstMarket,
MARKET_2: secondMarket,
DATE: outputDate,
HERE_LINK: (
<$Link href={fetAgixMarketWindDownProposal}>
{stringGetter({ key: STRING_KEYS.HERE })}
</$Link>
),
},
}),
toastSensitivity: 'foreground',
groupKey: MarketWindDownNotificationIds.MarketWindDownProposalFetAgix,
});
}
}, [stringGetter]);

useEffect(() => {
if (
currentDate >= new Date(marketWindDownDate) &&
currentDate <= new Date(marketWindDownExpirationDate)
) {
trigger(
MarketWindDownNotificationIds.MarketWindDownFetAgix,
{
title: stringGetter({
key: 'NOTIFICATIONS.TWO_MARKET_WIND_DOWN.TITLE',
params: {
MARKET_1: firstMarket,
MARKET_2: secondMarket,
},
}),
body: stringGetter({
key: 'NOTIFICATIONS.TWO_MARKET_WIND_DOWN.BODY',
params: {
MARKET_1: firstMarket,
MARKET_2: secondMarket,
DATE: outputDate,
HERE_LINK: (
<$Link href={contractLossMechanismLearnMore}>
{stringGetter({ key: STRING_KEYS.HERE })}
</$Link>
),
},
}),
toastSensitivity: 'foreground',
groupKey: MarketWindDownNotificationIds.MarketWindDownFetAgix,
},
[]
);
}
}, [stringGetter]);
},
useNotificationAction: () => {
return () => {};
},
},
{
type: NotificationType.ApiError,
useTrigger: ({ trigger }) => {
Expand Down Expand Up @@ -579,3 +667,7 @@ const $Link = styled(Link)`
--link-color: var(--color-accent);
display: inline-block;
`;

const $Output = styled(Output)`
display: inline-block;
`;
4 changes: 4 additions & 0 deletions src/hooks/useURLConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface LinksConfigs {
withdrawalGateLearnMore?: string;
exchangeStats?: string;
complianceSupportEmail?: string;
fetAgixMarketWindDownProposal?: string;
contractLossMechanismLearnMore?: string;
}

export const useURLConfigs = (): LinksConfigs => {
Expand Down Expand Up @@ -65,5 +67,7 @@ export const useURLConfigs = (): LinksConfigs => {
withdrawalGateLearnMore: linksConfigs.withdrawalGateLearnMore ?? FALLBACK_URL,
exchangeStats: linksConfigs.exchangeStats ?? FALLBACK_URL,
complianceSupportEmail: linksConfigs.complianceSupportEmail ?? FALLBACK_URL,
fetAgixMarketWindDownProposal: linksConfigs.fetAgixMarketWindDownProposal,
contractLossMechanismLearnMore: linksConfigs.contractLossMechanismLearnMore,
};
};

0 comments on commit fe26630

Please sign in to comment.