Skip to content

Commit 77a992a

Browse files
committed
High leverage warning improvements
1 parent 4864646 commit 77a992a

File tree

12 files changed

+65
-45
lines changed

12 files changed

+65
-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: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { useCallback, useState } from "react";
1+
import { useCallback } 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 { HIGH_LEVERAGE_WARNING_DISMISSED_TIMESTAMP_KEY } 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";
910
import { useSelector } from "context/SyntheticsStateContext/utils";
1011
import { useIsFreshAccountForHighLeverageTrading } from "domain/synthetics/accountStats/useIsFreshAccountForHighLeverageTrading";
12+
import { useLocalStorageSerializeKey } from "lib/localStorage";
1113
import { useIsAddressInGroup } from "lib/userAnalytics/getIsAddressInGroup";
1214
import { getToken } from "sdk/configs/tokens";
1315

@@ -19,6 +21,18 @@ const IS_MAJOR_TOKEN_MAP: Record<number, string[]> = {
1921

2022
const MAX_MAJOR_TOKEN_LEVERAGE = 15n * BASIS_POINTS_DIVISOR_BIGINT;
2123
const MAX_ALTCOIN_LEVERAGE = 10n * BASIS_POINTS_DIVISOR_BIGINT;
24+
const WAIVE_DISMISSAL_PERIOD_MS = 24 * 60 * 60 * 1000; // 24 hours
25+
26+
const NUMBER_OPTS: { raw: boolean; serializer: (val: number) => string; deserializer: (value: string) => number } = {
27+
raw: true,
28+
deserializer(value) {
29+
const timestamp = Number(value);
30+
return isNaN(timestamp) ? 0 : timestamp;
31+
},
32+
serializer(val) {
33+
return val.toString();
34+
},
35+
};
2236

2337
export function useShowHighLeverageWarning(): {
2438
showHighLeverageWarning: boolean;
@@ -39,13 +53,19 @@ export function useShowHighLeverageWarning(): {
3953
const isMajorToken = toTokenSymbol ? IS_MAJOR_TOKEN_MAP[chainId].includes(toTokenSymbol) : false;
4054
const leverage = useSelector(selectTradeboxLeverage);
4155

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

58+
const [dismissedTimestamp, setDismissedTimestamp] = useLocalStorageSerializeKey(
59+
[account, HIGH_LEVERAGE_WARNING_DISMISSED_TIMESTAMP_KEY],
60+
0,
61+
NUMBER_OPTS
62+
);
63+
64+
const isDismissed = (dismissedTimestamp ?? 0) > Date.now() - WAIVE_DISMISSAL_PERIOD_MS;
65+
4666
const dismissHighLeverageWarning = useCallback(() => {
47-
setIsDismissed(true);
48-
}, []);
67+
setDismissedTimestamp(Date.now());
68+
}, [setDismissedTimestamp]);
4969

5070
return {
5171
showHighLeverageWarning: isFreshAccount && isInGroup && isHighLeverage && !isDismissed,

src/config/localStorage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export const EXPRESS_TRADING_BANNER_DISMISSED_KEY = "express-trading-banner-dism
8787
export const SUBACCOUNT_APPROVAL_KEY = "subaccount-approval";
8888
export const TOKEN_PERMITS_KEY = "token-permits";
8989

90+
export const HIGH_LEVERAGE_WARNING_DISMISSED_TIMESTAMP_KEY = "high-leverage-warning-dismissed-timestamp";
91+
9092
export const getSubgraphUrlKey = (chainId: number, subgraph: string) => `subgraphUrl:${chainId}:${subgraph}`;
9193

9294
export function getSubaccountApprovalKey(chainId: number, account: string | undefined) {

src/locales/de/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,10 @@ msgstr ""
17221722
msgid "Account"
17231723
msgstr "Konto"
17241724

1725+
#: src/components/Synthetics/TradeBox/TradeBox.tsx
1726+
msgid "Using high leverage increases the risk of liquidation."
1727+
msgstr ""
1728+
17251729
#: src/components/Synthetics/TradeBox/ExpressTradingWarningCard.tsx
17261730
msgid "Express Trading is not available for wrapping or unwrapping native token {0}."
17271731
msgstr ""
@@ -7992,10 +7996,6 @@ msgstr ""
79927996
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."
79937997
msgstr ""
79947998

7995-
#: src/components/Synthetics/TradeBox/TradeBox.tsx
7996-
msgid "Using high leverage increases the risk of <0>losing funds</0>."
7997-
msgstr ""
7998-
79997999
#: src/components/Synthetics/StatusNotification/GmStatusNotification.tsx
80008000
msgid "Sell order cancelled"
80018001
msgstr ""

src/locales/en/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,10 @@ msgstr "Enter a price"
17221722
msgid "Account"
17231723
msgstr "Account"
17241724

1725+
#: src/components/Synthetics/TradeBox/TradeBox.tsx
1726+
msgid "Using high leverage increases the risk of liquidation."
1727+
msgstr "Using high leverage increases the risk of liquidation."
1728+
17251729
#: src/components/Synthetics/TradeBox/ExpressTradingWarningCard.tsx
17261730
msgid "Express Trading is not available for wrapping or unwrapping native token {0}."
17271731
msgstr "Express Trading is not available for wrapping or unwrapping native token {0}."
@@ -7998,10 +8002,6 @@ msgstr "<0>Delegate your undelegated {0} GMX DAO</0>voting power before claiming
79988002
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."
79998003
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."
80008004

8001-
#: src/components/Synthetics/TradeBox/TradeBox.tsx
8002-
msgid "Using high leverage increases the risk of <0>losing funds</0>."
8003-
msgstr "Using high leverage increases the risk of <0>losing funds</0>."
8004-
80058005
#: src/components/Synthetics/StatusNotification/GmStatusNotification.tsx
80068006
msgid "Sell order cancelled"
80078007
msgstr "Sell order cancelled"

src/locales/es/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,10 @@ msgstr ""
17221722
msgid "Account"
17231723
msgstr "Cuenta"
17241724

1725+
#: src/components/Synthetics/TradeBox/TradeBox.tsx
1726+
msgid "Using high leverage increases the risk of liquidation."
1727+
msgstr ""
1728+
17251729
#: src/components/Synthetics/TradeBox/ExpressTradingWarningCard.tsx
17261730
msgid "Express Trading is not available for wrapping or unwrapping native token {0}."
17271731
msgstr ""
@@ -7992,10 +7996,6 @@ msgstr ""
79927996
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."
79937997
msgstr ""
79947998

7995-
#: src/components/Synthetics/TradeBox/TradeBox.tsx
7996-
msgid "Using high leverage increases the risk of <0>losing funds</0>."
7997-
msgstr ""
7998-
79997999
#: src/components/Synthetics/StatusNotification/GmStatusNotification.tsx
80008000
msgid "Sell order cancelled"
80018001
msgstr ""

src/locales/fr/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,10 @@ msgstr ""
17221722
msgid "Account"
17231723
msgstr "Compte"
17241724

1725+
#: src/components/Synthetics/TradeBox/TradeBox.tsx
1726+
msgid "Using high leverage increases the risk of liquidation."
1727+
msgstr ""
1728+
17251729
#: src/components/Synthetics/TradeBox/ExpressTradingWarningCard.tsx
17261730
msgid "Express Trading is not available for wrapping or unwrapping native token {0}."
17271731
msgstr ""
@@ -7992,10 +7996,6 @@ msgstr ""
79927996
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."
79937997
msgstr ""
79947998

7995-
#: src/components/Synthetics/TradeBox/TradeBox.tsx
7996-
msgid "Using high leverage increases the risk of <0>losing funds</0>."
7997-
msgstr ""
7998-
79997999
#: src/components/Synthetics/StatusNotification/GmStatusNotification.tsx
80008000
msgid "Sell order cancelled"
80018001
msgstr ""

src/locales/ja/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,10 @@ msgstr ""
17221722
msgid "Account"
17231723
msgstr "アカウント"
17241724

1725+
#: src/components/Synthetics/TradeBox/TradeBox.tsx
1726+
msgid "Using high leverage increases the risk of liquidation."
1727+
msgstr ""
1728+
17251729
#: src/components/Synthetics/TradeBox/ExpressTradingWarningCard.tsx
17261730
msgid "Express Trading is not available for wrapping or unwrapping native token {0}."
17271731
msgstr ""
@@ -7992,10 +7996,6 @@ msgstr ""
79927996
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."
79937997
msgstr ""
79947998

7995-
#: src/components/Synthetics/TradeBox/TradeBox.tsx
7996-
msgid "Using high leverage increases the risk of <0>losing funds</0>."
7997-
msgstr ""
7998-
79997999
#: src/components/Synthetics/StatusNotification/GmStatusNotification.tsx
80008000
msgid "Sell order cancelled"
80018001
msgstr ""

src/locales/ko/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,10 @@ msgstr ""
17221722
msgid "Account"
17231723
msgstr "계정"
17241724

1725+
#: src/components/Synthetics/TradeBox/TradeBox.tsx
1726+
msgid "Using high leverage increases the risk of liquidation."
1727+
msgstr ""
1728+
17251729
#: src/components/Synthetics/TradeBox/ExpressTradingWarningCard.tsx
17261730
msgid "Express Trading is not available for wrapping or unwrapping native token {0}."
17271731
msgstr ""
@@ -7992,10 +7996,6 @@ msgstr ""
79927996
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."
79937997
msgstr ""
79947998

7995-
#: src/components/Synthetics/TradeBox/TradeBox.tsx
7996-
msgid "Using high leverage increases the risk of <0>losing funds</0>."
7997-
msgstr ""
7998-
79997999
#: src/components/Synthetics/StatusNotification/GmStatusNotification.tsx
80008000
msgid "Sell order cancelled"
80018001
msgstr ""

src/locales/pseudo/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,10 @@ msgstr ""
17221722
msgid "Account"
17231723
msgstr ""
17241724

1725+
#: src/components/Synthetics/TradeBox/TradeBox.tsx
1726+
msgid "Using high leverage increases the risk of liquidation."
1727+
msgstr ""
1728+
17251729
#: src/components/Synthetics/TradeBox/ExpressTradingWarningCard.tsx
17261730
msgid "Express Trading is not available for wrapping or unwrapping native token {0}."
17271731
msgstr ""
@@ -7992,10 +7996,6 @@ msgstr ""
79927996
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."
79937997
msgstr ""
79947998

7995-
#: src/components/Synthetics/TradeBox/TradeBox.tsx
7996-
msgid "Using high leverage increases the risk of <0>losing funds</0>."
7997-
msgstr ""
7998-
79997999
#: src/components/Synthetics/StatusNotification/GmStatusNotification.tsx
80008000
msgid "Sell order cancelled"
80018001
msgstr ""

0 commit comments

Comments
 (0)