diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-08-30 07:14:51 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-08-30 07:14:51 +0800 |
commit | e85418b11ad14bf6f0cc3fdbcdbb5669330c4778 (patch) | |
tree | df71d73fa1533cea8b36fb24db90e02a07766607 /ui/lib | |
parent | 40d5b446cfbea436a012d1799d0d7710caca752c (diff) | |
parent | a9c738d4d3226f61942641a41c399c75a3e9eb3e (diff) | |
download | tangerine-wallet-browser-e85418b11ad14bf6f0cc3fdbcdbb5669330c4778.tar tangerine-wallet-browser-e85418b11ad14bf6f0cc3fdbcdbb5669330c4778.tar.gz tangerine-wallet-browser-e85418b11ad14bf6f0cc3fdbcdbb5669330c4778.tar.bz2 tangerine-wallet-browser-e85418b11ad14bf6f0cc3fdbcdbb5669330c4778.tar.lz tangerine-wallet-browser-e85418b11ad14bf6f0cc3fdbcdbb5669330c4778.tar.xz tangerine-wallet-browser-e85418b11ad14bf6f0cc3fdbcdbb5669330c4778.tar.zst tangerine-wallet-browser-e85418b11ad14bf6f0cc3fdbcdbb5669330c4778.zip |
Merge branch 'master' into EdgeCompatibility
Diffstat (limited to 'ui/lib')
-rw-r--r-- | ui/lib/account-link.js | 18 | ||||
-rw-r--r-- | ui/lib/persistent-form.js | 57 |
2 files changed, 75 insertions, 0 deletions
diff --git a/ui/lib/account-link.js b/ui/lib/account-link.js new file mode 100644 index 000000000..eb958e22d --- /dev/null +++ b/ui/lib/account-link.js @@ -0,0 +1,18 @@ +module.exports = function(address, network) { + const net = parseInt(network) + let link + + switch (net) { + case 1: // main net + link = `http://etherscan.io/address/${address}` + break + case 2: // morden test net + link = `http://testnet.etherscan.io/address/${address}` + break + default: + link = '' + break + } + + return link +} diff --git a/ui/lib/persistent-form.js b/ui/lib/persistent-form.js new file mode 100644 index 000000000..2fd7600a2 --- /dev/null +++ b/ui/lib/persistent-form.js @@ -0,0 +1,57 @@ +const inherits = require('util').inherits +const Component = require('react').Component +const defaultKey = 'persistent-form-default' +const eventName = 'keyup' + +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 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 + this.setPersistentStore(store) +} + +PersistentForm.prototype.componentWillUnmount = function () { + const fields = document.querySelectorAll('[data-persistent-formid]') + fields.forEach((field) => { + field.removeEventListener(eventName, this.persistentFieldDidUpdate.bind(this)) + }) + this.setPersistentStore({}) +} |