From e71e3ca8d31c28ec346c0d39e9906f61b8ccf877 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 28 Nov 2018 17:58:36 +0800 Subject: [PATCH 1/2] convert all addresses to lowercase --- src/redux/sagas/handleReplyItem.html | 3 ++- src/redux/sagas/router-saga.html | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/redux/sagas/handleReplyItem.html b/src/redux/sagas/handleReplyItem.html index da65adee..535e359b 100644 --- a/src/redux/sagas/handleReplyItem.html +++ b/src/redux/sagas/handleReplyItem.html @@ -30,7 +30,8 @@ // Step 1. Store the reply info console.log('Handling ReplyEvent', event) const { itemHash, replyMetadataHash, provider: providerAddress } = event.returnValues - const { address: hashtagAddress } = event + // Protection against calling toLowerCase() on undefined variables + const hashtagAddress = event.address ? event.address.toLowerCase() : event.address const reply = { blockNumber: event.blockNumber, providerAddress, diff --git a/src/redux/sagas/router-saga.html b/src/redux/sagas/router-saga.html index c54d9c82..95872be4 100644 --- a/src/redux/sagas/router-saga.html +++ b/src/redux/sagas/router-saga.html @@ -41,7 +41,7 @@ const path = window.location.pathname // [0 / [1] / [2] / [3] // path = /hashtag/0xCeb...fE/0x2342tds - const [, pageName, hashtag, item] = path.split('/') + let [, pageName, hashtag, item] = path.split('/') const params = parseSearch() @@ -71,6 +71,9 @@ || pageName === 'new-request' ) { if (hashtag && hashtag !== _hashtag) { + // Prevent inconsistencies with address with/without checksum case + // This parameter is entered by the user + hashtag = hashtag.toLowerCase() yield put({ type: 'GET_HASHTAG', hashtag }) yield put({ type: 'CURRENT_HASHTAG', hashtag }) _hashtag = hashtag; From 932a954b7327c603d68c96bc45b931abc9ec080e Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 28 Nov 2018 19:38:47 +0800 Subject: [PATCH 2/2] also fetch reputation of visited hashtags --- src/redux/app-reducers.html | 8 ++++++++ src/redux/app-selectors.html | 1 + src/redux/sagas/hashtag-saga.html | 4 +++- src/redux/sagas/hashtagList-saga.html | 13 ++++++++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/redux/app-reducers.html b/src/redux/app-reducers.html index 7cf58918..8cfad2eb 100644 --- a/src/redux/app-reducers.html +++ b/src/redux/app-reducers.html @@ -40,6 +40,7 @@ }, balance: {}, hashtagList: [], + visitedHashtags: {}, fetching: {}, hashtags: {}, current: {}, @@ -313,6 +314,13 @@ } } } + case 'ADD_VISITED_HASHTAG': { + return deepmerge(state, { + visitedHashtags: { + [action.hashtag.hashtagAddress]: action.hashtag + } + }) + } default: { return state } diff --git a/src/redux/app-selectors.html b/src/redux/app-selectors.html index f2a40896..adf300ae 100644 --- a/src/redux/app-selectors.html +++ b/src/redux/app-selectors.html @@ -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, diff --git a/src/redux/sagas/hashtag-saga.html b/src/redux/sagas/hashtag-saga.html index aa8457bc..a7bce255 100644 --- a/src/redux/sagas/hashtag-saga.html +++ b/src/redux/sagas/hashtag-saga.html @@ -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 } } @@ -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 diff --git a/src/redux/sagas/hashtagList-saga.html b/src/redux/sagas/hashtagList-saga.html index 2d61742b..3596b7f5 100644 --- a/src/redux/sagas/hashtagList-saga.html +++ b/src/redux/sagas/hashtagList-saga.html @@ -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)