diff options
author | Alexander Tseung <alextsg@gmail.com> | 2018-08-26 09:00:38 +0800 |
---|---|---|
committer | Alexander Tseung <alextsg@gmail.com> | 2018-09-13 10:48:51 +0800 |
commit | 930dac110aa9127380673e119b0eaab9d45b1198 (patch) | |
tree | 365611642dd30a89bf3f9982fd8827e420c913dd /ui/app/components/transaction-activity-log/transaction-activity-log.util.js | |
parent | ce1975fbb4f36c83e64948968612b0c74a0b39b8 (diff) | |
download | tangerine-wallet-browser-930dac110aa9127380673e119b0eaab9d45b1198.tar.gz tangerine-wallet-browser-930dac110aa9127380673e119b0eaab9d45b1198.tar.zst tangerine-wallet-browser-930dac110aa9127380673e119b0eaab9d45b1198.zip |
Add ActivityLog component
Diffstat (limited to 'ui/app/components/transaction-activity-log/transaction-activity-log.util.js')
-rw-r--r-- | ui/app/components/transaction-activity-log/transaction-activity-log.util.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/ui/app/components/transaction-activity-log/transaction-activity-log.util.js b/ui/app/components/transaction-activity-log/transaction-activity-log.util.js new file mode 100644 index 000000000..fe780788a --- /dev/null +++ b/ui/app/components/transaction-activity-log/transaction-activity-log.util.js @@ -0,0 +1,75 @@ +// 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 + }, []) +} |