From 75e778a11bff2581a666b58ee3be2f0be8d441ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Fari=C3=B1a?= Date: Fri, 7 May 2021 17:41:21 -0300 Subject: [PATCH 1/4] refactor: uses lowercased addresses to interact with the server - and process them as lowercased as well --- src/common/parse.js | 8 ++++---- src/common/wallet/walletManager.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/parse.js b/src/common/parse.js index 01998f6dc..4a4393839 100644 --- a/src/common/parse.js +++ b/src/common/parse.js @@ -251,9 +251,9 @@ class ParseHelper { */ static async fetchTransactions(symbol, type, address, skipCount, fetchCount) { const queryFrom = new Parse.Query(ParseTransaction); - queryFrom.equalTo('from', address); + queryFrom.equalTo('from', address.toLowerCase()); const queryTo = new Parse.Query(ParseTransaction); - queryTo.equalTo('to', address); + queryTo.equalTo('to', address.toLowerCase()); const query = Parse.Query.or(queryFrom, queryTo) .equalTo('type', type) .equalTo('symbol', symbol) @@ -261,7 +261,7 @@ class ParseHelper { const results = await query.skip(skipCount).limit(fetchCount).find(); const transactions = _.map(results, (item) => { const transaction = parseDataUtil.getTransaction(item); - const isSender = address === transaction.from; + const isSender = address.toLowerCase() === transaction.from.toLowerCase(); return parseDataUtil.getTransactionViewData(transaction, isSender); }); return transactions; @@ -272,7 +272,7 @@ class ParseHelper { * @param {*} tokens */ static async subscribeTransactions(tokens) { - const addresses = _.uniq(_.map(tokens, 'address')); + const addresses = (_.uniq(_.map(tokens, 'address'))).map((address) => address.toLowerCase()); const queryFrom = new Parse.Query(ParseTransaction); queryFrom.containedIn('from', addresses); const queryTo = new Parse.Query(ParseTransaction); diff --git a/src/common/wallet/walletManager.js b/src/common/wallet/walletManager.js index f06967d93..171495458 100644 --- a/src/common/wallet/walletManager.js +++ b/src/common/wallet/walletManager.js @@ -165,7 +165,7 @@ class WalletManager { _.each(tokenInstances, (token) => { const newToken = token; - const matchedToken = _.find(updatedItems, (item) => item.address === token.address && item.symbol === token.symbol && item.type === token.type); + const matchedToken = _.find(updatedItems, (item) => item.address.toLowerCase() === token.address.toLowerCase() && item.symbol === token.symbol && item.type === token.type); if (matchedToken) { // update balance From a1b69bc912cf09e676dbae06b1d66229f7b1d633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Fari=C3=B1a?= Date: Tue, 11 May 2021 17:58:06 -0300 Subject: [PATCH 2/4] refactor: fixes !== operator --- src/common/common.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/common/common.js b/src/common/common.js index 30b3bc403..7daae9a1d 100644 --- a/src/common/common.js +++ b/src/common/common.js @@ -630,7 +630,7 @@ const common = { const rskEndpoint = chainId === TESTNET.NETWORK_VERSION ? TESTNET.RSK_END_POINT : MAINNET.RSK_END_POINT; const rsk3 = new Rsk3(rskEndpoint); rsk3.getCode(address).then((code) => { - if (code !== '0x00' || code !== '0x0' || code != '0x') { + if (code !== '0x00' || code !== '0x0' || code !== '0x') { resolve(true); } else { resolve(false); @@ -710,7 +710,7 @@ const common = { const { inputs, names, types, method, } = inputData; - const params = { }; + const params = {}; _.forEach(inputs, (inputValue, index) => { const key = this.uppercaseFirstLetter(names[index]); const type = types[index]; @@ -854,6 +854,7 @@ const common = { } return false; }, + }; export default common; From d3297482eb086938b0ba03ef3bdf34ab5e7b82d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Fari=C3=B1a?= Date: Tue, 11 May 2021 17:58:31 -0300 Subject: [PATCH 3/4] feat: adds utility function to checksum only rootstock addresses --- src/common/common.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/common/common.js b/src/common/common.js index 7daae9a1d..dcf6f4010 100644 --- a/src/common/common.js +++ b/src/common/common.js @@ -855,6 +855,18 @@ const common = { return false; }, + /** + * Returns the address ready to show to the user. Applies checksum if needed by the nerworkId. + * Only considers Rootstock network + * @param {string} address + * @param {string} network + */ + toChecksumAddressIfNeeded(address, network) { + if (network.toLowerCase() === 'rootstock') { + return Rsk3.utils.toChecksumAddress(address, MAINNET.NETWORK_VERSION); + } + return address; + }, }; export default common; From 08fe4be21b2e123c313d98868e9da1ca7900ec5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Fari=C3=B1a?= Date: Tue, 11 May 2021 18:19:57 -0300 Subject: [PATCH 4/4] fix: checksums addresses on transaction view --- src/pages/wallet/transaction.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pages/wallet/transaction.js b/src/pages/wallet/transaction.js index ab58e8585..7794a0f83 100644 --- a/src/pages/wallet/transaction.js +++ b/src/pages/wallet/transaction.js @@ -130,6 +130,7 @@ class Transaction extends Component { isRefreshing: false, from, to, + chain, }; } @@ -199,9 +200,12 @@ class Transaction extends Component { render() { const { navigation } = this.props; const { - transactionState, transactionId, amount, dateTime, memo, confirmations, title, stateIcon, isRefreshing, from, to, + transactionState, transactionId, amount, dateTime, memo, confirmations, title, stateIcon, isRefreshing, from, to, chain, } = this.state; + const fromChecksum = common.toChecksumAddressIfNeeded(from, chain); + const toChecksum = common.toChecksumAddressIfNeeded(to, chain); + const txStateText = strings(`txState.${transactionState}`); const refreshControl = ( @@ -237,14 +241,14 @@ class Transaction extends Component { - {from} + {fromChecksum} - {to} + {toChecksum} @@ -279,6 +283,7 @@ Transaction.propTypes = { navigate: PropTypes.func.isRequired, dispatch: PropTypes.func.isRequired, goBack: PropTypes.func.isRequired, + // eslint-disable-next-line react/forbid-prop-types state: PropTypes.object.isRequired, }).isRequired, addNotification: PropTypes.func.isRequired,