Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ledger Sync - Fix side effect causing the synchronization to stop working #7929

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/brown-ducks-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"ledger-live-desktop": patch
"live-mobile": patch
"@ledgerhq/live-wallet": patch
---

Ledger Sync - Fixed side effect that caused the synchronization to stop working
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import {
WSState,
} from "@ledgerhq/live-wallet/store";
import { replaceAccounts } from "~/renderer/actions/accounts";
import { latestDistantStateSelector } from "~/renderer/reducers/wallet";
import {
latestDistantStateSelector,
latestDistantVersionSelector,
} from "~/renderer/reducers/wallet";
import { useTrustchainSdk } from "./useTrustchainSdk";
import { useOnTrustchainRefreshNeeded } from "./useOnTrustchainRefreshNeeded";
import { Dispatch } from "redux";
Expand Down Expand Up @@ -80,6 +83,7 @@ export function useCloudSyncSDK(): CloudSyncSDK<Schema> {
ctx,
getState,
latestDistantStateSelector,
latestDistantVersionSelector,
localStateSelector,
saveUpdate,
}),
Expand Down
4 changes: 4 additions & 0 deletions apps/ledger-live-desktop/src/renderer/reducers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export function latestDistantStateSelector(state: State): DistantState | null {
return walletSyncStateSelector(walletSelector(state)).data;
}

export function latestDistantVersionSelector(state: State): number {
return walletSyncStateSelector(walletSelector(state)).version;
}

export const useMaybeAccountName = (
account: AccountLike | null | undefined,
): string | undefined => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { walletSelector } from "~/reducers/wallet";
import { State } from "~/reducers/types";
import { bridgeCache } from "~/bridge/cache";
import { replaceAccounts } from "~/actions/accounts";
import { latestDistantStateSelector } from "~/reducers/wallet";
import { latestDistantStateSelector, latestDistantVersionSelector } from "~/reducers/wallet";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
import getWalletSyncEnvironmentParams from "@ledgerhq/live-common/walletSync/getEnvironmentParams";

Expand Down Expand Up @@ -80,6 +80,7 @@ export function useCloudSyncSDK(): CloudSyncSDK<Schema> {
ctx,
getState,
latestDistantStateSelector,
latestDistantVersionSelector,
localStateSelector,
saveUpdate,
}),
Expand Down
4 changes: 4 additions & 0 deletions apps/ledger-live-mobile/src/reducers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export function latestDistantStateSelector(state: State): DistantState | null {
return walletSyncStateSelector(walletSelector(state)).data;
}

export function latestDistantVersionSelector(state: State): number {
return walletSyncStateSelector(walletSelector(state)).version;
}

export const useMaybeAccountName = (
account: AccountLike | null | undefined,
): string | undefined => {
Expand Down
2 changes: 2 additions & 0 deletions apps/web-tools/trustchain/components/AppAccountsSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const localStateSelector = (state: State) => ({
});

const latestDistantStateSelector = (state: State) => state.walletState.walletSyncState.data;
const latestDistantVersionSelector = (state: State) => state.walletState.walletSyncState.version;

export default function AppAccountsSync({
deviceId,
Expand Down Expand Up @@ -141,6 +142,7 @@ export default function AppAccountsSync({
ctx,
getState,
latestDistantStateSelector,
latestDistantVersionSelector,
localStateSelector,
saveUpdate,
}),
Expand Down
6 changes: 6 additions & 0 deletions libs/live-wallet/src/walletsync/incrementalUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ export function makeSaveNewUpdate<S>({
ctx,
getState,
latestDistantStateSelector,
latestDistantVersionSelector,
localStateSelector,
saveUpdate,
}: {
ctx: WalletSyncDataManagerResolutionContext;
getState: () => S;
latestDistantStateSelector: (state: S) => DistantState | null;
latestDistantVersionSelector: (state: S) => number;
localStateSelector: (state: S) => LocalState;
saveUpdate: (
data: DistantState | null,
Expand All @@ -27,6 +29,7 @@ export function makeSaveNewUpdate<S>({
case "new-data": {
// we resolve incoming distant state changes
const state = getState();
const latestVersion = latestDistantVersionSelector(state);
const latest = latestDistantStateSelector(state);
const local = localStateSelector(state);
const data = event.data;
Expand All @@ -41,6 +44,9 @@ export function makeSaveNewUpdate<S>({
} else {
log("walletsync", "resolved. no changes to apply.");
}
if (event.version !== latestVersion) {
await saveUpdate(data, event.version, null);
}
break;
}
case "pushed-data": {
Expand Down
Loading