Skip to content

Commit

Permalink
Merge pull request #4662 from LedgerHQ/support/fix-ledger-manager-wor…
Browse files Browse the repository at this point in the history
…ding

Use translations for Ledger Manager instead of hardcoded value
  • Loading branch information
KVNLS authored Sep 18, 2023
2 parents 49ea3fd + e3ea552 commit 047f7e4
Show file tree
Hide file tree
Showing 23 changed files with 85 additions and 73 deletions.
28 changes: 16 additions & 12 deletions apps/ledger-live-desktop/MOCK.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,35 @@
In order to be able to complete all OK/KO cases of all flows for testing and development, we expose a way to mock events that require interaction with a real device. When running with the env variable `MOCK` you'll have access to `mockDeviceEvent` which receives one or more events that will be emitted to the subscribed observers triggering the associated actions.

### Dev

Simply open the console, `mockDeviceEvent` is available as a global window variable. Pass the snippet below or any event of your liking to that method.

### QA

As it's done in the `onboarding.spec.js` file, we need to get access to that method via a call to `const mockeDeviceEvent = getMockDeviceEvent(app)` afterward the functionality of the method is the same as for dev with the exception of having to `await` the result to not break the tests.

## What is this useful for?
It allows us to interact with all parts of the application without the need for a real device or real accounts.

It allows us to interact with all parts of the application without the need for a real device or real accounts.

## Snippets per-flow

These are a series of snippets that allow you to reach the OK and KO ends of a device interaction for each of the flows. For the KOs, we can essentially use the name of any error and it will throw it, depending on the flow ones make more sense than others.

### Successfully opening an app

```js
mockDeviceEvent({ type: "opened" })
mockDeviceEvent({ type: "opened" });
```

### Device allow events

```js
mockDeviceEvent({ type: "device-permission-requested", wording: "Allow manager" })
mockDeviceEvent({ type: "device-permission-requested" });
```

```js
mockDeviceEvent({ type: "device-permission-granted" })
mockDeviceEvent({ type: "device-permission-granted" });
```

### Genuine Check / Manager termination
Expand All @@ -37,14 +41,14 @@ mockDeviceEvent({ type: "opened" })
Refer to the signature of `mockListAppsResult` to see the doors it opens. But a tldr is the first parameter are the apps available in the catalog, the second is the list of installed apps.

```js
mockDeviceEvent(
{ type: "listingApps", deviceInfo: deviceInfo155 },
{
type: "result",
result: mockListAppsResult("Bitcoin", "Bitcoin", deviceInfo155),
}
)
```
mockDeviceEvent(
{ type: "listingApps", deviceInfo: deviceInfo155 },
{
type: "result",
result: mockListAppsResult("Bitcoin", "Bitcoin", deviceInfo155),
},
);
```

#### Error samples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ type States = PartialNullable<{
managerAppName?: string;
};
isLoading: boolean;
allowManagerRequestedWording: string;
allowManagerRequested: boolean;
allowRenamingRequested: boolean;
requestQuitApp: boolean;
deviceInfo: DeviceInfo;
latestFirmware: unknown;
Expand Down Expand Up @@ -182,7 +183,8 @@ export const DeviceActionDefaultRendering = <R, H extends States, P>({
isLocked,
error,
isLoading,
allowManagerRequestedWording,
allowManagerRequested,
allowRenamingRequested,
imageRemoveRequested,
requestQuitApp,
deviceInfo,
Expand Down Expand Up @@ -288,9 +290,12 @@ export const DeviceActionDefaultRendering = <R, H extends States, P>({
return renderRequiresAppInstallation({ appNames });
}

if (allowManagerRequestedWording) {
const wording = allowManagerRequestedWording;
return renderAllowManager({ modelId, type, wording });
if (allowRenamingRequested) {
return renderAllowManager({ modelId, type, requestType: "rename" });
}

if (allowManagerRequested) {
return renderAllowManager({ modelId, type });
}

if (languageInstallationRequested) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,11 @@ export const renderListingApps = () => (
export const renderAllowManager = ({
modelId,
type,
wording,
requestType = "manager",
}: {
modelId: DeviceModelId;
type: Theme["theme"];
wording: string;
requestType?: "manager" | "rename";
}) => (
<Wrapper>
<DeviceBlocker />
Expand All @@ -420,7 +420,11 @@ export const renderAllowManager = ({
</AnimationWrapper>
<Footer>
<Title>
<Trans i18nKey="DeviceAction.allowManagerPermission" values={{ wording }} />
{requestType === "rename" ? (
<Trans i18nKey="DeviceAction.allowRenaming" />
) : (
<Trans i18nKey="DeviceAction.allowManagerPermission" />
)}
</Title>
</Footer>
</Wrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ const helpfulEvents = [
name: "permission requested",
event: {
type: "device-permission-requested",
wording: "Allow Ledger Manager",
},
},
{
Expand Down
3 changes: 2 additions & 1 deletion apps/ledger-live-desktop/static/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,8 @@
"DeviceAction": {
"allowAppPermission": "Open the {{wording}} app on your device",
"allowAppPermissionSubtitleToken": "to manage your {{token}} tokens",
"allowManagerPermission": "Allow {{wording}} on your device",
"allowManagerPermission": "Allow Ledger Manager on your device",
"allowRenaming": "Allow renaming on your device",
"loading": "Loading...",
"connectAndUnlockDevice": "Connect and unlock your device",
"unlockDevice": "Unlock your device",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const InstallSetOfApps = ({
const status = action.useHook(userConfirmed ? selectedDevice : undefined, commandRequest);

const {
allowManagerRequestedWording,
allowManagerRequested,
skippedAppOps,
installQueue,
listedApps,
Expand Down Expand Up @@ -160,7 +160,7 @@ const InstallSetOfApps = ({
})}
</Flex>
<QueuedDrawer
isRequestingToBeOpened={!!allowManagerRequestedWording || !!error}
isRequestingToBeOpened={allowManagerRequested || !!error}
onClose={onWrappedError}
onModalHide={onWrappedError}
>
Expand Down
19 changes: 14 additions & 5 deletions apps/ledger-live-mobile/src/components/DeviceAction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ type Status = PartialNullable<{
managerAppName?: string;
};
isLoading: boolean;
allowManagerRequestedWording: string;
allowManagerRequested: boolean;
allowRenamingRequested: boolean;
requestQuitApp: boolean;
deviceInfo: DeviceInfo;
requestOpenApp: string;
Expand Down Expand Up @@ -184,7 +185,8 @@ export function DeviceActionDefaultRendering<R, H extends Status, P>({
isLocked,
error,
isLoading,
allowManagerRequestedWording,
allowManagerRequested,
allowRenamingRequested,
requestQuitApp,
deviceInfo,
requestOpenApp,
Expand Down Expand Up @@ -314,15 +316,22 @@ export function DeviceActionDefaultRendering<R, H extends Status, P>({
theme,
});
}
if (allowManagerRequested) {
return renderAllowManager({
t,
device: selectedDevice,
colors,
theme,
});
}

if (allowManagerRequestedWording) {
const wording = allowManagerRequestedWording;
if (allowRenamingRequested) {
return renderAllowManager({
t,
device: selectedDevice,
wording,
colors,
theme,
requestType: "rename",
});
}

Expand Down
16 changes: 10 additions & 6 deletions apps/ledger-live-mobile/src/components/DeviceAction/rendering.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,22 +378,26 @@ export function renderConfirmSell({

export function renderAllowManager({
t,
wording,
device,
theme,
requestType = "manager",
}: RawProps & {
wording: string;
device: Device;
requestType?: "manager" | "rename";
}) {
// TODO: disable gesture, modal close, hide header buttons
return (
<Wrapper pb={6} pt={6}>
<Flex>
<Text fontWeight="semiBold" fontSize={24} textAlign="center" mb={10}>
{t("DeviceAction.allowManagerPermission", {
wording,
productName: getDeviceModel(device.modelId)?.productName,
})}
{t(
requestType === "rename"
? "DeviceAction.allowRenaming"
: "DeviceAction.allowManagerPermission",
{
productName: getDeviceModel(device.modelId)?.productName,
},
)}
</Text>
</Flex>
<AnimationContainer>
Expand Down
3 changes: 2 additions & 1 deletion apps/ledger-live-mobile/src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -3774,7 +3774,8 @@
"stayInTheAppPlz": "Stay in the Ledger Live app and keep your Ledger nearby.",
"allowAppPermission": "Open the {{wording}} app on your device",
"allowAppPermissionSubtitleToken": "to manage your {{token}} tokens",
"allowManagerPermission": "Allow {{wording}} on your {{productName}}",
"allowManagerPermission": "Allow Ledger Manager on your {{productName}}",
"allowRenaming": "Allow renaming on your {{productName}}",
"allowRemoveCustomLockscreen": "Confirm removal of image on your Ledger Stax",
"allowSecureConnection": "Allow a secure connection with Ledger",
"loading": "Loading...",
Expand Down
8 changes: 4 additions & 4 deletions apps/ledger-live-mobile/src/screens/FirmwareUpdate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ export const FirmwareUpdate = ({
});
}

if (restoreAppsState.allowManagerRequestedWording) {
if (restoreAppsState.allowManagerRequested) {
return (
<AllowManager
device={device}
Expand All @@ -547,7 +547,7 @@ export const FirmwareUpdate = ({
);
}

if (connectManagerState.allowManagerRequestedWording) {
if (connectManagerState.allowManagerRequested) {
return <AllowManager device={device} wording={t("DeviceAction.allowSecureConnection")} />;
}

Expand Down Expand Up @@ -664,8 +664,8 @@ export const FirmwareUpdate = ({
hasReconnectErrors,
staxLoadImageState.imageLoadRequested,
staxLoadImageState.imageCommitRequested,
restoreAppsState.allowManagerRequestedWording,
connectManagerState.allowManagerRequestedWording,
restoreAppsState.allowManagerRequested,
connectManagerState.allowManagerRequested,
installLanguageState.languageInstallationRequested,
restoreStepDeniedError,
userSolvableError,
Expand Down
2 changes: 0 additions & 2 deletions libs/ledger-live-common/src/apps/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export type InstalledItem = {
export type ListAppsEvent =
| {
type: "device-permission-requested";
wording: string;
}
| {
type: "device-permission-granted";
Expand All @@ -35,7 +34,6 @@ export type ListAppsEvent =
export type InlineAppInstallEvent =
| {
type: "device-permission-requested";
wording: string;
}
| {
type: "listing-apps";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type FilteredSocketEvent =
}
| {
type: "device-permission-requested";
wording: string;
};

export type InstallFirmwareCommandEvent =
Expand Down
18 changes: 9 additions & 9 deletions libs/ledger-live-common/src/hw/actions/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type State = {
unresponsive: boolean;
allowOpeningRequestedWording: string | null | undefined;
allowOpeningGranted: boolean;
allowManagerRequestedWording: string | null | undefined;
allowManagerRequested: boolean;
allowManagerGranted: boolean;
device: Device | null | undefined;
deviceInfo?: DeviceInfo | null | undefined;
Expand Down Expand Up @@ -140,7 +140,7 @@ const getInitialState = (device?: Device | null | undefined, request?: AppReques
requiresAppInstallation: null,
allowOpeningRequestedWording: null,
allowOpeningGranted: false,
allowManagerRequestedWording: null,
allowManagerRequested: false,
allowManagerGranted: false,
device: null,
deviceInfo: null,
Expand Down Expand Up @@ -200,7 +200,7 @@ const reducer = (state: State, e: Event): State => {
requiresAppInstallation: null,
allowOpeningRequestedWording: null,
allowOpeningGranted: true,
allowManagerRequestedWording: null,
allowManagerRequested: false,
allowManagerGranted: true,
device: state.device,
opened: false,
Expand Down Expand Up @@ -251,7 +251,7 @@ const reducer = (state: State, e: Event): State => {
requiresAppInstallation: null,
allowOpeningRequestedWording: null,
allowOpeningGranted: false,
allowManagerRequestedWording: null,
allowManagerRequested: false,
allowManagerGranted: false,
device: state.device,
opened: false,
Expand All @@ -274,7 +274,7 @@ const reducer = (state: State, e: Event): State => {
requiresAppInstallation: null,
allowOpeningRequestedWording: null,
allowOpeningGranted: false,
allowManagerRequestedWording: null,
allowManagerRequested: false,
allowManagerGranted: false,
device: state.device,
opened: false,
Expand Down Expand Up @@ -307,7 +307,7 @@ const reducer = (state: State, e: Event): State => {
allowOpeningGranted: false,
allowOpeningRequestedWording: null,
allowManagerGranted: false,
allowManagerRequestedWording: e.wording,
allowManagerRequested: true,

request: state.request,
skippedAppOps: state.skippedAppOps,
Expand All @@ -331,7 +331,7 @@ const reducer = (state: State, e: Event): State => {
allowOpeningGranted: true,
allowOpeningRequestedWording: null,
allowManagerGranted: true,
allowManagerRequestedWording: null,
allowManagerRequested: false,

request: state.request,
skippedAppOps: state.skippedAppOps,
Expand All @@ -355,7 +355,7 @@ const reducer = (state: State, e: Event): State => {
allowOpeningGranted: false,
allowOpeningRequestedWording: null,
allowManagerGranted: false,
allowManagerRequestedWording: null,
allowManagerRequested: false,
requiresAppInstallation: {
appNames: e.appNames,
appName: e.appName,
Expand All @@ -380,7 +380,7 @@ const reducer = (state: State, e: Event): State => {
allowOpeningGranted: false,
allowOpeningRequestedWording: null,
allowManagerGranted: false,
allowManagerRequestedWording: null,
allowManagerRequested: false,
device: state.device,
error: null,
isLoading: false,
Expand Down
Loading

1 comment on commit 047f7e4

@vercel
Copy link

@vercel vercel bot commented on 047f7e4 Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.