aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/notifications.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-06-25 08:22:27 +0800
committerkumavis <aaron@kumavis.me>2016-06-25 08:22:27 +0800
commitd7d440b2c22eb29744dbd59d6a0d83c27e60c9bd (patch)
treeacb5391bc84adac60e3aa27e8b916808eceff469 /app/scripts/lib/notifications.js
parent86fdcca2ec810c7a002ec984f267920da0a85f9a (diff)
downloadtangerine-wallet-browser-d7d440b2c22eb29744dbd59d6a0d83c27e60c9bd.tar
tangerine-wallet-browser-d7d440b2c22eb29744dbd59d6a0d83c27e60c9bd.tar.gz
tangerine-wallet-browser-d7d440b2c22eb29744dbd59d6a0d83c27e60c9bd.tar.bz2
tangerine-wallet-browser-d7d440b2c22eb29744dbd59d6a0d83c27e60c9bd.tar.lz
tangerine-wallet-browser-d7d440b2c22eb29744dbd59d6a0d83c27e60c9bd.tar.xz
tangerine-wallet-browser-d7d440b2c22eb29744dbd59d6a0d83c27e60c9bd.tar.zst
tangerine-wallet-browser-d7d440b2c22eb29744dbd59d6a0d83c27e60c9bd.zip
svg notif now work for msg signatures
Diffstat (limited to 'app/scripts/lib/notifications.js')
-rw-r--r--app/scripts/lib/notifications.js124
1 files changed, 77 insertions, 47 deletions
diff --git a/app/scripts/lib/notifications.js b/app/scripts/lib/notifications.js
index ce39c93ac..fbaab8e6b 100644
--- a/app/scripts/lib/notifications.js
+++ b/app/scripts/lib/notifications.js
@@ -1,10 +1,12 @@
const createId = require('hat')
+const extend = require('xtend')
const unmountComponentAtNode = require('react-dom').unmountComponentAtNode
const findDOMNode = require('react-dom').findDOMNode
const render = require('react-dom').render
const h = require('react-hyperscript')
const uiUtils = require('../../../ui/app/util')
-const renderPendingTx = require('../../../ui/app/components/pending-tx-details').prototype.renderGeneric
+const PendingTxDetails = require('../../../ui/app/components/pending-tx-details')
+const PendingMsgDetails = require('../../../ui/app/components/pending-msg-details')
const MetaMaskUiCss = require('../../../ui/css')
var notificationHandlers = {}
@@ -56,29 +58,29 @@ function createTxNotification (opts) {
// guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236
if (!chrome.notifications) return console.error('Chrome notifications API missing...')
- renderTransactionNotificationSVG(opts, function(err, source){
+ var state = {
+ title: 'New Unsigned Transaction',
+ imageifyIdenticons: false,
+ txData: {
+ txParams: opts.txParams,
+ time: (new Date()).getTime(),
+ },
+ identities: {
+
+ },
+ accounts: {
+
+ },
+ onConfirm: opts.confirm,
+ onCancel: opts.cancel,
+ }
+
+ renderTxNotificationSVG(state, function(err, notificationSvgSource){
if (err) throw err
-
- var imageUrl = 'data:image/svg+xml;utf8,' + encodeURIComponent(source)
-
- var id = createId()
- chrome.notifications.create(id, {
- type: 'image',
- requireInteraction: true,
- iconUrl: '/images/icon-128.png',
- imageUrl: imageUrl,
- title: opts.title,
- message: '',
- buttons: [{
- title: 'confirm',
- }, {
- title: 'cancel',
- }],
- })
- notificationHandlers[id] = {
- confirm: opts.confirm,
- cancel: opts.cancel,
- }
+
+ showNotification(extend(state, {
+ imageUrl: toSvgUri(notificationSvgSource),
+ }))
})
}
@@ -86,19 +88,46 @@ function createTxNotification (opts) {
function createMsgNotification (opts) {
// guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236
if (!chrome.notifications) return console.error('Chrome notifications API missing...')
- var message = [
- 'Submitted by ' + opts.msgParams.origin,
- 'to be signed by: ' + uiUtils.addressSummary(opts.msgParams.from),
- 'message:\n' + opts.msgParams.data,
- ].join('\n')
+
+ var state = {
+ title: 'New Unsigned Message',
+ imageifyIdenticons: false,
+ txData: {
+ msgParams: opts.msgParams,
+ time: (new Date()).getTime(),
+ },
+ identities: {
+
+ },
+ accounts: {
+
+ },
+ onConfirm: opts.confirm,
+ onCancel: opts.cancel,
+ }
+
+ renderMsgNotificationSVG(state, function(err, notificationSvgSource){
+ if (err) throw err
+
+ showNotification(extend(state, {
+ imageUrl: toSvgUri(notificationSvgSource),
+ }))
+
+ })
+}
+
+function showNotification (state) {
+ // guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236
+ if (!chrome.notifications) return console.error('Chrome notifications API missing...')
var id = createId()
chrome.notifications.create(id, {
- type: 'basic',
+ type: 'image',
requireInteraction: true,
iconUrl: '/images/icon-128.png',
- title: opts.title,
- message: message,
+ imageUrl: state.imageUrl,
+ title: state.title,
+ message: '',
buttons: [{
title: 'confirm',
}, {
@@ -106,26 +135,23 @@ function createMsgNotification (opts) {
}],
})
notificationHandlers[id] = {
- confirm: opts.confirm,
- cancel: opts.cancel,
+ confirm: state.onConfirm,
+ cancel: state.onCancel,
}
-}
-function renderTransactionNotificationSVG(opts, cb){
- var state = {
- imageifyIdenticons: false,
- txData: {
- txParams: opts.txParams,
- time: (new Date()).getTime(),
- },
- identities: {
+}
- },
- accounts: {
+function renderTxNotificationSVG(state, cb){
+ var content = h(PendingTxDetails, state)
+ renderNotificationSVG(content, cb)
+}
- },
- }
+function renderMsgNotificationSVG(state, cb){
+ var content = h(PendingMsgDetails, state)
+ renderNotificationSVG(content, cb)
+}
+function renderNotificationSVG(content, cb){
var container = document.createElement('div')
var confirmView = h('div.app-primary', {
style: {
@@ -137,7 +163,7 @@ function renderTransactionNotificationSVG(opts, cb){
},
}, [
h('style', MetaMaskUiCss()),
- renderPendingTx(h, state),
+ content,
])
render(confirmView, container, function ready(){
@@ -159,4 +185,8 @@ function svgWrapper(content){
</svg>
`
return wrapperSource.split('{{content}}').join(content)
+}
+
+function toSvgUri(content){
+ return 'data:image/svg+xml;utf8,' + encodeURIComponent(content)
} \ No newline at end of file