A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
ciphermask/ui/app/components/transaction-activity-log/transaction-activity-log.ut...

75 lines
1.8 KiB

// path constants
const STATUS_PATH = '/status'
const GAS_PRICE_PATH = '/txParams/gasPrice'
// status constants
const STATUS_UNAPPROVED = 'unapproved'
const STATUS_SUBMITTED = 'submitted'
const STATUS_CONFIRMED = 'confirmed'
const STATUS_DROPPED = 'dropped'
// op constants
const REPLACE_OP = 'replace'
const eventPathsHash = {
[STATUS_PATH]: true,
[GAS_PRICE_PATH]: true,
}
const statusHash = {
[STATUS_SUBMITTED]: true,
[STATUS_CONFIRMED]: true,
[STATUS_DROPPED]: true,
}
function eventCreator (eventKey, timestamp, value, valueDescriptionKey) {
return {
eventKey,
timestamp,
value,
valueDescriptionKey,
}
}
export function getActivities (transaction) {
const { history = [] } = transaction
return history.reduce((acc, base) => {
// First history item should be transaction creation
if (!Array.isArray(base) && base.status === STATUS_UNAPPROVED && base.txParams) {
const { time, txParams: { value } = {} } = base
return acc.concat(eventCreator('created', time, value, 'value'))
} else if (Array.isArray(base)) {
const events = []
base.forEach(entry => {
const { op, path, value, timestamp } = entry
if (path in eventPathsHash && op === REPLACE_OP) {
switch (path) {
case STATUS_PATH: {
if (value in statusHash) {
events.push(eventCreator(value, timestamp))
}
break
}
case GAS_PRICE_PATH: {
events.push(eventCreator('updated', timestamp, value, 'gasPrice'))
break
}
default: {
events.push(eventCreator(value, timestamp))
}
}
}
})
return acc.concat(events)
}
return acc
}, [])
}