Skip to content

Commit

Permalink
bugfix: fix dapp compat issues (#1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpshr authored Aug 27, 2019
1 parent 8f30eb3 commit 0ec910a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
aliases:
- &restore-cache
keys:
- v1.0.4-{{ .Branch }}-{{ checksum "package.json" }}
- v1.0.4-{{ .Branch }}
- v1.0.5-{{ .Branch }}-{{ checksum "package.json" }}
- v1.0.5-{{ .Branch }}

- &save-cache
key: v1.0.4-{{ .Branch }}-{{ checksum "package.json" }}
key: v1.0.5-{{ .Branch }}-{{ checksum "package.json" }}
paths:
- node_modules
- &restore-node-cache
keys:
- v1.0.4-node-{{ .Branch }}-{{ checksum "package.json" }}
- v1.0.4-node-{{ .Branch }}
- v1.0.5-node-{{ .Branch }}-{{ checksum "package.json" }}
- v1.0.5-node-{{ .Branch }}
- &save-node-cache
key: v1.0.4-node-{{ .Branch }}-{{ checksum "package.json" }}
key: v1.0.5-node-{{ .Branch }}-{{ checksum "package.json" }}
paths:
- node_modules

Expand Down
30 changes: 28 additions & 2 deletions app/components/Views/BrowserTab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import Branch from 'react-native-branch';
import WatchAssetRequest from '../../UI/WatchAssetRequest';
import Analytics from '../../../core/Analytics';
import ANALYTICS_EVENT_OPTS from '../../../util/analytics';
import { resemblesAddress } from '../../../util/address';
import { toggleNetworkModal } from '../../../actions/modals';
import setOnboardingWizardStep from '../../../actions/wizard';
import OnboardingWizard from '../../UI/OnboardingWizard';
Expand Down Expand Up @@ -470,10 +471,19 @@ export class BrowserTab extends PureComponent {
personal_sign: async payload => {
const { PersonalMessageManager } = Engine.context;
try {
const firstParam = payload.params[0];
const secondParam = payload.params[1];
const params = {
data: firstParam,
from: secondParam
};
if (resemblesAddress(firstParam) && !resemblesAddress(secondParam)) {
params.data = secondParam;
params.from = firstParam;
}
const pageMeta = await this.getPageMeta();
const rawSig = await PersonalMessageManager.addUnapprovedMessageAsync({
data: payload.params[0],
from: payload.params[1],
...params,
...pageMeta
});
return (
Expand Down Expand Up @@ -512,6 +522,22 @@ export class BrowserTab extends PureComponent {
},
eth_signTypedData_v3: async payload => {
const { TypedMessageManager } = Engine.context;

let data;
try {
data = JSON.parse(payload.params[1]);
} catch (e) {
throw new Error('Data must be passed as a valid JSON string.');
}
const chainId = data.domain.chainId;
const activeChainId =
this.props.networkType === 'rpc' ? this.props.network : Networks[this.props.networkType].networkId;

// eslint-disable-next-line eqeqeq
if (chainId && chainId != activeChainId) {
throw new Error(`Provided chainId (${chainId}) must match the active chainId (${activeChainId})`);
}

try {
const pageMeta = await this.getPageMeta();
const rawSig = await TypedMessageManager.addUnapprovedMessageAsync(
Expand Down
4 changes: 2 additions & 2 deletions app/core/InpageBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ window.ethereum._metamask = new Proxy(
* @returns {Promise<boolean>} - Promise resolving to true if accounts have been previously enabled for this domain
*/
isApproved: async () => {
const { isApproved } = await window.ethereum.send('metamask_isApproved');
return isApproved;
const response = await window.ethereum.send('metamask_isApproved');
return response ? response.isApproved : false;
},

/**
Expand Down
9 changes: 9 additions & 0 deletions app/util/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,12 @@ export function isENS(name) {
}
return true;
}

/**
* Determines if a given string looks like a valid Ethereum address
*
* @param {address} string
*/
export function resemblesAddress(address) {
return address.length === 2 + 20 * 2;
}

0 comments on commit 0ec910a

Please sign in to comment.