-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bugfix: fix dapp compat issues #1021
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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 ( | ||
|
@@ -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})`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as previous comment |
||
} | ||
|
||
try { | ||
const pageMeta = await this.getPageMeta(); | ||
const rawSig = await TypedMessageManager.addUnapprovedMessageAsync( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you throw here it won't get back to the dapp context.
You should do
Promise.reject({ error: error.message, jsonrpc: payload.jsonrpc, id: payload.id });
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing here does get back to the dapp context (the thrown error is caught and shuffled as the RPC response up the chain.) I verified this only in a dapp context using Dan's test page, but I'm happy to explicitly reject if that's preferred.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left this as-is for now to stay in-line with the way we handle invalid data above.