Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2094 from LedgerHQ/custom-manifest
Browse files Browse the repository at this point in the history
Load custom platform manifest
  • Loading branch information
JunichiSugiura authored Jan 11, 2022
2 parents 41b1c17 + c2ff894 commit 7075e48
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 25 deletions.
11 changes: 10 additions & 1 deletion src/components/RootNavigator/SettingsNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import DebugSettings, {
} from "../../screens/Settings/Debug";
import DebugExport from "../../screens/Settings/Debug/ExportAccounts";
import ExperimentalSettings from "../../screens/Settings/Experimental";
import DeveloperSettings from "../../screens/Settings/Developer";
import DeveloperSettings, {
DeveloperCustomManifest,
} from "../../screens/Settings/Developer";
import RepairDevice from "../../screens/RepairDevice";
import { getStackNavigatorConfig } from "../../navigation/navigatorConfig";
import Button from "../Button";
Expand Down Expand Up @@ -126,6 +128,13 @@ export default function SettingsNavigator() {
title: t("settings.developer.title"),
}}
/>
<Stack.Screen
name={ScreenName.DeveloperCustomManifest}
component={DeveloperCustomManifest}
options={{
title: t("settings.developer.customManifest.title"),
}}
/>
<Stack.Screen
name={ScreenName.DebugSettings}
component={DebugSettings}
Expand Down
1 change: 1 addition & 0 deletions src/const/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const ScreenName = {
DelegationValidationError: "DelegationValidationError",
DelegationValidationSuccess: "DelegationValidationSuccess",
DeveloperSettings: "DeveloperSettings",
DeveloperCustomManifest: "DeveloperCustomManifest",
DisplayResult: "DisplayResult",
Distribution: "Distribution",
EditAccountName: "EditAccountName",
Expand Down
5 changes: 4 additions & 1 deletion src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,10 @@
},
"developer": {
"title": "Developer",
"desc": "Try out the Developer features and let us know what you think."
"desc": "Try out the Developer features and let us know what you think.",
"customManifest": {
"title": "Load Custom Platform Manifest"
}
}
},
"migrateAccounts": {
Expand Down
23 changes: 0 additions & 23 deletions src/screens/Settings/Developer.js

This file was deleted.

107 changes: 107 additions & 0 deletions src/screens/Settings/Developer/CustomManifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// @flow
import React, { useState, useMemo, useCallback } from "react";
import { TextInput, StyleSheet } from "react-native";
import { useTheme, NavigationProp } from "@react-navigation/native";
import { usePlatformApp } from "@ledgerhq/live-common/lib/platform/PlatformAppProvider";
import NavigationScrollView from "../../../components/NavigationScrollView";
import Button from "../../../components/Button";
import { ScreenName } from "../../../const";

export default function CustomManifest({
navigation,
}: {
navigation: NavigationProp,
}) {
const { colors } = useTheme();
const {
manifest,
disabled,
addLocalManifest,
onChange,
} = useCustomManifest();

const onOpen = useCallback(() => {
const json = JSON.parse(manifest);

Array.isArray(json)
? json.map(m => addLocalManifest(m))
: addLocalManifest(json);

const params = Array.isArray(json)
? { platform: json[0].id, name: json[0].name }
: { platform: json.id, name: json.name };

navigation.navigate({
name: ScreenName.PlatformApp,
params,
});
}, [manifest, addLocalManifest, navigation]);

return (
<NavigationScrollView contentContainerStyle={styles.root}>
<TextInput
style={[
styles.input,
{ color: colors.text, borderColor: colors.border },
]}
value={manifest}
onChangeText={onChange}
placeholder="Paste your manufest json"
multiline
autoCorrect={false}
/>
<Button
type="primary"
title="Open"
disabled={disabled}
onPress={onOpen}
/>
</NavigationScrollView>
);
}

function useCustomManifest() {
const [manifest, setManifest] = useState("");
const { addLocalManifest } = usePlatformApp();

const onChange = useCallback(val => {
try {
const json = JSON.parse(val);
setManifest(JSON.stringify(json, null, 2));
} catch (e) {
setManifest(val);
}
}, []);

const disabled = useMemo(() => {
if (!manifest) {
return true;
}

try {
JSON.parse(manifest);
return false;
} catch (e) {
return true;
}
}, [manifest]);

return {
manifest,
disabled,
onChange,
addLocalManifest,
};
}

const styles = StyleSheet.create({
root: {
flex: 1,
padding: 16,
},
input: {
flex: 1,
borderWidth: 1,
marginBottom: 16,
},
});
37 changes: 37 additions & 0 deletions src/screens/Settings/Developer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// @flow
import { NavigationProp } from "@react-navigation/native";
import { isEnvDefault } from "@ledgerhq/live-common/lib/env";
import React from "react";
import { ScrollView } from "react-native";
import SettingsRow from "../../../components/SettingsRow";
import { ScreenName } from "../../../const";
import { developerFeatures } from "../../../experimental";
import { TrackScreen } from "../../../analytics";
import FeatureRow from "../Experimental/FeatureRow";

export { default as DeveloperCustomManifest } from "./CustomManifest";

export default function DeveloperSettings({
navigation,
}: {
navigation: NavigationProp,
}) {
return (
<ScrollView>
<TrackScreen category="Settings" name="Developer" />

{developerFeatures.map(
feat =>
(!feat.shadow || (feat.shadow && !isEnvDefault(feat.name))) && (
// $FlowFixMe
<FeatureRow key={feat.name} feature={feat} />
),
)}

<SettingsRow
title="Load Platform Manifest"
onPress={() => navigation.navigate(ScreenName.DeveloperCustomManifest)}
/>
</ScrollView>
);
}

0 comments on commit 7075e48

Please sign in to comment.