From 9ff52488da6169b7b372cb6c6ba4ae78d91566e3 Mon Sep 17 00:00:00 2001 From: Maximilian Schneider Date: Fri, 14 Jan 2022 11:28:28 -0800 Subject: [PATCH 1/2] disable spot margin by default --- components/trade_form/AdvancedTradeForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/trade_form/AdvancedTradeForm.tsx b/components/trade_form/AdvancedTradeForm.tsx index 024d2010..0ec92a0e 100644 --- a/components/trade_form/AdvancedTradeForm.tsx +++ b/components/trade_form/AdvancedTradeForm.tsx @@ -64,7 +64,7 @@ export default function AdvancedTradeForm({ const market = useMangoStore((s) => s.selectedMarket.current) const isPerpMarket = market instanceof PerpMarket const [reduceOnly, setReduceOnly] = useState(false) - const [spotMargin, setSpotMargin] = useState(true) + const [spotMargin, setSpotMargin] = useState(false) const [positionSizePercent, setPositionSizePercent] = useState('') const [insufficientSol, setInsufficientSol] = useState(false) const { takerFee, makerFee } = useFees() From 68b9ef1709f3bf98d803ff73b8aa4d68db55eec1 Mon Sep 17 00:00:00 2001 From: Maximilian Schneider Date: Fri, 14 Jan 2022 11:44:10 -0800 Subject: [PATCH 2/2] make spot margin configurable --- components/SettingsModal.tsx | 16 ++++++++++++++++ components/trade_form/AdvancedTradeForm.tsx | 11 +++++++++-- public/locales/en/common.json | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/components/SettingsModal.tsx b/components/SettingsModal.tsx index ae78a3fa..bb1f9db3 100644 --- a/components/SettingsModal.tsx +++ b/components/SettingsModal.tsx @@ -29,6 +29,7 @@ const CUSTOM_NODE = NODE_URLS.find((n) => n.label === 'Custom') export const NODE_URL_KEY = 'node-url-key-0.5' export const DEFAULT_MARKET_KEY = 'defaultMarket' export const ORDERBOOK_FLASH_KEY = 'showOrderbookFlash' +export const DEFAULT_SPOT_MARGIN_KEY = 'defaultSpotMargin' export const initialMarket = { base: 'BTC', kind: 'perp', @@ -43,6 +44,7 @@ const SettingsModal = ({ isOpen, onClose }) => { NODE_URL_KEY, NODE_URLS[0].value ) + const [defaultMarket] = useLocalStorageState( DEFAULT_MARKET_KEY, initialMarket @@ -51,6 +53,12 @@ const SettingsModal = ({ isOpen, onClose }) => { ORDERBOOK_FLASH_KEY, true ) + + const [defaultSpotMargin, setDefaultSpotMargin] = useLocalStorageState( + DEFAULT_SPOT_MARGIN_KEY, + false + ) + const rpcEndpoint = NODE_URLS.find((node) => node.value === rpcEndpointUrl) || CUSTOM_NODE return ( @@ -96,6 +104,14 @@ const SettingsModal = ({ isOpen, onClose }) => { onChange={(checked) => setShowOrderbookFlash(checked)} /> + +
+ {t('default-spot-margin')} + setDefaultSpotMargin(checked)} + /> +
) : null} s.selectedMarket.current) const isPerpMarket = market instanceof PerpMarket const [reduceOnly, setReduceOnly] = useState(false) - const [spotMargin, setSpotMargin] = useState(false) + const [defaultSpotMargin] = useLocalStorageState( + DEFAULT_SPOT_MARGIN_KEY, + false + ) + const [spotMargin, setSpotMargin] = useState(defaultSpotMargin) const [positionSizePercent, setPositionSizePercent] = useState('') const [insufficientSol, setInsufficientSol] = useState(false) const { takerFee, makerFee } = useFees() diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 998d5933..0db9567c 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -94,6 +94,7 @@ "data-refresh-tip-title": "Manual Data Refresh", "date": "Date", "default-market": "Default Market", + "default-spot-margin": "Trade with margin by default", "delay-displaying-recent": "There may be a delay in displaying the latest activity.", "deposit": "Deposit", "deposit-before": "You need more {{tokenSymbol}} in your wallet to fully repay your borrow",