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

Improve dapp browser #653

Merged
merged 7 commits into from
Apr 16, 2021
Merged
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
5 changes: 2 additions & 3 deletions src/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,16 +621,15 @@ const common = {
},

/**
* Chcke address is contract addrsss
* Check address is contract addrsss
* @param {*} address need check address
* @param {*} chainId chain id
*/
async isContractAddress(address, chainId) {
return new Promise((resolve, reject) => {
const rskEndpoint = chainId === TESTNET.NETWORK_VERSION ? TESTNET.RSK_END_POINT : MAINNET.RSK_END_POINT;
const rsk3 = new Rsk3(rskEndpoint);
const checksumAddress = Rsk3.utils.toChecksumAddress(address, chainId);
rsk3.getCode(checksumAddress).then((code) => {
rsk3.getCode(address).then((code) => {
if (code !== '0x00') {
resolve(true);
} else {
Expand Down
8 changes: 6 additions & 2 deletions src/components/common/modal/wallet.selection.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ const styles = StyleSheet.create({
fontSize: 16,
fontFamily: fontFamily.AvenirBook,
marginLeft: 11,
width: '100%',
},
tokenText: {
fontFamily: fontFamily.AvenirRoman,
Expand Down Expand Up @@ -243,15 +244,18 @@ class WalletSelection extends PureComponent {
getWalletItem = ({ item }) => {
const { selectedWallet } = this.state;
const { address: selectedAddress } = selectedWallet;
const { address, network } = item;
const { address, network, name } = item;
return (
<TouchableOpacity activeOpacity={1} onPress={() => { this.setState({ selectedWallet: item }); }}>
<View style={styles.selection}>
<View style={styles.row}>
<View style={[network === 'Mainnet' ? styles.mainnet : styles.testnet]}>
{network && <Text style={styles.network}>{strings(`networkType.${_.toLower(network)}`)}</Text>}
</View>
<Text style={styles.address}>{common.ellipsisAddress(address, 6)}</Text>
<View>
<Text style={styles.address}>{name}</Text>
<Text style={styles.address}>{common.ellipsisAddress(address, 6)}</Text>
</View>
</View>
<View style={styles.circle}>
<View style={selectedAddress === address ? styles.isSelected : {}} />
Expand Down
15 changes: 11 additions & 4 deletions src/pages/dapp/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class DAppBrowser extends Component {
window.ethereum.selectedAddress = '${address}';
window.address = '${address}';
window.ethereum.networkVersion = '${this.networkVersion}';
window.ethereum.isRWallet = true;
window.web3 = web3;

// Adapt web3 old version (new web3 version move toDecimal and toBigNumber to utils class).
Expand Down Expand Up @@ -327,15 +328,20 @@ class DAppBrowser extends Component {
}

// ensure window.ethereum.send and window.ethereum.sendAsync are not undefined
setInterval(() => {
setTimeout(() => {
if (!window.ethereum.send) {
window.ethereum.send = sendAsync;
}
if (!window.ethereum.sendAsync) {
window.ethereum.sendAsync = sendAsync;
}
if (!window.ethereum.request) {
window.ethereum.request = sendAsync;
window.ethereum.request = (payload) =>
new Promise((resolve, reject) =>
sendAsync(payload).then(response =>
response.result
? resolve(response.result)
: reject(new Error(response.message || 'provider error'))));
}
}, 1000)
}
Expand Down Expand Up @@ -478,7 +484,8 @@ class DAppBrowser extends Component {
popupMessageModal = async (payload) => {
const dappUrl = this.getDappUrl();
const { id, params } = payload;
const message = this.rsk3.utils.hexToAscii(params[0]);
const message = params[0].startsWith('0x') ? this.rsk3.utils.hexToAscii(params[0]) : params[0];
jessgusclark marked this conversation as resolved.
Show resolved Hide resolved

this.setState({
modalView: (
<MessageModal
Expand Down Expand Up @@ -596,7 +603,7 @@ class DAppBrowser extends Component {
value,
};
const networkId = network === 'Mainnet' ? MAINNET.NETWORK_VERSION : TESTNET.NETWORK_VERSION;
const toAddress = Rsk3.utils.toChecksumAddress(to, networkId);
const toAddress = to.toLowerCase();

const isContractAddress = await common.isContractAddress(toAddress, networkId);

Expand Down
14 changes: 11 additions & 3 deletions src/pages/wallet/wallet.connect/modal/message.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import {
View, Text, ScrollView, StyleSheet,
} from 'react-native';
import PropTypes from 'prop-types';

import { strings } from '../../../../common/i18n';
Expand All @@ -25,9 +27,13 @@ const styles = StyleSheet.create({
color: color.dustyGray,
fontSize: 15,
fontFamily: fontFamily.AvenirBook,
width: '60%',
textAlign: 'right',
},
scroll: {
width: '60%',
padding: 5,
maxHeight: 200,
},
});

export default function MessageModal({
Expand All @@ -41,7 +47,9 @@ export default function MessageModal({
<>
<View style={styles.line}>
<Text style={styles.lineTitle}>{strings('page.wallet.walletconnect.message')}</Text>
<Text style={styles.lineValue}>{message}</Text>
<ScrollView style={styles.scroll}>
<Text style={styles.lineValue}>{message}</Text>
</ScrollView>
</View>
</>
)}
Expand Down