Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
also fetch reputation of visited hashtags
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Nov 28, 2018
1 parent e71e3ca commit 932a954
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/redux/app-reducers.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
balance: {},
hashtagList: [],
visitedHashtags: {},
fetching: {},
hashtags: {},
current: {},
Expand Down Expand Up @@ -313,6 +314,13 @@
}
}
}
case 'ADD_VISITED_HASHTAG': {
return deepmerge(state, {
visitedHashtags: {
[action.hashtag.hashtagAddress]: action.hashtag
}
})
}
default: {
return state
}
Expand Down
1 change: 1 addition & 0 deletions src/redux/app-selectors.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
},
confirmedTx: (state) => state.confirmedTx,
hashtagList: (state) => state.hashtagList,
visitedHashtags: (state) => state.visitedHashtags,
address: (state) => state.publicKey,
username: (state) => state.username,
language: (state) => state.language,
Expand Down
4 changes: 3 additions & 1 deletion src/redux/sagas/hashtag-saga.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
hashtagMetadataHash: await hashtagContract.methods.hashtagMetadataHash().call(),
hashtagFee: parseInt(await hashtagContract.methods.hashtagFee().call()),
deployBlock: deployBlock || 8149489,
address: hashtagContract._address
address: hashtagContract._address,
hashtagAddress: hashtagContract._address
}
}

Expand Down Expand Up @@ -157,6 +158,7 @@
// - deployBlock() -> deployBlock
const hashtagContractData = yield call(getHashtagContractData, hashtagContract)
yield put({ type: 'UPDATE_NEWHASHTAG', hashtagAddress, data: hashtagContractData });
yield put({ type: 'ADD_VISITED_HASHTAG', hashtag: hashtagContractData })

// Step 2A. Resolve hashtagMetadata with IPFS
// - ipfs.cat(hashtagMetadata) -> description
Expand Down
13 changes: 12 additions & 1 deletion src/redux/sagas/hashtagList-saga.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,18 @@
if (!hashtagList.length) {
hashtagList = yield call(getHashtagList)
}
const reputationsObj = yield call(getReputationFromHashtags, hashtagList, address)

// Append the visited hashtags and remove duplicates
// visitedHashtags is an object
const visitedHashtags = yield select(selectors.visitedHashtags)
const uniqueHashtags = visitedHashtags
hashtagList.forEach(hashtag => {
uniqueHashtags[hashtag.hashtagAddress] = hashtag
})
const uniqueHashtagList = Object.values(uniqueHashtags)

// Get reputation for all hashtags in the list
const reputationsObj = yield call(getReputationFromHashtags, uniqueHashtagList, address)
yield put({ type: 'UPDATE_REPUTATION', address, reputationsObj });
} catch (e) {
console.error(`Error fetching user's reputation`, e)
Expand Down

0 comments on commit 932a954

Please sign in to comment.