Skip to content

Commit 1371eca

Browse files
committed
refactor: persistence to use store interface from lib
1 parent 5a29294 commit 1371eca

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
@@ -185,10 +185,10 @@ export async function fetchHistory(ncId, count, after) {
185185
export function* requestHistoryNanoContract({ payload }) {
186186
const { address, ncId, after } = payload;
187187
const count = NANO_CONTRACT_TX_HISTORY_SIZE;
188-
189188
const ncEntryKey = formatNanoContractRegistryEntry(address, ncId);
190-
const allNcs = STORE.getItem(nanoContractKey.registeredContracts) || {};
191-
if (!allNcs[ncEntryKey]) {
189+
const storage = STORE.getStorage();
190+
191+
if (!storage.isNanoContractRegistered(ncEntryKey)) {
192192
yield put(nanoContractHistoryFailure(failureMessage.notRegistered));
193193
}
194194

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

199199
// load into store
200-
const allNcs = STORE.getItem(nanoContractKey.registeredContracts) || {};
201-
const currentNc = allNcs[ncEntryKey];
202-
const historyLoaded = currentNc.history || [];
203-
currentNc.history = [...historyLoaded, ...history];
204-
STORE.setItem(nanoContractKey.registeredContracts, allNcs)
200+
const ncData = storage.getNanoContract(ncEntryKey);
201+
const loadedHistory = ncData.history || [];
202+
ncData.history = [...loadedHistory, ...history];
203+
storage.registerNanoContract(ncEntryKey, ncData);
205204

206205
// create an opportunity to load into redux
207206
yield put(nanoContractHistoryLoad({

0 commit comments

Comments
 (0)