This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2094 from LedgerHQ/custom-manifest
Load custom platform manifest
- Loading branch information
Showing
6 changed files
with
159 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |