Skip to content

Commit 0f96482

Browse files
committed
fix(backup): add boosts & transfers to backup
1 parent 0fbc9c3 commit 0f96482

File tree

16 files changed

+389
-171
lines changed

16 files changed

+389
-171
lines changed

__tests__/helpers.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
reduceValue,
44
timeAgo,
55
isObjPartialMatch,
6+
deepCompareStructure,
67
ellipsis,
78
generateCalendar,
89
getDurationForBlocks,
@@ -160,6 +161,77 @@ describe('isObjPartialMatch', () => {
160161
});
161162
});
162163

164+
describe('deepCompareStructure', () => {
165+
it('can perform match', () => {
166+
const f = deepCompareStructure;
167+
expect(f({}, {})).toEqual(true);
168+
expect(f({}, [])).toEqual(false);
169+
expect(f({ a: 1 }, {})).toEqual(false);
170+
expect(f({ a: 1 }, { a: 2 })).toEqual(true);
171+
expect(f({ a: 1 }, { b: 1 })).toEqual(false);
172+
expect(f({ a: { b: 1 } }, { a: { b: 2 } })).toEqual(true);
173+
expect(f({ a: { b: 1 } }, { a: { c: 1 } })).toEqual(false);
174+
expect(f({ a: 1 }, { a: [] })).toEqual(false);
175+
expect(f({ a: { b: [] } }, { a: { b: [] } })).toEqual(true);
176+
expect(f({ a: { b: 1 } }, { a: { b: [] } })).toEqual(false);
177+
178+
const received = {
179+
boostedTransactions: {
180+
bitcoin: {},
181+
bitcoinTestnet: {},
182+
bitcoinRegtest: {
183+
fff9398e30329ab0d4ae227c017b9c11537d6fadede4df402d3ae9bb854816f5: {
184+
parentTransactions: [
185+
'fff9398e30329ab0d4ae227c017b9c11537d6fadede4df402d3ae9bb854816f5',
186+
],
187+
childTransaction:
188+
'ee459c02101cad9dbab8d0fc2fe55026130e7db4d88ca8892b9003167c787fa1',
189+
type: 'cpfp',
190+
fee: 664,
191+
},
192+
'415098a69d7b1c93b31b14625c4b7663a4bdeee5f15c5982083ac1c4ec14717b': {
193+
parentTransactions: [
194+
'415098a69d7b1c93b31b14625c4b7663a4bdeee5f15c5982083ac1c4ec14717b',
195+
],
196+
childTransaction:
197+
'f7f0d6184818a9588633be608dc4d8f3510708c5946bea330c663a0bf8c334a2',
198+
type: 'cpfp',
199+
fee: 664,
200+
},
201+
},
202+
},
203+
transfers: {
204+
bitcoin: [],
205+
bitcoinTestnet: [],
206+
bitcoinRegtest: [
207+
{
208+
txId: '67a7108cd434d8580a0295517df0c740b59e84e875284ac139717e4dda4da0f8',
209+
type: 'open',
210+
status: 'pending',
211+
orderId: '5f95e1f5-26f9-4fb2-82e6-9ae602764d3b',
212+
amount: 17602,
213+
},
214+
],
215+
},
216+
};
217+
218+
const expected = {
219+
boostedTransactions: {
220+
bitcoin: {},
221+
bitcoinTestnet: {},
222+
bitcoinRegtest: {},
223+
},
224+
transfers: {
225+
bitcoin: [],
226+
bitcoinTestnet: [],
227+
bitcoinRegtest: [],
228+
},
229+
};
230+
231+
expect(f(received, expected, 1)).toEqual(true);
232+
});
233+
});
234+
163235
describe('calendar', () => {
164236
it('can generate calendar', () => {
165237
const date = new Date(Date.UTC(2020, 11, 31, 23, 59, 59));

src/screens/Settings/AppStatus/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
isOnlineSelector,
1818
} from '../../../store/reselect/ui';
1919
import { TBackupItem } from '../../../store/types/backup';
20-
import { EBackupCategories } from '../../../store/utils/backup';
20+
import { EBackupCategory } from '../../../store/utils/backup';
2121
import { IColors } from '../../../styles/colors';
2222
import { ScrollView, View as ThemedView } from '../../../styles/components';
2323
import {
@@ -147,7 +147,7 @@ const AppStatus = ({}: SettingsScreenProps<'AppStatus'>): ReactElement => {
147147
);
148148
};
149149

150-
return Object.values(EBackupCategories).every((key) => {
150+
return Object.values(EBackupCategory).every((key) => {
151151
return isSyncOk(backup[key]);
152152
});
153153
}, [backup, now]);
@@ -157,7 +157,7 @@ const AppStatus = ({}: SettingsScreenProps<'AppStatus'>): ReactElement => {
157157
if (!isBackupSyncOk) {
158158
return { state: 'error' };
159159
}
160-
const syncTimes = Object.values(EBackupCategories).map((key) => {
160+
const syncTimes = Object.values(EBackupCategory).map((key) => {
161161
return backup[key].synced;
162162
});
163163
const max = Math.max(...syncTimes);

src/screens/Settings/Backup/Metadata.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useAppDispatch, useAppSelector } from '../../../hooks/redux';
1111
import { closeSheet } from '../../../store/slices/ui';
1212
import { backupSelector } from '../../../store/reselect/backup';
1313
import { i18nTime } from '../../../utils/i18n';
14-
import { EBackupCategories } from '../../../store/utils/backup';
14+
import { EBackupCategory } from '../../../store/utils/backup';
1515

1616
const imageSrc = require('../../../assets/illustrations/card.png');
1717

@@ -22,7 +22,7 @@ const Metadata = (): ReactElement => {
2222
const backup = useAppSelector(backupSelector);
2323

2424
const max = Math.max(
25-
...Object.values(EBackupCategories).map((key) => {
25+
...Object.values(EBackupCategory).map((key) => {
2626
return backup[key].synced;
2727
}),
2828
);

src/screens/Settings/BackupSettings/index.tsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { backupSelector } from '../../../store/reselect/backup';
1212
import { lightningBackupSelector } from '../../../store/reselect/lightning';
1313
import { forceBackup } from '../../../store/slices/backup';
1414
import { TBackupItem } from '../../../store/types/backup';
15-
import { EBackupCategories } from '../../../store/utils/backup';
15+
import { EBackupCategory } from '../../../store/utils/backup';
1616
import { toggleBottomSheet } from '../../../store/utils/ui';
1717
import {
1818
ArrowClockwise,
@@ -21,6 +21,7 @@ import {
2121
RectanglesTwo,
2222
SettingsIcon,
2323
TagIcon,
24+
TimerIconAlt,
2425
TransferIcon,
2526
UsersIcon,
2627
} from '../../../styles/icons';
@@ -38,7 +39,7 @@ const Status = ({
3839
Icon: React.FunctionComponent<any>;
3940
title: ReactNode;
4041
status: TBackupItem;
41-
category?: EBackupCategories;
42+
category?: EBackupCategory;
4243
disableRetry?: boolean;
4344
}): ReactElement => {
4445
const { t } = useTranslation('settings');
@@ -124,7 +125,7 @@ const Status = ({
124125
type TBackupCategory = {
125126
Icon: React.FunctionComponent<any>;
126127
title: string;
127-
category?: EBackupCategories;
128+
category?: EBackupCategory;
128129
status: TBackupItem;
129130
disableRetry?: boolean;
130131
};
@@ -154,32 +155,38 @@ const BackupSettings = ({
154155
{
155156
Icon: NoteIcon,
156157
title: t('backup.category_connection_receipts'),
157-
category: EBackupCategories.blocktank,
158-
status: backup[EBackupCategories.blocktank],
158+
category: EBackupCategory.blocktank,
159+
status: backup[EBackupCategory.blocktank],
159160
},
160161
{
161162
Icon: TransferIcon,
162163
title: t('backup.category_transaction_log'),
163-
category: EBackupCategories.ldkActivity,
164-
status: backup[EBackupCategories.ldkActivity],
164+
category: EBackupCategory.ldkActivity,
165+
status: backup[EBackupCategory.ldkActivity],
166+
},
167+
{
168+
Icon: TimerIconAlt,
169+
title: t('backup.category_wallet'),
170+
category: EBackupCategory.wallet,
171+
status: backup[EBackupCategory.wallet],
165172
},
166173
{
167174
Icon: SettingsIcon,
168175
title: t('backup.category_settings'),
169-
category: EBackupCategories.settings,
170-
status: backup[EBackupCategories.settings],
176+
category: EBackupCategory.settings,
177+
status: backup[EBackupCategory.settings],
171178
},
172179
{
173180
Icon: RectanglesTwo,
174181
title: t('backup.category_widgets'),
175-
category: EBackupCategories.widgets,
176-
status: backup[EBackupCategories.widgets],
182+
category: EBackupCategory.widgets,
183+
status: backup[EBackupCategory.widgets],
177184
},
178185
{
179186
Icon: TagIcon,
180187
title: t('backup.category_tags'),
181-
category: EBackupCategories.metadata,
182-
status: backup[EBackupCategories.metadata],
188+
category: EBackupCategory.metadata,
189+
status: backup[EBackupCategory.metadata],
183190
},
184191
// {
185192
// Icon: UserRectangleIcon,
@@ -190,8 +197,8 @@ const BackupSettings = ({
190197
{
191198
Icon: UsersIcon,
192199
title: t('backup.category_contacts'),
193-
category: EBackupCategories.slashtags,
194-
status: backup[EBackupCategories.slashtags],
200+
category: EBackupCategory.slashtags,
201+
status: backup[EBackupCategory.slashtags],
195202
},
196203
];
197204

src/store/shapes/backup.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TBackupItem, TBackupState } from '../types/backup';
2-
import { EBackupCategories } from '../utils/backup';
2+
import { EBackupCategory } from '../utils/backup';
33

44
const item: TBackupItem = {
55
required: Date.now() - 1000,
@@ -8,10 +8,11 @@ const item: TBackupItem = {
88
};
99

1010
export const initialBackupState: TBackupState = {
11-
[EBackupCategories.widgets]: { ...item },
12-
[EBackupCategories.settings]: { ...item },
13-
[EBackupCategories.metadata]: { ...item },
14-
[EBackupCategories.blocktank]: { ...item },
15-
[EBackupCategories.slashtags]: { ...item },
16-
[EBackupCategories.ldkActivity]: { ...item },
11+
[EBackupCategory.wallet]: { ...item },
12+
[EBackupCategory.widgets]: { ...item },
13+
[EBackupCategory.settings]: { ...item },
14+
[EBackupCategory.metadata]: { ...item },
15+
[EBackupCategory.blocktank]: { ...item },
16+
[EBackupCategory.slashtags]: { ...item },
17+
[EBackupCategory.ldkActivity]: { ...item },
1718
};

src/store/slices/backup.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PayloadAction, createSlice } from '@reduxjs/toolkit';
22

33
import { initialBackupState } from '../shapes/backup';
4-
import { EBackupCategories } from '../utils/backup';
4+
import { EBackupCategory } from '../utils/backup';
55
import { addPaidBlocktankOrder, updateBlocktankOrder } from './blocktank';
66
import {
77
addLastUsedTag,
@@ -17,6 +17,7 @@ import {
1717
} from './metadata';
1818
import { updateSettings } from './settings';
1919
import { addContact, addContacts, deleteContact } from './slashtags';
20+
import { addTransfer, removeTransfer, updateTransfer } from './wallet';
2021
import { setFeedWidget, deleteWidget } from './widgets';
2122
import { updateActivityItems } from './activity';
2223
import { EActivityType } from '../types/activity';
@@ -26,40 +27,58 @@ export const backupSlice = createSlice({
2627
initialState: initialBackupState,
2728
reducers: {
2829
resetBackupState: () => initialBackupState,
29-
backupStart: (state, action: PayloadAction<{ category: string }>) => {
30+
requireBackup: (state, action: PayloadAction<EBackupCategory>) => {
31+
state[action.payload].required = Date.now();
32+
},
33+
backupStart: (
34+
state,
35+
action: PayloadAction<{ category: EBackupCategory }>,
36+
) => {
3037
const { category } = action.payload;
3138
state[category].running = true;
3239
},
33-
backupSuccess: (state, action: PayloadAction<{ category: string }>) => {
40+
backupSuccess: (
41+
state,
42+
action: PayloadAction<{ category: EBackupCategory }>,
43+
) => {
3444
const { category } = action.payload;
3545
state[category].running = false;
3646
state[category].synced = Date.now();
3747
},
38-
backupError: (state, action: PayloadAction<{ category: string }>) => {
48+
backupError: (
49+
state,
50+
action: PayloadAction<{ category: EBackupCategory }>,
51+
) => {
3952
const { category } = action.payload;
4053
state[category].running = false;
4154
},
42-
forceBackup: (state, action: PayloadAction<{ category: string }>) => {
55+
forceBackup: (
56+
state,
57+
action: PayloadAction<{ category: EBackupCategory }>,
58+
) => {
4359
const { category } = action.payload;
4460
state[category].required = Date.now();
4561
state[category].running = true;
4662
},
4763
},
4864
extraReducers: (builder) => {
4965
const blocktankReducer = (state): void => {
50-
state[EBackupCategories.blocktank].required = Date.now();
66+
state[EBackupCategory.blocktank].required = Date.now();
5167
};
5268
const metadataReducer = (state): void => {
53-
state[EBackupCategories.metadata].required = Date.now();
69+
state[EBackupCategory.metadata].required = Date.now();
5470
};
5571
const settingsReducer = (state): void => {
56-
state[EBackupCategories.settings].required = Date.now();
72+
state[EBackupCategory.settings].required = Date.now();
5773
};
5874
const slashtagsReducer = (state): void => {
59-
state[EBackupCategories.slashtags].required = Date.now();
75+
state[EBackupCategory.slashtags].required = Date.now();
76+
};
77+
const walletReducer = (state): void => {
78+
state[EBackupCategory.wallet].required = Date.now();
6079
};
6180
const widgetsReducer = (state): void => {
62-
state[EBackupCategories.widgets].required = Date.now();
81+
state[EBackupCategory.widgets].required = Date.now();
6382
};
6483

6584
builder
@@ -79,6 +98,9 @@ export const backupSlice = createSlice({
7998
.addCase(addContact, slashtagsReducer)
8099
.addCase(addContacts, slashtagsReducer)
81100
.addCase(deleteContact, slashtagsReducer)
101+
.addCase(addTransfer, walletReducer)
102+
.addCase(updateTransfer, walletReducer)
103+
.addCase(removeTransfer, walletReducer)
82104
.addCase(setFeedWidget, widgetsReducer)
83105
.addCase(deleteWidget, widgetsReducer)
84106
.addCase(updateActivityItems, (state, action) => {
@@ -87,7 +109,7 @@ export const backupSlice = createSlice({
87109
(item) => item.activityType === EActivityType.lightning,
88110
);
89111
if (hasLnActivity) {
90-
state[EBackupCategories.ldkActivity].required = Date.now();
112+
state[EBackupCategory.ldkActivity].required = Date.now();
91113
}
92114
});
93115
},
@@ -97,6 +119,7 @@ const { actions, reducer } = backupSlice;
97119

98120
export const {
99121
resetBackupState,
122+
requireBackup,
100123
backupStart,
101124
backupSuccess,
102125
backupError,

0 commit comments

Comments
 (0)