mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #2260 from MetaMask/history-notes
transaction - provide notes for history
This commit is contained in:
commit
b7c1951602
@ -66,13 +66,15 @@ module.exports = class TransactionController extends EventEmitter {
|
||||
|
||||
this.txStateManager.store.subscribe(() => this.emit('update:badge'))
|
||||
|
||||
this.pendingTxTracker.on('tx:warning', this.txStateManager.updateTx.bind(this.txStateManager))
|
||||
this.pendingTxTracker.on('tx:warning', (txMeta) => {
|
||||
this.txStateManager.updateTx(txMeta, 'transactions/pending-tx-tracker#event: tx:warning')
|
||||
})
|
||||
this.pendingTxTracker.on('tx:failed', this.txStateManager.setTxStatusFailed.bind(this.txStateManager))
|
||||
this.pendingTxTracker.on('tx:confirmed', this.txStateManager.setTxStatusConfirmed.bind(this.txStateManager))
|
||||
this.pendingTxTracker.on('tx:retry', (txMeta) => {
|
||||
if (!('retryCount' in txMeta)) txMeta.retryCount = 0
|
||||
txMeta.retryCount++
|
||||
this.txStateManager.updateTx(txMeta)
|
||||
this.txStateManager.updateTx(txMeta, 'transactions/pending-tx-tracker#event: tx:retry')
|
||||
})
|
||||
|
||||
this.blockTracker.on('block', this.pendingTxTracker.checkForTxInBlock.bind(this.pendingTxTracker))
|
||||
@ -168,14 +170,14 @@ module.exports = class TransactionController extends EventEmitter {
|
||||
const txParams = txMeta.txParams
|
||||
// ensure value
|
||||
const gasPrice = txParams.gasPrice || await this.query.gasPrice()
|
||||
txParams.value = txParams.value || '0x0'
|
||||
txParams.gasPrice = ethUtil.addHexPrefix(gasPrice.toString(16))
|
||||
txParams.value = txParams.value || '0x0'
|
||||
// set gasLimit
|
||||
return await this.txGasUtil.analyzeGasUsage(txMeta)
|
||||
}
|
||||
|
||||
async updateAndApproveTransaction (txMeta) {
|
||||
this.txStateManager.updateTx(txMeta)
|
||||
this.txStateManager.updateTx(txMeta, 'confTx: user approved transaction')
|
||||
await this.approveTransaction(txMeta.id)
|
||||
}
|
||||
|
||||
@ -193,7 +195,7 @@ module.exports = class TransactionController extends EventEmitter {
|
||||
txMeta.txParams.nonce = ethUtil.addHexPrefix(nonceLock.nextNonce.toString(16))
|
||||
// add nonce debugging information to txMeta
|
||||
txMeta.nonceDetails = nonceLock.nonceDetails
|
||||
this.txStateManager.updateTx(txMeta)
|
||||
this.txStateManager.updateTx(txMeta, 'transactions#approveTransaction')
|
||||
// sign transaction
|
||||
const rawTx = await this.signTransaction(txId)
|
||||
await this.publishTransaction(txId, rawTx)
|
||||
@ -224,7 +226,7 @@ module.exports = class TransactionController extends EventEmitter {
|
||||
async publishTransaction (txId, rawTx) {
|
||||
const txMeta = this.txStateManager.getTx(txId)
|
||||
txMeta.rawTx = rawTx
|
||||
this.txStateManager.updateTx(txMeta)
|
||||
this.txStateManager.updateTx(txMeta, 'transactions#publishTransaction')
|
||||
const txHash = await this.query.sendRawTransaction(rawTx)
|
||||
this.setTxHash(txId, txHash)
|
||||
this.txStateManager.setTxStatusSubmitted(txId)
|
||||
@ -239,7 +241,7 @@ module.exports = class TransactionController extends EventEmitter {
|
||||
// Add the tx hash to the persisted meta-tx object
|
||||
const txMeta = this.txStateManager.getTx(txId)
|
||||
txMeta.hash = txHash
|
||||
this.txStateManager.updateTx(txMeta)
|
||||
this.txStateManager.updateTx(txMeta, 'transactions#setTxHash')
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -20,8 +20,11 @@ function migrateFromSnapshotsToDiffs(longHistory) {
|
||||
)
|
||||
}
|
||||
|
||||
function generateHistoryEntry(previousState, newState) {
|
||||
return jsonDiffer.compare(previousState, newState)
|
||||
function generateHistoryEntry(previousState, newState, note) {
|
||||
const entry = jsonDiffer.compare(previousState, newState)
|
||||
// Add a note to the first op, since it breaks if we append it to the entry
|
||||
if (note && entry[0]) entry[0].note = note
|
||||
return entry
|
||||
}
|
||||
|
||||
function replayHistory(_shortHistory) {
|
||||
|
@ -82,7 +82,7 @@ module.exports = class TransactionStateManger extends EventEmitter {
|
||||
return txMeta
|
||||
}
|
||||
|
||||
updateTx (txMeta) {
|
||||
updateTx (txMeta, note) {
|
||||
if (txMeta.txParams) {
|
||||
Object.keys(txMeta.txParams).forEach((key) => {
|
||||
let value = txMeta.txParams[key]
|
||||
@ -96,7 +96,7 @@ module.exports = class TransactionStateManger extends EventEmitter {
|
||||
// recover previous tx state obj
|
||||
const previousState = txStateHistoryHelper.replayHistory(txMeta.history)
|
||||
// generate history entry and add to history
|
||||
const entry = txStateHistoryHelper.generateHistoryEntry(previousState, currentState)
|
||||
const entry = txStateHistoryHelper.generateHistoryEntry(previousState, currentState, note)
|
||||
txMeta.history.push(entry)
|
||||
|
||||
// commit txMeta to state
|
||||
@ -113,7 +113,7 @@ module.exports = class TransactionStateManger extends EventEmitter {
|
||||
updateTxParams (txId, txParams) {
|
||||
const txMeta = this.getTx(txId)
|
||||
txMeta.txParams = extend(txMeta.txParams, txParams)
|
||||
this.updateTx(txMeta)
|
||||
this.updateTx(txMeta, `txStateManager#updateTxParams`)
|
||||
}
|
||||
|
||||
/*
|
||||
@ -233,7 +233,7 @@ module.exports = class TransactionStateManger extends EventEmitter {
|
||||
if (status === 'submitted' || status === 'rejected') {
|
||||
this.emit(`${txMeta.id}:finished`, txMeta)
|
||||
}
|
||||
this.updateTx(txMeta)
|
||||
this.updateTx(txMeta, `txStateManager: setting status to ${status}`)
|
||||
this.emit('update:badge')
|
||||
}
|
||||
|
||||
|
@ -23,16 +23,16 @@ describe('tx-state-history-helper', function () {
|
||||
|
||||
it('replaying history does not mutate the original obj', function () {
|
||||
const initialState = { test: true, message: 'hello', value: 1 }
|
||||
const diff1 = {
|
||||
const diff1 = [{
|
||||
"op": "replace",
|
||||
"path": "/message",
|
||||
"value": "haay",
|
||||
}
|
||||
const diff2 = {
|
||||
}]
|
||||
const diff2 = [{
|
||||
"op": "replace",
|
||||
"path": "/value",
|
||||
"value": 2,
|
||||
}
|
||||
}]
|
||||
const history = [initialState, diff1, diff2]
|
||||
|
||||
const beforeStateSnapshot = JSON.stringify(initialState)
|
||||
@ -42,4 +42,5 @@ describe('tx-state-history-helper', function () {
|
||||
assert.notEqual(initialState, latestState, 'initial state is not the same obj as the latest state')
|
||||
assert.equal(beforeStateSnapshot, afterStateSnapshot, 'initial state is not modified during run')
|
||||
})
|
||||
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user