-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT]: Add LedgerSync status banner + hook (#7538)
- Loading branch information
1 parent
7f588f3
commit 4dad5d0
Showing
6 changed files
with
144 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"live-mobile": patch | ||
--- | ||
|
||
Add LedgerSync status banner + hook |
56 changes: 56 additions & 0 deletions
56
...le/src/newArch/features/WalletSync/__integrations__/walletSyncStatus.integration.test.tsx
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,56 @@ | ||
import React from "react"; | ||
import { screen } from "@testing-library/react-native"; | ||
import { render } from "@tests/test-renderer"; | ||
import { WalletSyncSettingsNavigator } from "./shared"; | ||
import { State } from "~/reducers/types"; | ||
|
||
jest.mock("../hooks/useLedgerSyncStatus", () => ({ | ||
useLedgerSyncStatus: () => ({ | ||
error: new Error(), | ||
isError: true, | ||
}), | ||
})); | ||
|
||
describe("WalletSyncStatus", () => { | ||
it("Should display warning banner when LedgerSync is down", async () => { | ||
const { user } = render(<WalletSyncSettingsNavigator />, { | ||
overrideInitialState: (state: State) => ({ | ||
...state, | ||
settings: { | ||
...state.settings, | ||
readOnlyModeEnabled: false, | ||
overriddenFeatureFlags: { | ||
llmWalletSync: { | ||
enabled: true, | ||
params: { | ||
environment: "STAGING", | ||
watchConfig: { | ||
pollingInterval: 10000, | ||
initialTimeout: 5000, | ||
userIntentDebounce: 1000, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
trustchain: { | ||
...state.trustchain, | ||
trustchain: { | ||
rootId: "rootId", | ||
applicationPath: "applicationPath", | ||
walletSyncEncryptionKey: "walletSyncEncryptionKey", | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
// Check if the ledger sync row is visible | ||
await expect(await screen.findByText(/ledger sync/i)).toBeVisible(); | ||
|
||
// On Press the ledger sync row | ||
await user.press(await screen.findByText(/ledger sync/i)); | ||
|
||
// Check if the activation screen is visible | ||
expect(await screen.findByText(/Ledger Sync is currently unavailable./i)).toBeVisible(); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
apps/ledger-live-mobile/src/newArch/features/WalletSync/components/AlertLedgerSyncDown.tsx
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,13 @@ | ||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { Alert } from "@ledgerhq/native-ui"; | ||
|
||
export function AlertLedgerSyncDown() { | ||
const { t } = useTranslation(); | ||
return ( | ||
<Alert | ||
type="warning" | ||
title={t("walletSync.walletSyncActivated.errors.ledgerSyncUnavailable")} | ||
/> | ||
); | ||
} |
2 changes: 2 additions & 0 deletions
2
apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/type.hooks.ts
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
38 changes: 38 additions & 0 deletions
38
apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useLedgerSyncStatus.ts
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,38 @@ | ||
import { useQueries, UseQueryResult } from "@tanstack/react-query"; | ||
import { QueryKey } from "./type.hooks"; | ||
import getTrustchainApi, { StatusAPIResponse as TrustchainStatus } from "@ledgerhq/trustchain/api"; | ||
import getCloudSyncApi, { | ||
StatusAPIResponse as CloudSyncStatus, | ||
} from "@ledgerhq/live-wallet/cloudsync/api"; | ||
import { useFeature } from "@ledgerhq/live-common/featureFlags/index"; | ||
import getWalletSyncEnvironmentParams from "@ledgerhq/live-common/walletSync/getEnvironmentParams"; | ||
|
||
export function useLedgerSyncStatus() { | ||
const featureWalletSync = useFeature("llmWalletSync"); | ||
const { trustchainApiBaseUrl, cloudSyncApiBaseUrl } = getWalletSyncEnvironmentParams( | ||
featureWalletSync?.params?.environment, | ||
); | ||
const QUERIES = [ | ||
{ | ||
queryKey: [QueryKey.fetchTrustchainStatus], | ||
queryFn: () => getTrustchainApi(trustchainApiBaseUrl).fetchStatus(), | ||
}, | ||
{ | ||
queryKey: [QueryKey.fetchCloudSyncStatus], | ||
queryFn: () => getCloudSyncApi(cloudSyncApiBaseUrl).fetchStatus(), | ||
}, | ||
]; | ||
|
||
return useQueries({ | ||
queries: QUERIES, | ||
combine: combineData, | ||
}); | ||
} | ||
|
||
function combineData(results: UseQueryResult<TrustchainStatus | CloudSyncStatus, Error>[]) { | ||
return { | ||
error: results.find(result => result.isError)?.error || null, | ||
isLoading: results.some(result => result.isLoading), | ||
isError: results.some(result => result.isError), | ||
}; | ||
} |
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