From 6eb09c1a796f636ce45c9589a47a40f37e4ed2ac Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 25 Aug 2016 12:17:09 -0700 Subject: Add persistent form class --- ui/lib/persistent-form.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 ui/lib/persistent-form.js (limited to 'ui/lib') diff --git a/ui/lib/persistent-form.js b/ui/lib/persistent-form.js new file mode 100644 index 000000000..4bb19ad58 --- /dev/null +++ b/ui/lib/persistent-form.js @@ -0,0 +1,60 @@ +const inherits = require('util').inherits +const Component = require('react').Component +const defaultKey = 'persistent-form-default' +const eventName = 'keyup'//.persistent-form-change'//.persistent-form-change' + +module.exports = PersistentForm + +function PersistentForm () { + Component.call(this) +} + +inherits(PersistentForm, Component) + +PersistentForm.prototype.componentDidMount = function () { + const fields = document.querySelectorAll('[data-persistent-formid]') + const store = this.getPersistentStore() + fields.forEach((field) => { + const key = field.getAttribute('data-persistent-formid') + const val = field.value + const cached = store[key] + if (cached !== undefined) { + field.value = cached + } + + field.addEventListener(eventName, this.persistentFieldDidUpdate.bind(this)) + }) +} + +PersistentForm.prototype.getPersistentStore = function () { + let store = window.localStorage[this.persistentFormParentId || defaultKey] + if (store && store !== 'null') { + store = JSON.parse(store) + } else { + store = {} + } + return store +} + +PersistentForm.prototype.setPersistentStore = function (newStore) { + window.localStorage[this.persistentFormParentId || defaultKey] = JSON.stringify(newStore) +} + +PersistentForm.prototype.persistentFieldDidUpdate = function (event) { + const field = event.target + const store = this.getPersistentStore() + const key = field.getAttribute('data-persistent-formid') + const val = field.value + store[key] = val + console.log(val) + this.setPersistentStore(store) +} + +PersistentForm.prototype.componentWillUnmount = function () { + const fields = document.querySelectorAll('[data-persistent-formid]') + const store = this.getPersistentStore() + fields.forEach((field) => { + field.removeEventListener(eventName, this.persistentFieldDidUpdate.bind(this)) + }) + this.setPersistentStore({}) +} -- cgit From 2026b674c53caf643abc69364c60250cf0163062 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 25 Aug 2016 14:09:54 -0700 Subject: Remove log --- ui/lib/persistent-form.js | 1 - 1 file changed, 1 deletion(-) (limited to 'ui/lib') diff --git a/ui/lib/persistent-form.js b/ui/lib/persistent-form.js index 4bb19ad58..537cfb1ce 100644 --- a/ui/lib/persistent-form.js +++ b/ui/lib/persistent-form.js @@ -46,7 +46,6 @@ PersistentForm.prototype.persistentFieldDidUpdate = function (event) { const key = field.getAttribute('data-persistent-formid') const val = field.value store[key] = val - console.log(val) this.setPersistentStore(store) } -- cgit From 6f082dd9e7b7cd9cd0fba6590282d4ce46032c70 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 25 Aug 2016 14:23:41 -0700 Subject: Linted --- ui/lib/persistent-form.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'ui/lib') diff --git a/ui/lib/persistent-form.js b/ui/lib/persistent-form.js index 537cfb1ce..2fd7600a2 100644 --- a/ui/lib/persistent-form.js +++ b/ui/lib/persistent-form.js @@ -1,7 +1,7 @@ const inherits = require('util').inherits const Component = require('react').Component const defaultKey = 'persistent-form-default' -const eventName = 'keyup'//.persistent-form-change'//.persistent-form-change' +const eventName = 'keyup' module.exports = PersistentForm @@ -16,7 +16,6 @@ PersistentForm.prototype.componentDidMount = function () { const store = this.getPersistentStore() fields.forEach((field) => { const key = field.getAttribute('data-persistent-formid') - const val = field.value const cached = store[key] if (cached !== undefined) { field.value = cached @@ -51,7 +50,6 @@ PersistentForm.prototype.persistentFieldDidUpdate = function (event) { PersistentForm.prototype.componentWillUnmount = function () { const fields = document.querySelectorAll('[data-persistent-formid]') - const store = this.getPersistentStore() fields.forEach((field) => { field.removeEventListener(eventName, this.persistentFieldDidUpdate.bind(this)) }) -- cgit From fb6476224ff0537e179705c2ae0895672a23a67b Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 29 Aug 2016 16:40:57 -0700 Subject: Add tolerance for failed form persisting --- ui/lib/persistent-form.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'ui/lib') diff --git a/ui/lib/persistent-form.js b/ui/lib/persistent-form.js index 2fd7600a2..c2bf99360 100644 --- a/ui/lib/persistent-form.js +++ b/ui/lib/persistent-form.js @@ -14,6 +14,9 @@ inherits(PersistentForm, Component) PersistentForm.prototype.componentDidMount = function () { const fields = document.querySelectorAll('[data-persistent-formid]') const store = this.getPersistentStore() + if (!fields) { + return + } fields.forEach((field) => { const key = field.getAttribute('data-persistent-formid') const cached = store[key] @@ -50,8 +53,12 @@ PersistentForm.prototype.persistentFieldDidUpdate = function (event) { PersistentForm.prototype.componentWillUnmount = function () { const fields = document.querySelectorAll('[data-persistent-formid]') + if (!fields) { + return + } fields.forEach((field) => { field.removeEventListener(eventName, this.persistentFieldDidUpdate.bind(this)) }) this.setPersistentStore({}) } + -- cgit From c15eef9425531c86a9016d1cbad9d32f4d12edcd Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 29 Aug 2016 17:34:29 -0700 Subject: Make element enumeration Edge compatible --- ui/lib/persistent-form.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'ui/lib') diff --git a/ui/lib/persistent-form.js b/ui/lib/persistent-form.js index c2bf99360..d4dc20b03 100644 --- a/ui/lib/persistent-form.js +++ b/ui/lib/persistent-form.js @@ -14,10 +14,9 @@ inherits(PersistentForm, Component) PersistentForm.prototype.componentDidMount = function () { const fields = document.querySelectorAll('[data-persistent-formid]') const store = this.getPersistentStore() - if (!fields) { - return - } - fields.forEach((field) => { + + for (var i = 0; i < fields.length; i++) { + const field = fields[i] const key = field.getAttribute('data-persistent-formid') const cached = store[key] if (cached !== undefined) { @@ -25,7 +24,7 @@ PersistentForm.prototype.componentDidMount = function () { } field.addEventListener(eventName, this.persistentFieldDidUpdate.bind(this)) - }) + } } PersistentForm.prototype.getPersistentStore = function () { @@ -53,12 +52,10 @@ PersistentForm.prototype.persistentFieldDidUpdate = function (event) { PersistentForm.prototype.componentWillUnmount = function () { const fields = document.querySelectorAll('[data-persistent-formid]') - if (!fields) { - return - } - fields.forEach((field) => { + for (var i = 0; i < fields.length; i++) { + const field = fields[i] field.removeEventListener(eventName, this.persistentFieldDidUpdate.bind(this)) - }) + } this.setPersistentStore({}) } -- cgit From 6f86c5f8ee6779eddfde1fbc32e356bbc80708f3 Mon Sep 17 00:00:00 2001 From: Frankie Date: Thu, 8 Sep 2016 12:56:04 -0700 Subject: Add network checks for unconfirmed Txs --- ui/lib/tx-helper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ui/lib') diff --git a/ui/lib/tx-helper.js b/ui/lib/tx-helper.js index 8f15cd3cc..c984bc9af 100644 --- a/ui/lib/tx-helper.js +++ b/ui/lib/tx-helper.js @@ -1,7 +1,7 @@ const valuesFor = require('../app/util').valuesFor -module.exports = function (unconfTxs, unconfMsgs) { - var txValues = valuesFor(unconfTxs) +module.exports = function (unconfTxs, unconfMsgs, network) { + var txValues = network ? valuesFor(unconfTxs).filter(tx => tx.txParams.metamaskNetworkId === network) : valuesFor(unconfTxs) var msgValues = valuesFor(unconfMsgs) var allValues = txValues.concat(msgValues) return allValues.sort(tx => tx.time) -- cgit