Skip to content

Commit

Permalink
fix: disable send shortcuts while contact prompt is active (#1692)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Sinclair <[email protected]>
Co-authored-by: Bruno Barbieri <[email protected]>
  • Loading branch information
3 people authored Sep 13, 2024
1 parent 37e2060 commit dc11fa4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 53 deletions.
39 changes: 23 additions & 16 deletions src/entries/popup/components/TransactionFee/TransactionFee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { SwitchTransactionSpeedMenu } from './TransactionSpeedsMenu';

type FeeProps = {
chainId: ChainId;
disableShortcuts?: boolean;
accentColor?: string;
plainTriggerBorder?: boolean;
selectedSpeed: GasSpeed;
Expand All @@ -71,6 +72,7 @@ function Fee({
analyticsEvents,
baseFeeTrend,
chainId,
disableShortcuts,
currentBaseFee,
gasFeeParamsBySpeed,
isLoading,
Expand Down Expand Up @@ -130,22 +132,24 @@ function Fee({

useKeyboardShortcut({
handler: (e: KeyboardEvent) => {
if (e.key === shortcuts.global.OPEN_CUSTOM_GAS_MENU.key) {
if (chainId === ChainId.mainnet) {
trackShortcut({
key: shortcuts.global.OPEN_CUSTOM_GAS_MENU.display,
type: 'customGasMenu.open',
});
// hackery preventing GweiInputMask from firing an onChange event when opening the menu with KB
setTimeout(() => openCustomGasSheet(), 0);
}
} else if (e.key === shortcuts.global.OPEN_GAS_MENU.key) {
if (chainId === ChainId.mainnet || chainId === ChainId.polygon) {
trackShortcut({
key: shortcuts.global.OPEN_GAS_MENU.display,
type: 'gasMenu.open',
});
switchTransactionSpeedMenuRef?.current?.open();
if (!disableShortcuts) {
if (e.key === shortcuts.global.OPEN_CUSTOM_GAS_MENU.key) {
if (chainId === ChainId.mainnet) {
trackShortcut({
key: shortcuts.global.OPEN_CUSTOM_GAS_MENU.display,
type: 'customGasMenu.open',
});
// hackery preventing GweiInputMask from firing an onChange event when opening the menu with KB
setTimeout(() => openCustomGasSheet(), 0);
}
} else if (e.key === shortcuts.global.OPEN_GAS_MENU.key) {
if (chainId === ChainId.mainnet || chainId === ChainId.polygon) {
trackShortcut({
key: shortcuts.global.OPEN_GAS_MENU.display,
type: 'gasMenu.open',
});
switchTransactionSpeedMenuRef?.current?.open();
}
}
}
},
Expand Down Expand Up @@ -256,6 +260,7 @@ function Fee({

type TransactionFeeProps = {
chainId: ChainId;
disableShortcuts?: boolean;
address?: Address;
defaultSpeed?: GasSpeed;
transactionRequest: TransactionRequest;
Expand All @@ -271,6 +276,7 @@ type TransactionFeeProps = {

export function TransactionFee({
chainId,
disableShortcuts,
address,
defaultSpeed,
transactionRequest,
Expand Down Expand Up @@ -302,6 +308,7 @@ export function TransactionFee({
return (
<Fee
analyticsEvents={analyticsEvents}
disableShortcuts={disableShortcuts}
chainId={chainId}
accentColor={accentColor}
plainTriggerBorder={plainTriggerBorder}
Expand Down
77 changes: 40 additions & 37 deletions src/entries/popup/pages/send/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -550,49 +550,51 @@ export function Send() {

useKeyboardShortcut({
handler: (e: KeyboardEvent) => {
if (e.altKey) {
if (e.key === shortcuts.send.FOCUS_TO_ADDRESS.key) {
trackShortcut({
key: shortcuts.send.FOCUS_TO_ADDRESS.display,
type: 'send.focusToAddress',
});
toAddressInputRef?.current?.focus();
sendTokenInputRef?.current?.blur();
}
if (e.key === shortcuts.send.FOCUS_ASSET.key) {
trackShortcut({
key: shortcuts.send.FOCUS_ASSET.display,
type: 'send.focusAsset',
});
toAddressInputRef?.current?.blur();
sendTokenInputRef.current?.focus();
}
} else {
if (!toAddressInputRef.current?.isFocused?.()) {
if (e.key === shortcuts.send.SET_MAX_AMOUNT.key) {
if (!explainerSheetParams.show && !contactSaveAction.show) {
if (e.altKey) {
if (e.key === shortcuts.send.FOCUS_TO_ADDRESS.key) {
trackShortcut({
key: shortcuts.send.SET_MAX_AMOUNT.display,
type: 'send.setMax',
key: shortcuts.send.FOCUS_TO_ADDRESS.display,
type: 'send.focusToAddress',
});
setMaxAssetAmount();
toAddressInputRef?.current?.focus();
sendTokenInputRef?.current?.blur();
}
if (e.key === shortcuts.send.SWITCH_CURRENCY_LABEL.key) {
if (e.key === shortcuts.send.FOCUS_ASSET.key) {
trackShortcut({
key: shortcuts.send.SWITCH_CURRENCY_LABEL.display,
type: 'send.switchCurrency',
key: shortcuts.send.FOCUS_ASSET.display,
type: 'send.focusAsset',
});
switchIndependentField();
toAddressInputRef?.current?.blur();
sendTokenInputRef.current?.focus();
}
} else {
if (!toAddressInputRef.current?.isFocused?.()) {
if (e.key === shortcuts.send.SET_MAX_AMOUNT.key) {
trackShortcut({
key: shortcuts.send.SET_MAX_AMOUNT.display,
type: 'send.setMax',
});
setMaxAssetAmount();
}
if (e.key === shortcuts.send.SWITCH_CURRENCY_LABEL.key) {
trackShortcut({
key: shortcuts.send.SWITCH_CURRENCY_LABEL.display,
type: 'send.switchCurrency',
});
switchIndependentField();
}
}
if (
e.key === shortcuts.send.OPEN_CONTACT_MENU.key &&
!valueInputRef.current?.isFocused?.()
) {
trackShortcut({
key: shortcuts.send.OPEN_CONTACT_MENU.display,
type: 'send.openContactMenu',
});
clickHeaderRight();
}
}
if (
e.key === shortcuts.send.OPEN_CONTACT_MENU.key &&
!valueInputRef.current?.isFocused?.()
) {
trackShortcut({
key: shortcuts.send.OPEN_CONTACT_MENU.display,
type: 'send.openContactMenu',
});
clickHeaderRight();
}
}
},
Expand Down Expand Up @@ -753,6 +755,7 @@ export function Send() {
<Rows space="20px">
<Row>
<TransactionFee
disableShortcuts={contactSaveAction.show}
chainId={chainId}
transactionRequest={transactionRequestForGas}
accentColor={assetAccentColor}
Expand Down

0 comments on commit dc11fa4

Please sign in to comment.