-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨feat(llm/lld): avoid watchloop when ff is off (#7601)
* ✨feat(llm/lld): avoid watchloop when ff is off * 🧪feat(lld/llm): add unit test and jest config * 🧪feat(lld/llm): useRef instead of useState to avoid loop
- Loading branch information
1 parent
2871edd
commit d75616a
Showing
20 changed files
with
325 additions
and
116 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,6 @@ | ||
--- | ||
"ledger-live-desktop": patch | ||
"live-mobile": patch | ||
--- | ||
|
||
Avoid running watchloop when LS ff is disabled |
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
26 changes: 2 additions & 24 deletions
26
...ve-desktop/src/newArch/features/WalletSync/__tests__/manageSynchronizedInstances.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
10 changes: 1 addition & 9 deletions
10
apps/ledger-live-desktop/src/newArch/features/WalletSync/__tests__/manageYourBackup.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
63 changes: 63 additions & 0 deletions
63
apps/ledger-live-desktop/src/newArch/features/WalletSync/__tests__/shared.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,63 @@ | ||
import React from "react"; | ||
import { TrustchainMember } from "@ledgerhq/trustchain/types"; | ||
import WalletSyncRow from "~/renderer/screens/settings/sections/General/WalletSync"; | ||
import { getSdk } from "@ledgerhq/trustchain/index"; | ||
import { EMPTY } from "rxjs"; | ||
import { Flow, initialStateWalletSync, Step } from "~/renderer/reducers/walletSync"; | ||
import getWalletSyncEnvironmentParams from "@ledgerhq/live-common/walletSync/getEnvironmentParams"; | ||
|
||
export const INSTANCES: Array<TrustchainMember> = [ | ||
{ | ||
id: "currentInstance", | ||
name: "macOS", | ||
permissions: 112, | ||
}, | ||
{ | ||
id: "2", | ||
name: "Ipone 15", | ||
permissions: 112, | ||
}, | ||
]; | ||
|
||
export const lldWalletSyncFeatureFlag = { | ||
lldWalletSync: { | ||
enabled: true, | ||
params: { | ||
environment: "STAGING", | ||
watchConfig: { | ||
pollingInterval: 10000, | ||
initialTimeout: 5000, | ||
userIntentDebounce: 1000, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const mockedSdk = getSdk( | ||
true, | ||
{ | ||
applicationId: 12, | ||
name: "LLD Integration", | ||
apiBaseUrl: getWalletSyncEnvironmentParams("STAGING").trustchainApiBaseUrl, | ||
}, | ||
() => () => EMPTY, | ||
); | ||
|
||
export const walletSyncActivatedState = { | ||
...initialStateWalletSync, | ||
flow: Flow.WalletSyncActivated, | ||
step: Step.WalletSyncActivated, | ||
}; | ||
|
||
export const simpleTrustChain = { | ||
rootId: "rootId", | ||
deviceId: "deviceId", | ||
trustchainId: "trustchainId", | ||
}; | ||
|
||
export const WalletSyncTestApp = () => ( | ||
<> | ||
<div id="modals"></div> | ||
<WalletSyncRow /> | ||
</> | ||
); |
10 changes: 1 addition & 9 deletions
10
apps/ledger-live-desktop/src/newArch/features/WalletSync/__tests__/synchronize.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
57 changes: 57 additions & 0 deletions
57
.../ledger-live-desktop/src/newArch/features/WalletSync/__tests__/useWatchWalletSync.test.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,57 @@ | ||
import { renderHook } from "tests/testUtils"; | ||
import { INITIAL_STATE as INITIAL_STATE_SETTINGS } from "~/renderer/reducers/settings"; | ||
import { useWatchWalletSync } from "../hooks/useWatchWalletSync"; | ||
import { | ||
INSTANCES, | ||
lldWalletSyncFeatureFlag, | ||
mockedSdk, | ||
simpleTrustChain, | ||
walletSyncActivatedState, | ||
} from "./shared"; | ||
|
||
const INITIAL_STATE = { | ||
walletSync: { | ||
...walletSyncActivatedState, | ||
instances: INSTANCES, | ||
}, | ||
trustchain: { | ||
trustchain: simpleTrustChain, | ||
memberCredentials: { | ||
pubkey: "currentInstance", | ||
privatekey: "privatekey", | ||
}, | ||
}, | ||
settings: { | ||
...INITIAL_STATE_SETTINGS, | ||
overriddenFeatureFlags: lldWalletSyncFeatureFlag, | ||
}, | ||
}; | ||
|
||
jest.mock("../hooks/useTrustchainSdk", () => ({ | ||
useTrustchainSdk: () => ({ | ||
getMembers: (mockedSdk.getMembers = jest.fn()), | ||
removeMember: (mockedSdk.removeMember = jest.fn()), | ||
}), | ||
})); | ||
|
||
describe("useWatchWalletSync", () => { | ||
it("should not run ledger sync watch loop when ff is disabled", async () => { | ||
const { result, store } = renderHook(() => useWatchWalletSync(), {}); | ||
|
||
expect(store.getState().settings.overriddenFeatureFlags.lldWalletSync).not.toBeDefined(); | ||
expect(result.current.visualPending).toBe(false); | ||
expect(result.current.walletSyncError).toBe(null); | ||
expect(result.current.onUserRefresh).toBeInstanceOf(Function); | ||
expect(result.current.onUserRefresh).not.toThrow(); | ||
}); | ||
|
||
it("should run ledger sync watch loop when ff is enabled", async () => { | ||
const { result, store } = renderHook(() => useWatchWalletSync(), { | ||
initialState: INITIAL_STATE, | ||
}); | ||
|
||
expect(store.getState().settings.overriddenFeatureFlags.lldWalletSync.enabled).toBe(true); | ||
expect(result.current.visualPending).toBe(true); | ||
expect(result.current.walletSyncError).toBe(null); | ||
}); | ||
}); |
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
26 changes: 0 additions & 26 deletions
26
apps/ledger-live-desktop/src/newArch/features/WalletSync/testHelper/helper.ts
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
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,19 @@ | ||
import { DEFAULT_FEATURES } from "@ledgerhq/live-common/featureFlags/index"; | ||
|
||
import { FeatureId, Feature, Features } from "@ledgerhq/types-live"; | ||
|
||
/* getFeature provides a basic behavior to mock how we retrieve feature flags values | ||
* and allows overrides for our tests | ||
*/ | ||
export const getFeature = <T extends FeatureId>({ | ||
key, | ||
localOverrides, | ||
}: { | ||
key: T; | ||
appLanguage?: string; | ||
allowOverride?: boolean; | ||
localOverrides?: { [key in FeatureId]?: Feature | undefined }; | ||
}): Features[T] => { | ||
if (localOverrides?.[key]) return localOverrides?.[key] as Features[T]; | ||
return DEFAULT_FEATURES[key]; | ||
}; |
Oops, something went wrong.