Skip to content
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

Wallet connect update + Support for simple notifications #1624

Merged
merged 41 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fd5f4dd
bump
estebanmino Jun 4, 2020
ed09107
client|
estebanmino Jun 4, 2020
99b45a7
env android
estebanmino Jun 5, 2020
6cb1dd4
working
estebanmino Jun 6, 2020
808e7f8
android working
estebanmino Jun 6, 2020
c83ccc5
handle from entry
estebanmino Jun 6, 2020
769d874
Merge branch 'fix-branch' into wallet-connect-upgrade
estebanmino Jun 6, 2020
1fd0afc
images
estebanmino Jun 7, 2020
ce8602d
handle not valid uris
estebanmino Jun 8, 2020
d1c2b98
handle ios|
estebanmino Jun 9, 2020
450bf88
ios working
estebanmino Jun 9, 2020
48f35f4
ios and android working
estebanmino Jun 9, 2020
d13c830
modify script
estebanmino Jun 9, 2020
d647584
conflict
estebanmino Jun 9, 2020
9fc58d1
fix
estebanmino Jun 9, 2020
8538a17
Merge branch 'fix-branch' into wallet-connect-upgrade
estebanmino Jun 9, 2020
f41d328
small update
estebanmino Jun 9, 2020
b3a9e87
Merge branch 'develop' into wallet-connect-upgrade
estebanmino Jun 9, 2020
8852599
check params
estebanmino Jun 10, 2020
32284cf
bump
estebanmino Jun 10, 2020
44d3019
use of approval
estebanmino Jun 10, 2020
5a00d94
base notification
estebanmino Jun 10, 2020
ac0defc
refactor
estebanmino Jun 10, 2020
fafb27d
change name
estebanmino Jun 10, 2020
bdaf6b1
didn't break anything
estebanmino Jun 10, 2020
6283e39
still working
estebanmino Jun 10, 2020
5ccb501
simple notifications working
estebanmino Jun 11, 2020
cac2732
show simple not
estebanmino Jun 11, 2020
5236c72
origin
estebanmino Jun 11, 2020
a416941
show notifications
estebanmino Jun 11, 2020
ddb8b64
Merge branch 'develop' into wallet-connect-upgrade
estebanmino Jun 11, 2020
5d92047
locales
estebanmino Jun 11, 2020
66d627c
status
estebanmino Jun 11, 2020
823bc71
locales
estebanmino Jun 11, 2020
6222f91
reducer:
estebanmino Jun 11, 2020
2952030
lines
estebanmino Jun 11, 2020
b7c20f2
nots
estebanmino Jun 11, 2020
97ff3c7
undo sh
estebanmino Jun 11, 2020
a88e290
add entry to changelog
estebanmino Jun 11, 2020
7408f57
add entry to changelog
estebanmino Jun 11, 2020
2e6dbbd
add entry to changelog
estebanmino Jun 11, 2020
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Current Develop Branch

## v0.2.17 - Jun 12 2020
- [#1624](https://github.com/MetaMask/metamask-mobile/pull/1624): Wallet connect update + Support for simple notifications (#1624)
- [#1623](https://github.com/MetaMask/metamask-mobile/pull/1623): Fix browser intial load (#1623)
- [#1621](https://github.com/MetaMask/metamask-mobile/pull/1621): Fix branch (#1621)
- [#1512](https://github.com/MetaMask/metamask-mobile/pull/1512): Transaction components (#1512)
- [#1619](https://github.com/MetaMask/metamask-mobile/pull/1619): Fix aab link on slack (#1619)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@ export function showTransactionNotification({ autodismiss, transaction, status }
status
};
}

export function showSimpleNotification({ autodismiss, title, description, status }) {
return {
type: 'SHOW_SIMPLE_NOTIFICATION',
isVisible: true,
autodismiss,
title,
description,
status
};
}
43 changes: 21 additions & 22 deletions app/components/Nav/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import PaymentChannel from '../../Views/PaymentChannel';
import ImportPrivateKeySuccess from '../../Views/ImportPrivateKeySuccess';
import PaymentRequest from '../../UI/PaymentRequest';
import PaymentRequestSuccess from '../../UI/PaymentRequestSuccess';
import TransactionsNotificationManager from '../../../core/TransactionsNotificationManager';
import NotificationManager from '../../../core/NotificationManager';
import Engine from '../../../core/Engine';
import AppConstants from '../../../core/AppConstants';
import PushNotification from 'react-native-push-notification';
Expand All @@ -73,7 +73,6 @@ import TypedSign from '../../UI/TypedSign';
import Modal from 'react-native-modal';
import WalletConnect from '../../../core/WalletConnect';
import PaymentChannelsClient from '../../../core/PaymentChannelsClient';
import WalletConnectSessionApproval from '../../UI/WalletConnectSessionApproval';
import PaymentChannelApproval from '../../UI/PaymentChannelApproval';
import PaymentChannelDeposit from '../../Views/PaymentChannel/PaymentChannelDeposit';
import PaymentChannelSend from '../../Views/PaymentChannel/PaymentChannelSend';
Expand All @@ -91,16 +90,20 @@ import { isENS, safeToChecksumAddress } from '../../../util/address';
import Logger from '../../../util/Logger';
import contractMap from 'eth-contract-metadata';
import MessageSign from '../../UI/MessageSign';
import WalletConnectReturnToBrowserModal from '../../UI/WalletConnectReturnToBrowserModal';
import AsyncStorage from '@react-native-community/async-storage';
import Approve from '../../Views/ApproveView/Approve';
import Amount from '../../Views/SendFlow/Amount';
import Confirm from '../../Views/SendFlow/Confirm';
import ContactForm from '../../Views/Settings/Contacts/ContactForm';
import TransactionTypes from '../../../core/TransactionTypes';
import BackupAlert from '../../UI/BackupAlert';
import TxNotification from '../../UI/TxNotification';
import { showTransactionNotification, hideTransactionNotification } from '../../../actions/transactionNotification';
import Notification from '../../UI/Notification';
import {
showTransactionNotification,
hideTransactionNotification,
showSimpleNotification
} from '../../../actions/notification';
import AccountApproval from '../../UI/AccountApproval';

const styles = StyleSheet.create({
flex: {
Expand Down Expand Up @@ -423,6 +426,10 @@ class Main extends PureComponent {
* Dispatch showing a transaction notification
*/
showTransactionNotification: PropTypes.func,
/**
* Dispatch showing a simple notification
*/
showSimpleNotification: PropTypes.func,
/**
* Dispatch hiding a transaction notification
*/
Expand All @@ -449,7 +456,6 @@ class Main extends PureComponent {
signType: '',
walletConnectRequest: false,
walletConnectRequestInfo: {},
walletConnectReturnModalVisible: false,
paymentChannelRequest: false,
paymentChannelRequestLoading: false,
paymentChannelRequestCompleted: false,
Expand Down Expand Up @@ -489,7 +495,7 @@ class Main extends PureComponent {
}
if (data && data.action === 'tx') {
if (data.id) {
TransactionsNotificationManager.setTransactionToView(data.id);
NotificationManager.setTransactionToView(data.id);
}
this.props.navigation.navigate('TransactionsHome');
}
Expand Down Expand Up @@ -539,10 +545,11 @@ class Main extends PureComponent {
});

setTimeout(() => {
TransactionsNotificationManager.init(
NotificationManager.init(
this.props.navigation,
this.props.showTransactionNotification,
this.props.hideTransactionNotification
this.props.hideTransactionNotification,
this.props.showSimpleNotification
);
this.pollForIncomingTransactions();

Expand Down Expand Up @@ -638,9 +645,6 @@ class Main extends PureComponent {
WalletConnect.hub.on('walletconnectSessionRequest', peerInfo => {
this.setState({ walletConnectRequest: true, walletConnectRequestInfo: peerInfo });
});
WalletConnect.hub.on('walletconnect:return', () => {
this.setState({ walletConnectReturnModalVisible: true });
});
WalletConnect.init();
};

Expand Down Expand Up @@ -790,7 +794,7 @@ class Main extends PureComponent {
if (transactionMeta.status === 'submitted') {
this.setState({ transactionHandled: true });
this.props.navigation.pop();
TransactionsNotificationManager.watchSubmittedTransaction({
NotificationManager.watchSubmittedTransaction({
...transactionMeta,
assetType: transactionMeta.transaction.assetType
});
Expand Down Expand Up @@ -906,7 +910,6 @@ class Main extends PureComponent {
// If the app is now in background, we need to start
// the background timer, which is less intense
if (this.backgroundMode) {
this.setState({ walletConnectReturnModalVisible: false });
BackgroundTimer.runBackgroundTimer(async () => {
await Engine.refreshTransactionHistory();
}, AppConstants.TX_CHECK_BACKGROUND_FREQUENCY);
Expand Down Expand Up @@ -1074,23 +1077,19 @@ class Main extends PureComponent {
onBackButtonPress={this.onWalletConnectSessionRejected}
swipeDirection={'down'}
>
<WalletConnectSessionApproval
<AccountApproval
onCancel={this.onWalletConnectSessionRejected}
onConfirm={this.onWalletConnectSessionApproval}
currentPageInformation={{
title: meta && meta.name,
url: meta && meta.url
}}
autosign={false}
walletConnectRequest
/>
</Modal>
);
};

renderWalletConnectReturnModal = () => (
<WalletConnectReturnToBrowserModal modalVisible={this.state.walletConnectReturnModalVisible} />
);

renderPaymentChannelRequestApproval = () => {
const {
paymentChannelRequest,
Expand Down Expand Up @@ -1144,11 +1143,10 @@ class Main extends PureComponent {
<GlobalAlert />
<FadeOutOverlay />
<BackupAlert navigation={this.props.navigation} onPress={this.backupAlertPress} />
<TxNotification navigation={this.props.navigation} />
<Notification navigation={this.props.navigation} />
</View>
{this.renderSigningModal()}
{this.renderWalletConnectSessionRequestModal()}
{this.renderWalletConnectReturnModal()}
</React.Fragment>
);
}
Expand All @@ -1172,6 +1170,7 @@ const mapDispatchToProps = dispatch => ({
setEtherTransaction: transaction => dispatch(setEtherTransaction(transaction)),
setTransactionObject: transaction => dispatch(setTransactionObject(transaction)),
showTransactionNotification: args => dispatch(showTransactionNotification(args)),
showSimpleNotification: args => dispatch(showSimpleNotification(args)),
hideTransactionNotification: () => dispatch(hideTransactionNotification())
});

Expand Down
27 changes: 25 additions & 2 deletions app/components/UI/AccountApproval/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { colors, fontStyles } from '../../../styles/common';
import Device from '../../../util/Device';
import Analytics from '../../../core/Analytics';
import { ANALYTICS_EVENT_OPTS } from '../../../util/analytics';
import NotificationManager from '../../../core/NotificationManager';

const styles = StyleSheet.create({
root: {
Expand Down Expand Up @@ -85,7 +86,11 @@ class AccountApproval extends PureComponent {
/**
* A string representing the network name
*/
networkType: PropTypes.string
networkType: PropTypes.string,
/**
* Whether it was a request coming through wallet connect
*/
walletConnectRequest: PropTypes.bool
};

state = {
Expand All @@ -100,15 +105,32 @@ class AccountApproval extends PureComponent {
});
};

showWalletConnectNotification = (confirmation = false) => {
if (this.props.walletConnectRequest) {
const title = this.props.currentPageInformation.title;
InteractionManager.runAfterInteractions(() => {
NotificationManager.showSimpleNotification({
status: `simple_notification${!confirmation ? '_rejected' : ''}`,
duration: 5000,
title: confirmation
? strings('notifications.wc_connected_title', { title })
: strings('notifications.wc_connected_rejected_title'),
description: strings('notifications.wc_description')
});
});
}
};

/**
* Calls onConfirm callback and analytics to track connect confirmed event
*/
onConfirm = () => {
this.props.onConfirm();
Analytics.trackEventWithParameters(
ANALYTICS_EVENT_OPTS.AUTHENTICATION_CONNECT_CONFIRMED,
this.getTrackingParams()
);
this.props.onConfirm();
this.showWalletConnectNotification(true);
};

/**
Expand All @@ -120,6 +142,7 @@ class AccountApproval extends PureComponent {
this.getTrackingParams()
);
this.props.onCancel();
this.showWalletConnectNotification();
};

/**
Expand Down
21 changes: 20 additions & 1 deletion app/components/UI/MessageSign/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, View, Text } from 'react-native';
import { StyleSheet, View, Text, InteractionManager } from 'react-native';
import { fontStyles } from '../../../styles/common';
import Engine from '../../../core/Engine';
import SignatureRequest from '../SignatureRequest';
import ExpandedMessage from '../SignatureRequest/ExpandedMessage';
import NotificationManager from '../../../core/NotificationManager';
import { strings } from '../../../../locales/i18n';
import { WALLET_CONNECT_ORIGIN } from '../../../util/walletconnect';

const styles = StyleSheet.create({
expandedMessage: {
Expand Down Expand Up @@ -56,20 +59,36 @@ export default class MessageSign extends PureComponent {
truncateMessage: false
};

showWalletConnectNotification = (messageParams, confirmation = false) => {
InteractionManager.runAfterInteractions(() => {
messageParams.origin === WALLET_CONNECT_ORIGIN &&
NotificationManager.showSimpleNotification({
status: `simple_notification${!confirmation ? '_rejected' : ''}`,
duration: 5000,
title: confirmation
? strings('notifications.wc_signed_title')
: strings('notifications.wc_signed_rejected_title'),
description: strings('notifications.wc_description')
});
});
};

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);
this.showWalletConnectNotification(messageParams, true);
};

rejectMessage = () => {
const { messageParams } = this.props;
const { MessageManager } = Engine.context;
const messageId = messageParams.metamaskId;
MessageManager.rejectMessage(messageId);
this.showWalletConnectNotification(messageParams);
};

cancelSignature = () => {
Expand Down
Loading