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

feat: ledger account selection screen add hd options to sync with extension #10755

Merged
merged 61 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f4cb635
feat: First draft version to set Ledger Live HD path.
dawnseeker8 Aug 20, 2024
50a5dfb
feat: Remove all copyright description in Ledger Select Account screen.
dawnseeker8 Aug 21, 2024
17a0852
Merge branch 'main' into feat/ledger-live-path-support
dawnseeker8 Aug 21, 2024
01c7e7e
feat: Working version without fixing the unit tests.
dawnseeker8 Aug 21, 2024
2a80ca1
feat: Fix all broken unit tests files in LedgerConnect screen and Led…
dawnseeker8 Aug 21, 2024
2c9c99a
Merge branch 'main' into feat/ledger-live-path-support
dawnseeker8 Aug 22, 2024
54e5868
feat: add Hd path drop down to LedgerAccountSelector screen.
dawnseeker8 Aug 22, 2024
00da3d9
Merge branch 'main' into feat/ledger-live-path-support
dawnseeker8 Aug 23, 2024
d99a3ff
Merge branch 'feat/ledger-live-path-support' into feat/10678-hd-optio…
dawnseeker8 Aug 23, 2024
5cc1346
feat: Fix the localization message after Alex feedback.
dawnseeker8 Aug 23, 2024
b709db9
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
dawnseeker8 Aug 27, 2024
2eff237
fix: fix the lint error.
dawnseeker8 Aug 27, 2024
e03fb5b
fix: remove the title in AccountSelector.ts and make it adapt to what…
dawnseeker8 Aug 27, 2024
4fda347
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
dawnseeker8 Aug 28, 2024
6fd773c
fix: Create a new component `SelectOptionSheet` to match the Gustova'…
dawnseeker8 Aug 29, 2024
5b41157
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
dawnseeker8 Aug 30, 2024
db17283
fix: Create a new component `SelectOptionSheet` to match the Gustova'…
dawnseeker8 Aug 30, 2024
3c72561
Merge remote-tracking branch 'origin/feat/10678-hd-options-sync-with-…
dawnseeker8 Aug 30, 2024
3adbec1
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
dawnseeker8 Aug 30, 2024
adc04f1
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
dawnseeker8 Sep 2, 2024
63d7af0
fix: Fix existing lint:tsc error and unit tests.
dawnseeker8 Sep 2, 2024
74ca01e
fix: Fix failure unit tests and update snapshot
dawnseeker8 Sep 2, 2024
12d1db8
fix: Improve unit tests code coverage.
dawnseeker8 Sep 2, 2024
423a0a6
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
dawnseeker8 Sep 2, 2024
06fdd38
fix: Improve unit tests code coverage in SelectOptionSheet.tsx
dawnseeker8 Sep 2, 2024
7d0e9da
fix: Fix the lint issue.
dawnseeker8 Sep 2, 2024
a5e3032
fix: Add basic OptionSheet snapshot tests.
dawnseeker8 Sep 2, 2024
c772c41
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
dawnseeker8 Sep 3, 2024
07b4897
fix: Fix the lint:tsc error and unit tests.
dawnseeker8 Sep 3, 2024
dd7ae34
fix: Improve the unit tests coverage.
dawnseeker8 Sep 3, 2024
e9ca0b5
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
dawnseeker8 Sep 4, 2024
f20484c
fix: minor change to ledger/constants.ts
dawnseeker8 Sep 4, 2024
734b517
fix: Fix the tsc:lint error after `update branch` and cause conflict …
dawnseeker8 Sep 4, 2024
c279586
Apply suggestions from code review
dawnseeker8 Sep 4, 2024
361eee9
Apply suggestions from code review
dawnseeker8 Sep 4, 2024
a874079
fix: update snapshot for unit tests.
dawnseeker8 Sep 4, 2024
dfe54bb
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
dawnseeker8 Sep 4, 2024
288ac23
fix: update snapshot for unit tests.
dawnseeker8 Sep 4, 2024
68d2f76
fix: update snapshot for unit tests.
dawnseeker8 Sep 4, 2024
a3def55
fix: Commit based on Niclos's code review feedback.
dawnseeker8 Sep 4, 2024
f32d7dc
fix: Refactory `LedgerSelectAccount` components.
dawnseeker8 Sep 4, 2024
e86f85f
fix: Refactor `LedgerSelectAccount` components.
dawnseeker8 Sep 4, 2024
36228de
fix: Remove the setTimeOut wrapper to close the OptionSheet.
dawnseeker8 Sep 5, 2024
05133fe
fix: Reset error message during each operation so that error wont sho…
dawnseeker8 Sep 5, 2024
21a9c91
fix: Remove the console.warning
dawnseeker8 Sep 5, 2024
23fef3e
fix: Fix the useEffect side effect loop during pagination to make the…
dawnseeker8 Sep 5, 2024
9dc0c39
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
dawnseeker8 Sep 5, 2024
d2380b5
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
dawnseeker8 Sep 6, 2024
d1a65da
fix: Add logic to render (lagecy) label when import legacy ledger pa…
dawnseeker8 Sep 6, 2024
40d87cd
fix: format the code
dawnseeker8 Sep 6, 2024
81967c4
fix: remove the console log.
dawnseeker8 Sep 6, 2024
5aa433d
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
dawnseeker8 Sep 9, 2024
ffb7bcc
fix: make the metric return correct readable HD path string.
dawnseeker8 Sep 9, 2024
f6ef011
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
vivek-consensys Sep 9, 2024
fddd001
fix: Refactor code based on Nicolas feedback.
dawnseeker8 Sep 9, 2024
16bb54e
Merge remote-tracking branch 'origin/feat/10678-hd-options-sync-with-…
dawnseeker8 Sep 9, 2024
8a95bfe
fix: fix the lint:tsc error
dawnseeker8 Sep 9, 2024
3ac093f
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
dawnseeker8 Sep 9, 2024
5119e9b
Merge branch 'main' into feat/10678-hd-options-sync-with-extension
dawnseeker8 Sep 10, 2024
1901f58
fix: fix sign message screen render `sign with ledger` error when con…
dawnseeker8 Sep 10, 2024
562f9f2
fix: fix the lint issue
dawnseeker8 Sep 10, 2024
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
Prev Previous commit
Next Next commit
fix: Create a new component SelectOptionSheet to match the Gustova'…
…s requirement to use new design pattern.
  • Loading branch information
dawnseeker8 committed Aug 29, 2024
commit 6fd773c4424d2bff47c252a674e78e183c9bc9f3
189 changes: 189 additions & 0 deletions app/components/UI/SelectOptionSheet/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SelectComponent should render correctly 1`] = `
<View
style={
{
"flex": 1,
}
}
>
<TouchableOpacity
onPress={[Function]}
>
<View
style={
{
"flexDirection": "row",
}
}
>
<Text
numberOfLines={1}
style={
{
"alignSelf": "flex-start",
"color": "#141618",
"flex": 1,
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
"paddingBottom": 10,
"paddingHorizontal": 15,
"paddingTop": 10,
}
}
>
option 2
</Text>
<Text
allowFontScaling={false}
style={
[
{
"color": "#141618",
"fontSize": 24,
},
{
"height": 25,
"justifyContent": "flex-end",
"marginRight": 10,
"marginTop": 7,
"textAlign": "right",
},
{
"fontFamily": "Material Icons",
"fontStyle": "normal",
"fontWeight": "normal",
},
{},
]
}
>
</Text>
</View>
</TouchableOpacity>
<Modal
animationType="none"
deviceHeight={null}
deviceWidth={null}
hardwareAccelerated={false}
hideModalContentWhileAnimating={false}
onBackdropPress={[Function]}
onModalHide={[Function]}
onModalWillHide={[Function]}
onModalWillShow={[Function]}
onRequestClose={[Function]}
panResponderThreshold={4}
scrollHorizontal={false}
scrollOffset={0}
scrollOffsetMax={0}
scrollTo={null}
statusBarTranslucent={false}
supportedOrientations={
[
"portrait",
"landscape",
]
}
swipeThreshold={100}
transparent={true}
visible={false}
/>
</View>
`;

exports[`SelectOptionSheet should render correctly 1`] = `
<View
style={
{
"flex": 1,
}
}
>
<TouchableOpacity
onPress={[Function]}
>
<View
style={
{
"flexDirection": "row",
}
}
>
<Text
numberOfLines={1}
style={
{
"alignSelf": "flex-start",
"color": "#141618",
"flex": 1,
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
"paddingBottom": 10,
"paddingHorizontal": 15,
"paddingTop": 10,
}
}
>
option 2
</Text>
<Text
allowFontScaling={false}
style={
[
{
"color": "#141618",
"fontSize": 24,
},
{
"height": 25,
"justifyContent": "flex-end",
"marginRight": 10,
"marginTop": 7,
"textAlign": "right",
},
{
"fontFamily": "Material Icons",
"fontStyle": "normal",
"fontWeight": "normal",
},
{},
]
}
>
</Text>
</View>
</TouchableOpacity>
<Modal
animationType="none"
deviceHeight={null}
deviceWidth={null}
hardwareAccelerated={false}
hideModalContentWhileAnimating={false}
onBackdropPress={[Function]}
onModalHide={[Function]}
onModalWillHide={[Function]}
onModalWillShow={[Function]}
onRequestClose={[Function]}
panResponderThreshold={4}
scrollHorizontal={false}
scrollOffset={0}
scrollOffsetMax={0}
scrollTo={null}
statusBarTranslucent={false}
supportedOrientations={
[
"portrait",
"landscape",
]
}
swipeThreshold={100}
transparent={true}
visible={false}
/>
</View>
`;
31 changes: 31 additions & 0 deletions app/components/UI/SelectOptionSheet/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import renderWithProvider from '../../../util/test/renderWithProvider';
import SelectOptionSheet, { iSelectOption } from './';

jest.mock('../../../core/Engine', () => ({
context: {
colors: {},
},
}));

describe('SelectOptionSheet', () => {
it('should render correctly', () => {
const options: iSelectOption[] = [
{ key: 'key 1', value: 'val 1', label: 'option 1' },
{ key: 'key 2', value: 'val 2', label: 'option 2' },
];

const mockOnValueChange = jest.fn();

const { toJSON } = renderWithProvider(
<SelectOptionSheet
options={options}
selectedValue={'val 2'}
label={'Choose an option'}
defaultValue={options[0].value}
onValueChange={mockOnValueChange}
/>,
);
expect(toJSON()).toMatchSnapshot();
});
});
139 changes: 139 additions & 0 deletions app/components/UI/SelectOptionSheet/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import React, { useRef, useState } from 'react';
import { ScrollView, Text, TouchableOpacity, View } from 'react-native';
import { baseStyles } from '../../../styles/common';
import Icon from 'react-native-vector-icons/MaterialIcons';
import Modal from 'react-native-modal';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import dismissKeyboard from 'react-native/Libraries/Utilities/dismissKeyboard';
import IconCheck from 'react-native-vector-icons/MaterialCommunityIcons';
import Device from '../../../util/device';
import { useTheme } from '../../../util/theme';
import createStyles, { ROW_HEIGHT } from './styles';

export interface iSelectOption {
key?: string;
value?: string;
label?: string;
}

interface iSelectOptionSheet {
defaultValue?: string;
label: string;
selectedValue?: string;
options: iSelectOption[];
onValueChange: (val: string | undefined) => void;
}

const SelectOptionSheet = ({
defaultValue,
label,
selectedValue,
options,
onValueChange,
}: iSelectOptionSheet) => {
const [pickerVisible, setPickerVisible] = useState(false);
const scrollView = useRef<ScrollView>(null);
const { colors } = useTheme();
const styles = createStyles(colors);

const onSelectedValueChange = (val?: string) => {
onValueChange(val);
setTimeout(() => {
setPickerVisible(false);
}, 1000);
};

const hidePicker = () => {
setPickerVisible(false);
};

const showPicker = () => {
dismissKeyboard();
setPickerVisible(true);
Device.isIos() &&
options.length > 13 &&
options.forEach((item, i) => {
if (item.value === selectedValue) {
setTimeout(() => {
scrollView?.current?.scrollTo({
x: 0,
y: i * ROW_HEIGHT,
animated: true,
});
}, 100);
}
});
};

const getSelectedValue = () => {
const el = options?.filter((o) => o.value === selectedValue);
if (el.length && el[0].label) {
return el[0].label;
}
if (defaultValue) {
return defaultValue;
}
return '';
};

const renderDropdownSelector = () => (
<View style={baseStyles.flexGrow}>
<TouchableOpacity onPress={showPicker}>
<View style={styles.dropdown}>
<Text style={styles.selectedOption} numberOfLines={1}>
{getSelectedValue()}
</Text>
<Icon
name={'arrow-drop-down'}
size={24}
color={colors.icon.default}
style={styles.iconDropdown}
/>
</View>
</TouchableOpacity>
<Modal
isVisible={pickerVisible}
onBackdropPress={hidePicker}
onBackButtonPress={hidePicker}
style={styles.modal}
useNativeDriver
backdropColor={colors.overlay.default}
backdropOpacity={1}
>
<View style={styles.modalView}>
<View style={styles.accesoryBar}>
<Text style={styles.label}>{label}</Text>
</View>
<ScrollView style={styles.list} ref={scrollView}>
<View style={styles.listWrapper}>
{options.map((option) => (
<TouchableOpacity
onPress={() => onSelectedValueChange(option.value)}
style={styles.optionButton}
key={option.key}
>
<Text style={styles.optionLabel} numberOfLines={1}>
{option.label}
</Text>
{selectedValue === option.value ? (
<IconCheck
style={styles.icon}
name="check"
size={24}
color={colors.primary.default}
/>
) : null}
</TouchableOpacity>
))}
</View>
</ScrollView>
</View>
</Modal>
</View>
);

return renderDropdownSelector();
};

export default SelectOptionSheet;
Loading
Loading