* origin/develop: Position the 3dot menu in the same spot on asset screen and home screen (#10642) Move swaps constants to the shared constants directory (#10614) prefer chainId over networkId in most cases (#10594) no more node:console (#10640) fix: speedup cancellation (#10579) Setting balance to 0x0 when the original value is undefined (#10634) Hide zero balance tokens at useTokenTracker layer (#10630) Removing double click bug from delete custom network modal (#10628) remove transactionCategory in favor of more types (#10615) Ensure permission log will only store JSON-able data (#10524) Replace logic for eth swap token in fetchQuotesAndSetQuoteState with getSwapsEthToken call (#10624) add trezor HD path for ledger wallets (#10616)feature/default_network_editable
commit
9ce7b31719
@ -0,0 +1,46 @@ |
|||||||
|
import { cloneDeep } from 'lodash'; |
||||||
|
import { TRANSACTION_TYPES } from '../../../shared/constants/transaction'; |
||||||
|
|
||||||
|
const version = 53; |
||||||
|
|
||||||
|
/** |
||||||
|
* Deprecate transactionCategory and consolidate on 'type' |
||||||
|
*/ |
||||||
|
export default { |
||||||
|
version, |
||||||
|
async migrate(originalVersionedData) { |
||||||
|
const versionedData = cloneDeep(originalVersionedData); |
||||||
|
versionedData.meta.version = version; |
||||||
|
const state = versionedData.data; |
||||||
|
versionedData.data = transformState(state); |
||||||
|
return versionedData; |
||||||
|
}, |
||||||
|
}; |
||||||
|
|
||||||
|
function transformState(state) { |
||||||
|
const transactions = state?.TransactionController?.transactions; |
||||||
|
const incomingTransactions = |
||||||
|
state?.IncomingTransactionsController?.incomingTransactions; |
||||||
|
if (Array.isArray(transactions)) { |
||||||
|
transactions.forEach((transaction) => { |
||||||
|
if ( |
||||||
|
transaction.type !== TRANSACTION_TYPES.RETRY && |
||||||
|
transaction.type !== TRANSACTION_TYPES.CANCEL |
||||||
|
) { |
||||||
|
transaction.type = transaction.transactionCategory; |
||||||
|
} |
||||||
|
delete transaction.transactionCategory; |
||||||
|
}); |
||||||
|
} |
||||||
|
if (incomingTransactions) { |
||||||
|
const incomingTransactionsEntries = Object.entries(incomingTransactions); |
||||||
|
incomingTransactionsEntries.forEach(([key, transaction]) => { |
||||||
|
delete transaction.transactionCategory; |
||||||
|
state.IncomingTransactionsController.incomingTransactions[key] = { |
||||||
|
...transaction, |
||||||
|
type: TRANSACTION_TYPES.INCOMING, |
||||||
|
}; |
||||||
|
}); |
||||||
|
} |
||||||
|
return state; |
||||||
|
} |
@ -0,0 +1,3 @@ |
|||||||
|
{ |
||||||
|
"exclude": ["node:console"] |
||||||
|
} |
@ -0,0 +1,136 @@ |
|||||||
|
import { strict as assert } from 'assert'; |
||||||
|
import migration53 from '../../../app/scripts/migrations/053'; |
||||||
|
import { TRANSACTION_TYPES } from '../../../shared/constants/transaction'; |
||||||
|
|
||||||
|
describe('migration #53', function () { |
||||||
|
it('should update the version metadata', async function () { |
||||||
|
const oldStorage = { |
||||||
|
meta: { |
||||||
|
version: 52, |
||||||
|
}, |
||||||
|
data: {}, |
||||||
|
}; |
||||||
|
|
||||||
|
const newStorage = await migration53.migrate(oldStorage); |
||||||
|
assert.deepEqual(newStorage.meta, { |
||||||
|
version: 53, |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
it('should update type of standard transactions', async function () { |
||||||
|
const oldStorage = { |
||||||
|
meta: {}, |
||||||
|
data: { |
||||||
|
TransactionController: { |
||||||
|
transactions: [ |
||||||
|
{ |
||||||
|
type: TRANSACTION_TYPES.CANCEL, |
||||||
|
transactionCategory: TRANSACTION_TYPES.SENT_ETHER, |
||||||
|
txParams: { foo: 'bar' }, |
||||||
|
}, |
||||||
|
{ |
||||||
|
type: 'standard', |
||||||
|
transactionCategory: TRANSACTION_TYPES.SENT_ETHER, |
||||||
|
txParams: { foo: 'bar' }, |
||||||
|
}, |
||||||
|
{ |
||||||
|
type: 'standard', |
||||||
|
transactionCategory: TRANSACTION_TYPES.CONTRACT_INTERACTION, |
||||||
|
txParams: { foo: 'bar' }, |
||||||
|
}, |
||||||
|
{ |
||||||
|
type: TRANSACTION_TYPES.RETRY, |
||||||
|
transactionCategory: TRANSACTION_TYPES.SENT_ETHER, |
||||||
|
txParams: { foo: 'bar' }, |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
IncomingTransactionsController: { |
||||||
|
incomingTransactions: { |
||||||
|
test: { |
||||||
|
transactionCategory: 'incoming', |
||||||
|
txParams: { |
||||||
|
foo: 'bar', |
||||||
|
}, |
||||||
|
}, |
||||||
|
}, |
||||||
|
}, |
||||||
|
foo: 'bar', |
||||||
|
}, |
||||||
|
}; |
||||||
|
|
||||||
|
const newStorage = await migration53.migrate(oldStorage); |
||||||
|
assert.deepEqual(newStorage.data, { |
||||||
|
TransactionController: { |
||||||
|
transactions: [ |
||||||
|
{ type: TRANSACTION_TYPES.CANCEL, txParams: { foo: 'bar' } }, |
||||||
|
{ type: TRANSACTION_TYPES.SENT_ETHER, txParams: { foo: 'bar' } }, |
||||||
|
{ |
||||||
|
type: TRANSACTION_TYPES.CONTRACT_INTERACTION, |
||||||
|
txParams: { foo: 'bar' }, |
||||||
|
}, |
||||||
|
{ type: TRANSACTION_TYPES.RETRY, txParams: { foo: 'bar' } }, |
||||||
|
], |
||||||
|
}, |
||||||
|
IncomingTransactionsController: { |
||||||
|
incomingTransactions: { |
||||||
|
test: { |
||||||
|
type: 'incoming', |
||||||
|
txParams: { |
||||||
|
foo: 'bar', |
||||||
|
}, |
||||||
|
}, |
||||||
|
}, |
||||||
|
}, |
||||||
|
foo: 'bar', |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
it('should do nothing if transactions state does not exist', async function () { |
||||||
|
const oldStorage = { |
||||||
|
meta: {}, |
||||||
|
data: { |
||||||
|
TransactionController: { |
||||||
|
bar: 'baz', |
||||||
|
}, |
||||||
|
IncomingTransactionsController: { |
||||||
|
foo: 'baz', |
||||||
|
}, |
||||||
|
foo: 'bar', |
||||||
|
}, |
||||||
|
}; |
||||||
|
|
||||||
|
const newStorage = await migration53.migrate(oldStorage); |
||||||
|
assert.deepEqual(oldStorage.data, newStorage.data); |
||||||
|
}); |
||||||
|
|
||||||
|
it('should do nothing if transactions state is empty', async function () { |
||||||
|
const oldStorage = { |
||||||
|
meta: {}, |
||||||
|
data: { |
||||||
|
TransactionController: { |
||||||
|
transactions: [], |
||||||
|
bar: 'baz', |
||||||
|
}, |
||||||
|
IncomingTransactionsController: { |
||||||
|
incomingTransactions: {}, |
||||||
|
baz: 'bar', |
||||||
|
}, |
||||||
|
foo: 'bar', |
||||||
|
}, |
||||||
|
}; |
||||||
|
|
||||||
|
const newStorage = await migration53.migrate(oldStorage); |
||||||
|
assert.deepEqual(oldStorage.data, newStorage.data); |
||||||
|
}); |
||||||
|
|
||||||
|
it('should do nothing if state is empty', async function () { |
||||||
|
const oldStorage = { |
||||||
|
meta: {}, |
||||||
|
data: {}, |
||||||
|
}; |
||||||
|
|
||||||
|
const newStorage = await migration53.migrate(oldStorage); |
||||||
|
assert.deepEqual(oldStorage.data, newStorage.data); |
||||||
|
}); |
||||||
|
}); |
Loading…
Reference in new issue