Skip to content

Commit 8d2950f

Browse files
committed
refactor: persistence to use store interface from lib
1 parent 55dbf3b commit 8d2950f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/sagas/nanoContract.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ export async function fetchHistory(ncId, count, after) {
213213
export function* requestHistoryNanoContract({ payload }) {
214214
const { address, ncId, after } = payload;
215215
const count = NANO_CONTRACT_TX_HISTORY_SIZE;
216-
217216
const ncEntryKey = formatNanoContractRegistryEntry(address, ncId);
218-
const allNcs = STORE.getItem(nanoContractKey.registeredContracts) || {};
219-
if (!allNcs[ncEntryKey]) {
217+
const storage = STORE.getStorage();
218+
219+
if (!storage.isNanoContractRegistered(ncEntryKey)) {
220220
yield put(nanoContractHistoryFailure(failureMessage.notRegistered));
221221
}
222222

@@ -225,11 +225,10 @@ export function* requestHistoryNanoContract({ payload }) {
225225
const { history, next } = yield call(fetchHistory, ncId, count, after);
226226

227227
// load into store
228-
const allNcs = STORE.getItem(nanoContractKey.registeredContracts) || {};
229-
const currentNc = allNcs[ncEntryKey];
230-
const historyLoaded = currentNc.history || [];
231-
currentNc.history = [...historyLoaded, ...history];
232-
STORE.setItem(nanoContractKey.registeredContracts, allNcs)
228+
const ncData = storage.getNanoContract(ncEntryKey);
229+
const loadedHistory = ncData.history || [];
230+
ncData.history = [...loadedHistory, ...history];
231+
storage.registerNanoContract(ncEntryKey, ncData);
233232

234233
// create an opportunity to load into redux
235234
yield put(nanoContractHistoryLoad({

0 commit comments

Comments
 (0)