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

Transaction history fix #398

Merged
merged 2 commits into from
Aug 31, 2022
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"decimal.js": "^10.2.1",
"formik": "^2.2.9",
"google-protobuf": "^3.15.8",
"ldk": "^0.5.4",
"ldk": "^0.5.8",
"lodash.debounce": "^4.0.8",
"lottie-web": "^5.7.8",
"marina-provider": "^1.7.2",
Expand Down
2 changes: 1 addition & 1 deletion src/application/redux/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const marinaReducer = combineReducers({
reducer: walletReducer,
key: 'wallet',
blacklist: ['deepRestorer', 'updaterLoaders'],
version: 4,
version: 5,
migrate: walletMigrate,
}),
taxi: persist<TaxiState>({
Expand Down
24 changes: 23 additions & 1 deletion src/domain/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import type { MasterBlindingKey } from './master-blinding-key';
import type { MasterXPub } from './master-extended-pub';
import type { WalletState } from './wallet';

// v5 only erases the current transactions state for all accounts during migration
export type WalletPersistedStateV5 = WalletState & Partial<PersistedState>;

// v4 is a fixed version of v3 about covenantTemplate field in CustomAccountData
export type WalletPersistedStateV4 = WalletState & Partial<PersistedState>;
export type WalletPersistedStateV4 = WalletPersistedStateV5;

export type WalletPersistedStateV3 = WalletPersistedStateV4;
type keysAddedInV3 = 'encryptedMnemonic' | 'accounts';
Expand All @@ -30,6 +33,10 @@ type deletedInV2 = {
export type WalletPersistedStateV1 = Omit<WalletPersistedStateV2, keysAddedInV2> & deletedInV2;

export const walletMigrations = {
5: (state: WalletPersistedStateV4): WalletPersistedStateV5 => ({
...state,
unspentsAndTransactions: removeTransactions(state.unspentsAndTransactions),
}),
4: (state: WalletPersistedStateV3) => ({
...state,
accounts: accountsFieldRenameV4(state.accounts),
Expand Down Expand Up @@ -78,5 +85,20 @@ function accountsFieldRenameV4(
}
return renamed;
}

function removeTransactions(
utxosAndTxs: WalletPersistedStateV4['unspentsAndTransactions']
): WalletPersistedStateV5['unspentsAndTransactions'] {
const result: WalletPersistedStateV5['unspentsAndTransactions'] = {};
for (const [accountID, utxosTxsByNetwork] of Object.entries(utxosAndTxs)) {
result[accountID] = {
liquid: { ...utxosTxsByNetwork.liquid, transactions: {} },
testnet: { ...utxosTxsByNetwork.testnet, transactions: {} },
regtest: { ...utxosTxsByNetwork.regtest, transactions: {} },
};
}
return result;
}

// `as any` is needed (redux-persist doesn't support generic types in createMigrate func)
export const walletMigrate = createMigrate(walletMigrations as any);
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6553,10 +6553,10 @@ ldk@^0.5.2:
slip77 "^0.2.0"
tslib "^2.3.1"

ldk@^0.5.4:
version "0.5.4"
resolved "https://registry.yarnpkg.com/ldk/-/ldk-0.5.4.tgz#20240f318a5f047d2023adec02f1eae466278042"
integrity sha512-55f6Xd79L0WyRoMdhF1Ebk3efO9Nslcr0Z68ViAZvGF4j3Yo54yQQESgWa7PMHw5RSRxe0pKHQbF3nPmpmGURA==
ldk@^0.5.8:
version "0.5.8"
resolved "https://registry.yarnpkg.com/ldk/-/ldk-0.5.8.tgz#c9ee3af9397843cb166689789e39d4e9c0d25f67"
integrity sha512-IMsMKRxFNFhgM1SaqaCI84ABVTV9nd3AzXMP1zeX5ByD/R5lnWhzy9xrz8xxPsf1kSCEBs/N0uA1twSXQznuVw==
dependencies:
axios "^0.21.1"
bip32 "^3.0.1"
Expand Down