Skip to content

Commit

Permalink
fix: ledger sync side effect causing the synchronization to stop working
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrellard-ledger committed Sep 26, 2024
1 parent 0bf7412 commit 8a72596
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
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 @@ -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
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

0 comments on commit 8a72596

Please sign in to comment.