-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: message eth sign + Address Book Migration (#1151)
* wip number methods * snaps * sign messasge * 13.1 * bump gaba * snaps * to string * fix android issue * fix address book * add gaba again * add gaba again * fix network * add eth_sign to wallet connect * lock * debig false
- Loading branch information
1 parent
b7c7299
commit 7f428f1
Showing
16 changed files
with
747 additions
and
491 deletions.
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
72 changes: 72 additions & 0 deletions
72
app/components/UI/MessageSign/__snapshots__/index.test.js.snap
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`MessageSign should render correctly 1`] = ` | ||
<View | ||
style={ | ||
Object { | ||
"backgroundColor": "#FFFFFF", | ||
"borderTopLeftRadius": 10, | ||
"borderTopRightRadius": 10, | ||
"minHeight": "90%", | ||
"paddingBottom": 20, | ||
} | ||
} | ||
> | ||
<View> | ||
<Text | ||
onPress={[Function]} | ||
style={ | ||
Object { | ||
"color": "#000000", | ||
"fontFamily": "Roboto", | ||
"fontSize": 18, | ||
"fontWeight": "600", | ||
"marginHorizontal": 20, | ||
"marginVertical": 12, | ||
"textAlign": "center", | ||
} | ||
} | ||
> | ||
Signature Request | ||
</Text> | ||
</View> | ||
<Connect(SignatureRequest) | ||
currentPageInformation={ | ||
Object { | ||
"title": "title", | ||
"url": "url", | ||
} | ||
} | ||
onCancel={[Function]} | ||
onConfirm={[Function]} | ||
showWarning={true} | ||
type="ethSign" | ||
> | ||
<View | ||
style={ | ||
Object { | ||
"borderBottomColor": "#bbc0c5", | ||
"borderBottomWidth": 1, | ||
"padding": 20, | ||
} | ||
} | ||
> | ||
<Text | ||
style={ | ||
Object { | ||
"fontFamily": "Roboto", | ||
"fontSize": 16, | ||
"fontWeight": "400", | ||
"margin": 5, | ||
} | ||
} | ||
> | ||
Message: | ||
</Text> | ||
<Text> | ||
message | ||
</Text> | ||
</View> | ||
</Connect(SignatureRequest)> | ||
</View> | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { StyleSheet, View, Text } from 'react-native'; | ||
import { colors, fontStyles } from '../../../styles/common'; | ||
import Engine from '../../../core/Engine'; | ||
import SignatureRequest from '../SignatureRequest'; | ||
import { strings } from '../../../../locales/i18n'; | ||
import DeviceSize from '../../../util/DeviceSize'; | ||
|
||
const styles = StyleSheet.create({ | ||
root: { | ||
backgroundColor: colors.white, | ||
minHeight: '90%', | ||
borderTopLeftRadius: 10, | ||
borderTopRightRadius: 10, | ||
paddingBottom: DeviceSize.isIphoneX() ? 20 : 0 | ||
}, | ||
informationRow: { | ||
borderBottomColor: colors.grey200, | ||
borderBottomWidth: 1, | ||
padding: 20 | ||
}, | ||
messageLabelText: { | ||
...fontStyles.normal, | ||
margin: 5, | ||
fontSize: 16 | ||
}, | ||
title: { | ||
textAlign: 'center', | ||
fontSize: 18, | ||
marginVertical: 12, | ||
marginHorizontal: 20, | ||
color: colors.fontPrimary, | ||
...fontStyles.bold | ||
} | ||
}); | ||
|
||
/** | ||
* PureComponent that supports eth_sign | ||
*/ | ||
export default class MessageSign extends PureComponent { | ||
static propTypes = { | ||
/** | ||
* react-navigation object used for switching between screens | ||
*/ | ||
navigation: PropTypes.object, | ||
/** | ||
* Callback triggered when this message signature is rejected | ||
*/ | ||
onCancel: PropTypes.func, | ||
/** | ||
* Callback triggered when this message signature is approved | ||
*/ | ||
onConfirm: PropTypes.func, | ||
/** | ||
* Personal message to be displayed to the user | ||
*/ | ||
messageParams: PropTypes.object, | ||
/** | ||
* Object containing current page title and url | ||
*/ | ||
currentPageInformation: PropTypes.object | ||
}; | ||
|
||
signMessage = async () => { | ||
const { messageParams } = this.props; | ||
const { KeyringController, MessageManager } = Engine.context; | ||
const messageId = messageParams.metamaskId; | ||
const cleanMessageParams = await MessageManager.approveMessage(messageParams); | ||
const rawSig = await KeyringController.signMessage(cleanMessageParams); | ||
MessageManager.setMessageStatusSigned(messageId, rawSig); | ||
}; | ||
|
||
rejectMessage = () => { | ||
const { messageParams } = this.props; | ||
const { MessageManager } = Engine.context; | ||
const messageId = messageParams.metamaskId; | ||
MessageManager.rejectMessage(messageId); | ||
}; | ||
|
||
cancelSignature = () => { | ||
this.rejectMessage(); | ||
this.props.onCancel(); | ||
}; | ||
|
||
confirmSignature = () => { | ||
this.signMessage(); | ||
this.props.onConfirm(); | ||
}; | ||
|
||
render() { | ||
const { messageParams, currentPageInformation, navigation } = this.props; | ||
return ( | ||
<View style={styles.root}> | ||
<View style={styles.titleWrapper}> | ||
<Text style={styles.title} onPress={this.cancelSignature}> | ||
{strings('signature_request.title')} | ||
</Text> | ||
</View> | ||
<SignatureRequest | ||
navigation={navigation} | ||
onCancel={this.cancelSignature} | ||
onConfirm={this.confirmSignature} | ||
currentPageInformation={currentPageInformation} | ||
type="ethSign" | ||
showWarning | ||
> | ||
<View style={styles.informationRow}> | ||
<Text style={styles.messageLabelText}>{strings('signature_request.message')}</Text> | ||
<Text>{messageParams.data}</Text> | ||
</View> | ||
</SignatureRequest> | ||
</View> | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import MessageSign from './'; | ||
|
||
describe('MessageSign', () => { | ||
it('should render correctly', () => { | ||
const wrapper = shallow( | ||
<MessageSign currentPageInformation={{ title: 'title', url: 'url' }} messageParams={{ data: 'message' }} /> | ||
); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
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
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
Oops, something went wrong.