Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

refactor: uses lowercased addresses to interact with the server #674

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -854,6 +854,19 @@ 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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should receive the networkId that would be used to apply checksum format

if (network.toLowerCase() === 'rootstock') {
return Rsk3.utils.toChecksumAddress(address, MAINNET.NETWORK_VERSION);
}
return address;
},
};

export default common;
8 changes: 4 additions & 4 deletions src/common/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,17 @@ 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)
.descending('createdAt');
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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/common/wallet/walletManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions src/pages/wallet/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class Transaction extends Component {
isRefreshing: false,
from,
to,
chain,
};
}

Expand Down Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only have the chain name here, would be best to get and send networkId for checksum format check

const toChecksum = common.toChecksumAddressIfNeeded(to, chain);

const txStateText = strings(`txState.${transactionState}`);

const refreshControl = (
Expand Down Expand Up @@ -237,14 +241,14 @@ class Transaction extends Component {
<View style={styles.sectionContainer}>
<Loc style={[styles.sectionTitle]} text="page.wallet.transaction.from" />
<TouchableOpacity style={[styles.copyView]} onPress={this.onFromPress}>
<Text style={[styles.copyText]}>{from}</Text>
<Text style={[styles.copyText]}>{fromChecksum}</Text>
<Image style={styles.copyIcon} source={references.images.copyIcon} />
</TouchableOpacity>
</View>
<View style={styles.sectionContainer}>
<Loc style={[styles.sectionTitle]} text="page.wallet.transaction.to" />
<TouchableOpacity style={[styles.copyView]} onPress={this.onToPress}>
<Text style={[styles.copyText]}>{to}</Text>
<Text style={[styles.copyText]}>{toChecksum}</Text>
<Image style={styles.copyIcon} source={references.images.copyIcon} />
</TouchableOpacity>
</View>
Expand Down Expand Up @@ -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,
Expand Down