aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2018-04-06 09:05:03 +0800
committerfrankiebee <frankie.diamond@gmail.com>2018-04-06 09:05:03 +0800
commit7d243aacf9db9dc8e3e2e3acfc54298ffc06fe12 (patch)
tree0dd0b39f45d67b88b9eda83337fdf5c2a6f45864 /app
parent1ba74c1566fe67f610a730c362b3989e63787d4c (diff)
downloadtangerine-wallet-browser-7d243aacf9db9dc8e3e2e3acfc54298ffc06fe12.tar
tangerine-wallet-browser-7d243aacf9db9dc8e3e2e3acfc54298ffc06fe12.tar.gz
tangerine-wallet-browser-7d243aacf9db9dc8e3e2e3acfc54298ffc06fe12.tar.bz2
tangerine-wallet-browser-7d243aacf9db9dc8e3e2e3acfc54298ffc06fe12.tar.lz
tangerine-wallet-browser-7d243aacf9db9dc8e3e2e3acfc54298ffc06fe12.tar.xz
tangerine-wallet-browser-7d243aacf9db9dc8e3e2e3acfc54298ffc06fe12.tar.zst
tangerine-wallet-browser-7d243aacf9db9dc8e3e2e3acfc54298ffc06fe12.zip
create migration 25
Diffstat (limited to 'app')
-rw-r--r--app/scripts/migrations/025.js61
-rw-r--r--app/scripts/migrations/index.js1
2 files changed, 62 insertions, 0 deletions
diff --git a/app/scripts/migrations/025.js b/app/scripts/migrations/025.js
new file mode 100644
index 000000000..fc3b20a44
--- /dev/null
+++ b/app/scripts/migrations/025.js
@@ -0,0 +1,61 @@
+// next version number
+const version = 25
+
+/*
+
+normalizes txParams on unconfirmed txs
+
+*/
+const ethUtil = require('ethereumjs-util')
+const clone = require('clone')
+
+module.exports = {
+ version,
+
+ migrate: async function (originalVersionedData) {
+ const versionedData = clone(originalVersionedData)
+ versionedData.meta.version = version
+ const state = versionedData.data
+ const newState = transformState(state)
+ versionedData.data = newState
+ return versionedData
+ },
+}
+
+function transformState (state) {
+ const newState = state
+
+ if (newState.TransactionController) {
+ if (newState.TransactionController.transactions) {
+ const transactions = newState.TransactionController.transactions
+ newState.TransactionController.transactions = transactions.map((txMeta) => {
+ if (txMeta.status !== 'unapproved') return txMeta
+ txMeta.txParams = normalizeTxParams(txMeta.txParams)
+ return txMeta
+ })
+ }
+ }
+
+ return newState
+}
+
+function normalizeTxParams (txParams) {
+ // functions that handle normalizing of that key in txParams
+ const whiteList = {
+ from: from => ethUtil.addHexPrefix(from).toLowerCase(),
+ to: to => ethUtil.addHexPrefix(txParams.to).toLowerCase(),
+ nonce: nonce => ethUtil.addHexPrefix(nonce),
+ value: value => ethUtil.addHexPrefix(value),
+ data: data => ethUtil.addHexPrefix(data),
+ gas: gas => ethUtil.addHexPrefix(gas),
+ gasPrice: gasPrice => ethUtil.addHexPrefix(gasPrice),
+ }
+
+ // apply only keys in the whiteList
+ const normalizedTxParams = {}
+ Object.keys(whiteList).forEach((key) => {
+ if (txParams[key]) normalizedTxParams[key] = whiteList[key](txParams[key])
+ })
+
+ return normalizedTxParams
+}
diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js
index 7e4542740..6c4a51b32 100644
--- a/app/scripts/migrations/index.js
+++ b/app/scripts/migrations/index.js
@@ -35,4 +35,5 @@ module.exports = [
require('./022'),
require('./023'),
require('./024'),
+ require('./025'),
]