Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android Only] Some buttons are not working #5149

Merged
merged 6 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions src/components/change-wallet/AddressRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Icon } from '../icons';
import { Centered, Column, ColumnWithMargins, Row } from '../layout';
import { Text, TruncatedText } from '../text';
import ContextMenuButton from '@/components/native-context-menu/contextMenu';
import ContextMenuAndroid from '@/components/native-context-menu/contextMenu.android';
import useExperimentalFlag, { NOTIFICATIONS } from '@/config/experimentalHooks';
import {
removeFirstEmojiFromString,
Expand All @@ -25,6 +24,7 @@ import { abbreviations, deviceUtils, profileUtils } from '@/utils';
import { EditWalletContextMenuActions } from '@/screens/ChangeWalletSheet';
import { toChecksumAddress } from '@/handlers/web3';
import { IS_IOS, IS_ANDROID } from '@/env';
import { ContextMenu } from '../context-menu';

const maxAccountLabelWidth = deviceUtils.dimensions.width - 88;
const NOOP = () => undefined;
Expand Down Expand Up @@ -219,6 +219,25 @@ export default function AddressRow({
menuTitle: walletName,
};

const handleSelectActionMenuItem = useCallback(
(buttonIndex: number) => {
switch (buttonIndex) {
case 0:
contextMenuActions?.edit(walletId, address);
break;
case 1:
contextMenuActions?.notifications(walletName, address);
break;
case 2:
contextMenuActions?.remove(walletId, address);
break;
default:
break;
}
},
[contextMenuActions, walletName, walletId, address]
);

const handleSelectMenuItem = useCallback(
// @ts-expect-error ContextMenu is an untyped JS component and can't type its onPress handler properly
({ nativeEvent: { actionKey } }) => {
Expand Down Expand Up @@ -316,14 +335,15 @@ export default function AddressRow({
<OptionsIcon onPress={NOOP} />
</ContextMenuButton>
) : (
// @ts-expect-error js component
<ContextMenuAndroid
menuConfig={menuConfig}
<ContextMenu
options={menuConfig.menuItems.map(item => item.actionTitle)}
isAnchoredToRight
onPressMenuItem={handleSelectMenuItem}
onPressActionSheet={handleSelectActionMenuItem}
>
<OptionsIcon onPress={NOOP} />
</ContextMenuAndroid>
<Centered>
<OptionsIcon onPress={NOOP} />
</Centered>
</ContextMenu>
))}
</Column>
</Row>
Expand Down
45 changes: 45 additions & 0 deletions src/components/gas/GasSpeedButton.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-nested-ternary */
/* eslint-disable no-undef */
import AnimateNumber from '@bankify/react-native-animate-number';
import lang from 'i18n-js';
Expand Down Expand Up @@ -34,6 +35,8 @@ import styled from '@/styled-thing';
import { fonts, fontWithWidth, margin, padding } from '@/styles';
import { ethereumUtils, gasUtils } from '@/utils';
import { getNetworkObj } from '@/networks';
import { IS_ANDROID } from '@/env';
import { ContextMenu } from '../context-menu';

const {
GAS_EMOJIS,
Expand Down Expand Up @@ -249,6 +252,7 @@ const GasSpeedButton = ({
shouldOpenCustomGasSheet.focusTo,
flashbotTransaction,
speeds,
fallbackColor,
]);

const openCustomOptions = useCallback(
Expand Down Expand Up @@ -377,6 +381,25 @@ const GasSpeedButton = ({
[handlePressSpeedOption]
);

const handlePressActionSheet = useCallback(
buttonIndex => {
switch (buttonIndex) {
case 0:
handlePressSpeedOption(NORMAL);
break;
case 1:
handlePressSpeedOption(FAST);
break;
case 2:
handlePressSpeedOption(URGENT);
break;
case 3:
handlePressSpeedOption(CUSTOM);
}
},
[handlePressSpeedOption]
);

const nativeFeeCurrency = useMemo(() => {
switch (currentNetwork) {
case networkTypes.polygon:
Expand All @@ -399,6 +422,8 @@ const GasSpeedButton = ({

const menuConfig = useMemo(() => {
const menuOptions = speedOptions.map(gasOption => {
if (IS_ANDROID) return gasOption;

const totalGwei = add(
gasFeeParamsBySpeed[gasOption]?.maxBaseFee?.gwei,
gasFeeParamsBySpeed[gasOption]?.maxPriorityFeePerGas?.gwei
Expand Down Expand Up @@ -441,6 +466,7 @@ const GasSpeedButton = ({
gasFeeParamsBySpeed,
selectedGasFeeOption,
speedOptions,
isL2,
]);

const gasOptionsAvailable = useMemo(() => speedOptions.length > 1, [
Expand Down Expand Up @@ -477,6 +503,24 @@ const GasSpeedButton = ({
/>
);
if (!gasOptionsAvailable || gasIsNotReady) return pager;

if (IS_ANDROID) {
return (
<ContextMenu
activeOpacity={0}
enableContextMenu
isAnchoredToRight
isMenuPrimaryAction
onPressActionSheet={handlePressActionSheet}
options={menuConfig.menuItems}
useActionSheetFallback={false}
wrapNativeComponent={false}
>
<Centered>{pager}</Centered>
</ContextMenu>
);
}

return (
<ContextMenuButton
activeOpacity={0}
Expand Down Expand Up @@ -543,6 +587,7 @@ const GasSpeedButton = ({
onPress={openGasHelper}
scaleTo={0.9}
testID="estimated-fee-label"
disallowInterruption={false}
>
<Row>
<NativeCoinIconWrapper>
Expand Down
2 changes: 1 addition & 1 deletion src/components/positions/PositionsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const PositionCard = ({ position }: PositionCardProps) => {
}, [navigate, position]);

const depositTokens: CoinStackToken[] = useMemo(() => {
let tokens: CoinStackToken[] = [];
const tokens: CoinStackToken[] = [];
position.deposits.forEach((deposit: RainbowDeposit) => {
deposit.underlying.forEach(({ asset }) => {
tokens.push({
Expand Down
141 changes: 97 additions & 44 deletions src/screens/ENSIntroSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useRoute } from '@react-navigation/native';
import { IS_TESTING } from 'react-native-dotenv';
import lang from 'i18n-js';
import React, { useCallback, useMemo } from 'react';
import { InteractionManager } from 'react-native';
import { InteractionManager, View } from 'react-native';
import { MenuActionConfig } from 'react-native-ios-context-menu';
import LinearGradient from 'react-native-linear-gradient';
import ActivityIndicator from '../components/ActivityIndicator';
Expand Down Expand Up @@ -35,6 +35,8 @@ import {
} from '@/hooks';
import Routes from '@/navigation/routesNames';
import { useTheme } from '@/theme';
import { IS_ANDROID } from '@/env';
import ContextMenu from '@/components/context-menu/ContextMenu.android';

enum AnotherENSEnum {
search = 'search',
Expand All @@ -45,6 +47,92 @@ const topPadding = android ? 29 : 19;

const minHeight = 740;

type ContextMenuRendererProps = {
children: React.ReactNode;
handleSelectExistingName: () => void;
handleNavigateToSearch: () => void;
};

const ContextMenuRenderer = ({
children,
handleSelectExistingName,
handleNavigateToSearch,
}: ContextMenuRendererProps) => {
const menuConfig = useMemo(() => {
return {
menuItems: [
{
actionKey: AnotherENSEnum.my_ens,
actionTitle: lang.t('profiles.intro.my_ens_names'),
icon: {
iconType: 'SYSTEM',
iconValue: 'rectangle.stack.badge.person.crop',
},
},
{
actionKey: AnotherENSEnum.search,
actionTitle: lang.t('profiles.intro.search_new_ens'),
icon: {
iconType: 'SYSTEM',
iconValue: 'magnifyingglass',
},
},
] as MenuActionConfig[],
menuTitle: '',
};
}, []);

const handlePressMenuItem = useCallback(
// @ts-expect-error ContextMenu is an untyped JS component and can't type its onPress handler properly
({ nativeEvent: { actionKey } }) => {
if (actionKey === AnotherENSEnum.my_ens) {
handleSelectExistingName();
} else if (actionKey === AnotherENSEnum.search) {
handleNavigateToSearch();
}
},
[handleNavigateToSearch, handleSelectExistingName]
);

const handlePressActionSheet = useCallback(
(buttonIndex: number) => {
switch (buttonIndex) {
case 0:
handleSelectExistingName();
break;
case 1:
handleNavigateToSearch();
break;
}
},
[handleNavigateToSearch, handleSelectExistingName]
);

if (IS_ANDROID) {
return (
<ContextMenu
activeOpacity={0}
cancelButtonIndex={menuConfig.menuItems.length - 1}
dynamicOptions={undefined}
onPressActionSheet={handlePressActionSheet}
options={menuConfig.menuItems.map(i => i.actionTitle)}
>
<View>{children}</View>
</ContextMenu>
);
}

return (
<ContextMenuButton
menuConfig={menuConfig}
onPressMenuItem={handlePressMenuItem}
useActionSheetFallback={false}
>
{children}
</ContextMenuButton>
);
};

export default function ENSIntroSheet() {
const { width: deviceWidth, height: deviceHeight } = useDimensions();
const { colors } = useTheme();
Expand All @@ -64,6 +152,8 @@ export default function ENSIntroSheet() {
enabled: Boolean(uniqueDomain?.name),
});

console.log(nonPrimaryDomains.length);

// We are not using `isSmallPhone` from `useDimensions` here as we
// want to explicitly set a min height.
const isSmallPhone = deviceHeight < minHeight;
Expand Down Expand Up @@ -121,42 +211,6 @@ export default function ENSIntroSheet() {
});
}, [navigate, navigateToAssignRecords]);

const menuConfig = useMemo(() => {
return {
menuItems: [
{
actionKey: AnotherENSEnum.my_ens,
actionTitle: lang.t('profiles.intro.my_ens_names'),
icon: {
iconType: 'SYSTEM',
iconValue: 'rectangle.stack.badge.person.crop',
},
},
{
actionKey: AnotherENSEnum.search,
actionTitle: lang.t('profiles.intro.search_new_ens'),
icon: {
iconType: 'SYSTEM',
iconValue: 'magnifyingglass',
},
},
] as MenuActionConfig[],
menuTitle: '',
};
}, []);

const handlePressMenuItem = useCallback(
// @ts-expect-error ContextMenu is an untyped JS component and can't type its onPress handler properly
({ nativeEvent: { actionKey } }) => {
if (actionKey === AnotherENSEnum.my_ens) {
handleSelectExistingName();
} else if (actionKey === AnotherENSEnum.search) {
handleNavigateToSearch();
}
},
[handleNavigateToSearch, handleSelectExistingName]
);

return (
<Box
background="body (Deprecated)"
Expand Down Expand Up @@ -292,12 +346,11 @@ export default function ENSIntroSheet() {
/>
)}
{nonPrimaryDomains?.length > 0 ? (
<ContextMenuButton
menuConfig={menuConfig}
{...(android ? { handlePressMenuItem } : {})}
isMenuPrimaryAction
onPressMenuItem={handlePressMenuItem}
useActionSheetFallback={false}
<ContextMenuRenderer
handleNavigateToSearch={handleNavigateToSearch}
handleSelectExistingName={
handleSelectExistingName
}
>
<SheetActionButton
color={colors.transparent}
Expand All @@ -309,7 +362,7 @@ export default function ENSIntroSheet() {
textSize="lmedium"
weight="bold"
/>
</ContextMenuButton>
</ContextMenuRenderer>
) : (
<SheetActionButton
color={colors.transparent}
Expand Down
Loading
Loading