aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2018-06-14 08:27:50 +0800
committerGitHub <noreply@github.com>2018-06-14 08:27:50 +0800
commit66c77dc2bd95f40e2d6113e3b932e25c6dc8030c (patch)
tree7e4d4a2e8971e4a6363657b784004985dca16ea6
parent8cb5f57c30f4c13c8b1528174372a7d2deef8c6d (diff)
parent86f7692c0468160c75722fc49659c7c2912d881e (diff)
downloadtangerine-wallet-browser-66c77dc2bd95f40e2d6113e3b932e25c6dc8030c.tar
tangerine-wallet-browser-66c77dc2bd95f40e2d6113e3b932e25c6dc8030c.tar.gz
tangerine-wallet-browser-66c77dc2bd95f40e2d6113e3b932e25c6dc8030c.tar.bz2
tangerine-wallet-browser-66c77dc2bd95f40e2d6113e3b932e25c6dc8030c.tar.lz
tangerine-wallet-browser-66c77dc2bd95f40e2d6113e3b932e25c6dc8030c.tar.xz
tangerine-wallet-browser-66c77dc2bd95f40e2d6113e3b932e25c6dc8030c.tar.zst
tangerine-wallet-browser-66c77dc2bd95f40e2d6113e3b932e25c6dc8030c.zip
Merge pull request #4570 from MetaMask/persistence-stream-fix
background - persistence pipeline - fix persistence bug
-rw-r--r--CHANGELOG.md1
-rw-r--r--app/scripts/background.js14
-rw-r--r--app/scripts/lib/createStreamSink.js24
3 files changed, 33 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 45cb907db..c8aac50ad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## Current Master
+- Fix bug where metamask data would stop being written to disk after prolonged use
- Fix bug where account reset did not work with custom RPC providers.
- Fix bug where nonce mutex was never released
- Stop reloading browser page on Ethereum network change
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 56e190f97..2451cddb6 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -16,6 +16,7 @@ const ExtensionPlatform = require('./platforms/extension')
const Migrator = require('./lib/migrator/')
const migrations = require('./migrations/')
const PortStream = require('./lib/port-stream.js')
+const createStreamSink = require('./lib/createStreamSink')
const NotificationManager = require('./lib/notification-manager.js')
const MetamaskController = require('./metamask-controller')
const firstTimeState = require('./first-time-state')
@@ -273,7 +274,7 @@ function setupController (initState, initLangCode) {
asStream(controller.store),
debounce(1000),
storeTransform(versionifyData),
- storeTransform(persistData),
+ createStreamSink(persistData),
(error) => {
log.error('MetaMask - Persistence pipeline failed', error)
}
@@ -289,7 +290,7 @@ function setupController (initState, initLangCode) {
return versionedData
}
- function persistData (state) {
+ async function persistData (state) {
if (!state) {
throw new Error('MetaMask - updated state is missing', state)
}
@@ -297,12 +298,13 @@ function setupController (initState, initLangCode) {
throw new Error('MetaMask - updated state does not have data', state)
}
if (localStore.isSupported) {
- localStore.set(state)
- .catch((err) => {
+ try {
+ await localStore.set(state)
+ } catch (err) {
+ // log error so we dont break the pipeline
log.error('error setting state in local store:', err)
- })
+ }
}
- return state
}
//
diff --git a/app/scripts/lib/createStreamSink.js b/app/scripts/lib/createStreamSink.js
new file mode 100644
index 000000000..cf9416fea
--- /dev/null
+++ b/app/scripts/lib/createStreamSink.js
@@ -0,0 +1,24 @@
+const WritableStream = require('readable-stream').Writable
+const promiseToCallback = require('promise-to-callback')
+
+module.exports = createStreamSink
+
+
+function createStreamSink(asyncWriteFn, _opts) {
+ return new AsyncWritableStream(asyncWriteFn, _opts)
+}
+
+class AsyncWritableStream extends WritableStream {
+
+ constructor (asyncWriteFn, _opts) {
+ const opts = Object.assign({ objectMode: true }, _opts)
+ super(opts)
+ this._asyncWriteFn = asyncWriteFn
+ }
+
+ // write from incomming stream to state
+ _write (chunk, encoding, callback) {
+ promiseToCallback(this._asyncWriteFn(chunk, encoding))(callback)
+ }
+
+}