Skip to content

Commit e61e8d7

Browse files
committed
High leverage warning improvements
1 parent aa6099a commit e61e8d7

File tree

12 files changed

+90
-45
lines changed

12 files changed

+90
-45
lines changed

src/components/Synthetics/TradeBox/TradeBox.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -955,10 +955,8 @@ export function TradeBox({ isMobile }: { isMobile: boolean }) {
955955
</div>
956956
)}
957957
{showHighLeverageWarning && (
958-
<AlertInfoCard type="warning" onClose={dismissHighLeverageWarning}>
959-
<Trans>
960-
Using high leverage increases the risk of <span className="underline">losing funds</span>.
961-
</Trans>
958+
<AlertInfoCard type="info" onClose={dismissHighLeverageWarning}>
959+
<Trans>Using high leverage increases the risk of liquidation.</Trans>
962960
</AlertInfoCard>
963961
)}
964962
{isTrigger && (

src/components/Synthetics/TradeBox/hooks/useShowHighLeverageWarning.ts

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { useCallback, useState } from "react";
1+
import { useCallback, useEffect, useState } from "react";
22

33
import { AB_HIGH_LEVERAGE_WARNING_GROUP, AB_HIGH_LEVERAGE_WARNING_PROBABILITY } from "config/ab";
44
import { ARBITRUM, AVALANCHE, BOTANIX } from "config/chains";
55
import { BASIS_POINTS_DIVISOR_BIGINT } from "config/factors";
6+
import { getHighLeverageWarningDismissedTimestampKey } from "config/localStorage";
67
import { selectAccount, selectChainId } from "context/SyntheticsStateContext/selectors/globalSelectors";
78
import { selectTradeboxToTokenAddress } from "context/SyntheticsStateContext/selectors/shared/baseSelectors";
89
import { selectTradeboxLeverage } from "context/SyntheticsStateContext/selectors/tradeboxSelectors";
@@ -19,6 +20,18 @@ const IS_MAJOR_TOKEN_MAP: Record<number, string[]> = {
1920

2021
const MAX_MAJOR_TOKEN_LEVERAGE = 15n * BASIS_POINTS_DIVISOR_BIGINT;
2122
const MAX_ALTCOIN_LEVERAGE = 10n * BASIS_POINTS_DIVISOR_BIGINT;
23+
const WAIVE_DISMISSAL_PERIOD_MS = 24 * 60 * 60 * 1000; // 24 hours
24+
const DISMISSAL_POLL_INTERVAL_MS = 5000;
25+
26+
function getDismissedTimestamp(account: string) {
27+
const value = localStorage.getItem(getHighLeverageWarningDismissedTimestampKey(account));
28+
if (value === null) {
29+
return 0;
30+
}
31+
32+
const timestamp = Number(value);
33+
return isNaN(timestamp) ? 0 : timestamp;
34+
}
2235

2336
export function useShowHighLeverageWarning(): {
2437
showHighLeverageWarning: boolean;
@@ -39,13 +52,41 @@ export function useShowHighLeverageWarning(): {
3952
const isMajorToken = toTokenSymbol ? IS_MAJOR_TOKEN_MAP[chainId].includes(toTokenSymbol) : false;
4053
const leverage = useSelector(selectTradeboxLeverage);
4154

42-
const [isDismissed, setIsDismissed] = useState(false);
43-
4455
const isHighLeverage = isMajorToken ? leverage > MAX_MAJOR_TOKEN_LEVERAGE : leverage >= MAX_ALTCOIN_LEVERAGE;
4556

57+
const [dismissedTimestamp, setDismissedTimestamp] = useState(() => {
58+
if (!account) {
59+
return 0;
60+
}
61+
62+
return getDismissedTimestamp(account);
63+
});
64+
65+
useEffect(() => {
66+
if (!account) {
67+
return;
68+
}
69+
70+
const timer = window.setInterval(() => {
71+
const freshDismissedTimestamp = getDismissedTimestamp(account);
72+
if (freshDismissedTimestamp !== dismissedTimestamp) {
73+
setDismissedTimestamp(freshDismissedTimestamp);
74+
}
75+
}, DISMISSAL_POLL_INTERVAL_MS);
76+
77+
return () => {
78+
window.clearInterval(timer);
79+
};
80+
}, [account, dismissedTimestamp]);
81+
82+
const isDismissed = (dismissedTimestamp ?? 0) > Date.now() - WAIVE_DISMISSAL_PERIOD_MS;
83+
4684
const dismissHighLeverageWarning = useCallback(() => {
47-
setIsDismissed(true);
48-
}, []);
85+
setDismissedTimestamp(Date.now());
86+
if (account) {
87+
localStorage.setItem(getHighLeverageWarningDismissedTimestampKey(account), Date.now().toString());
88+
}
89+
}, [setDismissedTimestamp, account]);
4990

5091
return {
5192
showHighLeverageWarning: isFreshAccount && isInGroup && isHighLeverage && !isDismissed,

src/config/localStorage.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export const SUBACCOUNT_APPROVAL_KEY = "subaccount-approval";
8989
export const TOKEN_PERMITS_KEY = "token-permits";
9090
export const CLAIM_TERMS_ACCEPTED_KEY = "claim-terms-accepted";
9191

92+
export const HIGH_LEVERAGE_WARNING_DISMISSED_TIMESTAMP_KEY = "high-leverage-warning-dismissed-timestamp";
93+
9294
export const getSubgraphUrlKey = (chainId: number, subgraph: string) => `subgraphUrl:${chainId}:${subgraph}`;
9395

9496
export function getSubaccountApprovalKey(chainId: number, account: string | undefined) {
@@ -219,3 +221,7 @@ export function getClaimTermsAcceptedKey(
219221
) {
220222
return `${chainId}:${account}:${distributionId}:${claimTerms}-${CLAIM_TERMS_ACCEPTED_KEY}`;
221223
}
224+
225+
export function getHighLeverageWarningDismissedTimestampKey(account: string) {
226+
return `${account}-${HIGH_LEVERAGE_WARNING_DISMISSED_TIMESTAMP_KEY}`;
227+
}

src/locales/de/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,10 @@ msgstr ""
17571757
msgid "Account"
17581758
msgstr "Konto"
17591759

1760+
#: src/components/Synthetics/TradeBox/TradeBox.tsx
1761+
msgid "Using high leverage increases the risk of liquidation."
1762+
msgstr ""
1763+
17601764
#: src/components/Synthetics/TradeBox/ExpressTradingWarningCard.tsx
17611765
msgid "Express Trading is not available for wrapping or unwrapping native token {0}."
17621766
msgstr ""
@@ -8140,10 +8144,6 @@ msgstr ""
81408144
msgid "You will be long {indexSymbol} from your long position, as well as from your {collateralSymbol} collateral. The liquidation price is higher compared to using a stablecoin as collateral since the worth of the collateral will change with its price."
81418145
msgstr ""
81428146

8143-
#: src/components/Synthetics/TradeBox/TradeBox.tsx
8144-
msgid "Using high leverage increases the risk of <0>losing funds</0>."
8145-
msgstr ""
8146-
81478147
#: src/components/Synthetics/StatusNotification/GmStatusNotification.tsx
81488148
msgid "Sell order cancelled"
81498149
msgstr ""

src/locales/en/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,10 @@ msgstr "Enter a price"
17571757
msgid "Account"
17581758
msgstr "Account"
17591759

1760+
#: src/components/Synthetics/TradeBox/TradeBox.tsx
1761+
msgid "Using high leverage increases the risk of liquidation."
1762+
msgstr "Using high leverage increases the risk of liquidation."
1763+
17601764
#: src/components/Synthetics/TradeBox/ExpressTradingWarningCard.tsx
17611765
msgid "Express Trading is not available for wrapping or unwrapping native token {0}."
17621766
msgstr "Express Trading is not available for wrapping or unwrapping native token {0}."
@@ -8146,10 +8150,6 @@ msgstr "Claim funds"
81468150
msgid "You will be long {indexSymbol} from your long position, as well as from your {collateralSymbol} collateral. The liquidation price is higher compared to using a stablecoin as collateral since the worth of the collateral will change with its price."
81478151
msgstr "You will be long {indexSymbol} from your long position, as well as from your {collateralSymbol} collateral. The liquidation price is higher compared to using a stablecoin as collateral since the worth of the collateral will change with its price."
81488152

8149-
#: src/components/Synthetics/TradeBox/TradeBox.tsx
8150-
msgid "Using high leverage increases the risk of <0>losing funds</0>."
8151-
msgstr "Using high leverage increases the risk of <0>losing funds</0>."
8152-
81538153
#: src/components/Synthetics/StatusNotification/GmStatusNotification.tsx
81548154
msgid "Sell order cancelled"
81558155
msgstr "Sell order cancelled"

src/locales/es/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,10 @@ msgstr ""
17571757
msgid "Account"
17581758
msgstr "Cuenta"
17591759

1760+
#: src/components/Synthetics/TradeBox/TradeBox.tsx
1761+
msgid "Using high leverage increases the risk of liquidation."
1762+
msgstr ""
1763+
17601764
#: src/components/Synthetics/TradeBox/ExpressTradingWarningCard.tsx
17611765
msgid "Express Trading is not available for wrapping or unwrapping native token {0}."
17621766
msgstr ""
@@ -8140,10 +8144,6 @@ msgstr ""
81408144
msgid "You will be long {indexSymbol} from your long position, as well as from your {collateralSymbol} collateral. The liquidation price is higher compared to using a stablecoin as collateral since the worth of the collateral will change with its price."
81418145
msgstr ""
81428146

8143-
#: src/components/Synthetics/TradeBox/TradeBox.tsx
8144-
msgid "Using high leverage increases the risk of <0>losing funds</0>."
8145-
msgstr ""
8146-
81478147
#: src/components/Synthetics/StatusNotification/GmStatusNotification.tsx
81488148
msgid "Sell order cancelled"
81498149
msgstr ""

src/locales/fr/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,10 @@ msgstr ""
17571757
msgid "Account"
17581758
msgstr "Compte"
17591759

1760+
#: src/components/Synthetics/TradeBox/TradeBox.tsx
1761+
msgid "Using high leverage increases the risk of liquidation."
1762+
msgstr ""
1763+
17601764
#: src/components/Synthetics/TradeBox/ExpressTradingWarningCard.tsx
17611765
msgid "Express Trading is not available for wrapping or unwrapping native token {0}."
17621766
msgstr ""
@@ -8140,10 +8144,6 @@ msgstr ""
81408144
msgid "You will be long {indexSymbol} from your long position, as well as from your {collateralSymbol} collateral. The liquidation price is higher compared to using a stablecoin as collateral since the worth of the collateral will change with its price."
81418145
msgstr ""
81428146

8143-
#: src/components/Synthetics/TradeBox/TradeBox.tsx
8144-
msgid "Using high leverage increases the risk of <0>losing funds</0>."
8145-
msgstr ""
8146-
81478147
#: src/components/Synthetics/StatusNotification/GmStatusNotification.tsx
81488148
msgid "Sell order cancelled"
81498149
msgstr ""

src/locales/ja/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,10 @@ msgstr ""
17571757
msgid "Account"
17581758
msgstr "アカウント"
17591759

1760+
#: src/components/Synthetics/TradeBox/TradeBox.tsx
1761+
msgid "Using high leverage increases the risk of liquidation."
1762+
msgstr ""
1763+
17601764
#: src/components/Synthetics/TradeBox/ExpressTradingWarningCard.tsx
17611765
msgid "Express Trading is not available for wrapping or unwrapping native token {0}."
17621766
msgstr ""
@@ -8140,10 +8144,6 @@ msgstr ""
81408144
msgid "You will be long {indexSymbol} from your long position, as well as from your {collateralSymbol} collateral. The liquidation price is higher compared to using a stablecoin as collateral since the worth of the collateral will change with its price."
81418145
msgstr ""
81428146

8143-
#: src/components/Synthetics/TradeBox/TradeBox.tsx
8144-
msgid "Using high leverage increases the risk of <0>losing funds</0>."
8145-
msgstr ""
8146-
81478147
#: src/components/Synthetics/StatusNotification/GmStatusNotification.tsx
81488148
msgid "Sell order cancelled"
81498149
msgstr ""

src/locales/ko/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,10 @@ msgstr ""
17571757
msgid "Account"
17581758
msgstr "계정"
17591759

1760+
#: src/components/Synthetics/TradeBox/TradeBox.tsx
1761+
msgid "Using high leverage increases the risk of liquidation."
1762+
msgstr ""
1763+
17601764
#: src/components/Synthetics/TradeBox/ExpressTradingWarningCard.tsx
17611765
msgid "Express Trading is not available for wrapping or unwrapping native token {0}."
17621766
msgstr ""
@@ -8140,10 +8144,6 @@ msgstr ""
81408144
msgid "You will be long {indexSymbol} from your long position, as well as from your {collateralSymbol} collateral. The liquidation price is higher compared to using a stablecoin as collateral since the worth of the collateral will change with its price."
81418145
msgstr ""
81428146

8143-
#: src/components/Synthetics/TradeBox/TradeBox.tsx
8144-
msgid "Using high leverage increases the risk of <0>losing funds</0>."
8145-
msgstr ""
8146-
81478147
#: src/components/Synthetics/StatusNotification/GmStatusNotification.tsx
81488148
msgid "Sell order cancelled"
81498149
msgstr ""

src/locales/pseudo/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,10 @@ msgstr ""
17571757
msgid "Account"
17581758
msgstr ""
17591759

1760+
#: src/components/Synthetics/TradeBox/TradeBox.tsx
1761+
msgid "Using high leverage increases the risk of liquidation."
1762+
msgstr ""
1763+
17601764
#: src/components/Synthetics/TradeBox/ExpressTradingWarningCard.tsx
17611765
msgid "Express Trading is not available for wrapping or unwrapping native token {0}."
17621766
msgstr ""
@@ -8140,10 +8144,6 @@ msgstr ""
81408144
msgid "You will be long {indexSymbol} from your long position, as well as from your {collateralSymbol} collateral. The liquidation price is higher compared to using a stablecoin as collateral since the worth of the collateral will change with its price."
81418145
msgstr ""
81428146

8143-
#: src/components/Synthetics/TradeBox/TradeBox.tsx
8144-
msgid "Using high leverage increases the risk of <0>losing funds</0>."
8145-
msgstr ""
8146-
81478147
#: src/components/Synthetics/StatusNotification/GmStatusNotification.tsx
81488148
msgid "Sell order cancelled"
81498149
msgstr ""

0 commit comments

Comments
 (0)